¡¶Python³ÌÐòÉè¼Æ¡·Ï°ÌâÓë´ð°¸

glShadeModel(GL_SMOOTH) glEnable(GL_POINT_SMOOTH) glEnable(GL_LINE_SMOOTH)

glEnable(GL_POLYGON_SMOOTH) glMatrixMode(GL_PROJECTION)

glHint(GL_POINT_SMOOTH_HINT,GL_NICEST) glHint(GL_LINE_SMOOTH_HINT,GL_NICEST)

glHint(GL_POLYGON_SMOOTH_HINT,GL_FASTEST) glLoadIdentity()

gluPerspective(45.0, float(width)/float(height), 0.1, 100.0) glMatrixMode(GL_MODELVIEW) def MainLoop(self): glutMainLoop()

if __name__ == '__main__': w = MyPyOpenGLTest() w.MainLoop()

15.2 ±àд³ÌÐò£¬¶ÁÈ¡Á½·ù´óСһÑùµÄͼƬ£¬È»ºó½«Á½·ùͼÏñµÄÄÚÈݵþ¼Óµ½Ò»·ùͼÏñ£¬½á¹ûͼÏñÖÐÿ¸öÏñËØֵΪԭÁ½·ùͼÏñ¶ÔӦλÖÃÏñËØÖµµÄƽ¾ùÖµ¡£

´ð£º

from PIL import Image

im1 = Image.open('d:\\\\pic1.bmp') im2 = Image.open('d:\\\\pic2.bmp') size = im1.size

for i in range(size[0]): for j in range(size[1]):

color1 = im1.getpixel((i,j)) color2 = im2.getpixel((i,j)) r = (color1[0]+color2[0])//2 g = (color1[1]+color2[1])//2 b = (color1[2]+color2[2])//2 im1.putpixel((i,j),(r,g,b))

im1.save('d:\\\\pic3.bmp') im1.close() im2.close()

15.3 ±àд³ÌÐò£¬¶ÁÈ¡Ò»·ùͼÏñµÄÄÚÈÝ£¬½«Æä°´ÏóÏÞ·ÖΪ4µÈ·Ý£¬È»ºó1¡¢3ÏóÏÞÄÚÈݽ»»»£¬2¡¢4ÏóÏÞÄÚÈݽ»»»£¬Éú³ÉÒ»·ùÐÂͼÏñ¡£

´ð£º

from PIL import Image

im = Image.open('d:\\\\pic1.bmp') im2 = Image.open('d:\\\\pic1.bmp') size = im.size

box1 = (0, size[1]/2, size[0]/2, size[1]) region1 = im.crop(box1)

box2 = (0, 0, size[0]/2, size[1]/2) region2 = im.crop(box2)

box3 = (size[0]/2, 0, size[0], size[1]/2) region3 = im.crop(box3)

box4 = (size[0]/2, size[1]/2, size[0], size[1]) region4 = im.crop(box4)

im2.paste(region1, box3) im2.paste(region3, box1) im2.paste(region2, box4) im2.paste(region4, box2)

im2.save('d:\\\\pic4.bmp') im.close() im2.close()

15.4 ½áºÏGUI±à³Ì֪ʶ£¬±àдһ¸ö³ÌÐò£¬´´½¨Ò»¸ö´°¿Ú²¢ÔÚÉÏÃæ·ÅÖÃÁ½¸ö°´Å¥£¬·Ö±ðΪ¡°¿ªÊ¼²¥·Å¡±ºÍ¡°ÔÝÍ£²¥·Å¡±£¬½«±¾ÕÂ15.3½ÚÖеÄÒôÀÖ²¥·Å³ÌÐò½øÐзâ×°¡£

´ð£º

import wx import os

import pygame import random import time import threading

class wxGUI(wx.App): def OnInit(self):

frame = wx.Frame(parent=None, title='MP3Player', size=(250,150), pos=(350,350)) panel = wx.Panel(frame, -1)

self.buttonOK = wx.Button(panel, -1, 'Play', pos=(30,60))

self.Bind(wx.EVT_BUTTON, self.OnButtonOK, self.buttonOK)

self.buttonOK.Enabled = True

self.buttonCancel = wx.Button(panel, -1, 'Stop', pos=(120,60))

self.Bind(wx.EVT_BUTTON, self.OnButtonCancel, self.buttonCancel) self.buttonCancel.Enabled = False

frame.Show() return True def OnExit(self): try:

self.playing = False

pygame.mixer.music.stop() finally: pass

def play(self):

folder = r'h:\\music'

musics = [folder+'\\\\'+music for music in os.listdir(folder) if music.endswith('.mp3')] total = len(musics) pygame.mixer.init() while self.playing:

if not pygame.mixer.music.get_busy(): nextMusic = random.choice(musics) pygame.mixer.music.load(nextMusic) pygame.mixer.music.play(1) print 'playing....',nextMusic else:

time.sleep(1)

def OnButtonOK(self, event): self.playing = True

# create a new thread to play music t = threading.Thread(target=self.play) t.start()

self.buttonOK.Enabled = False

self.buttonCancel.Enabled = True

def OnButtonCancel(self, event): self.playing = False

pygame.mixer.music.stop() self.buttonOK.Enabled = True self.buttonCancel.Enabled = False

app = wxGUI()

app.MainLoop()

15.5 ÔËÐб¾ÕÂ15.4ÖеĴúÂë²¢²é¿´ÔËÐнá¹û¡£ ´ð£ºÂÔ¡£

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ì滻Ϊ@)