"""pygame慢画正弦曲线sin.py,本程序演示一只看不见的画笔在慢慢地画酷炫的正弦曲线,用到了三角正弦函数与draw的画圆命令。""" __author__ = "李兴球" __date__ = "2018年7月" __company__ = "风火轮编程" import pygame from pygame.locals import * import math import colorsys class Pen(): def __init__(self,radius,color,thickness,screen): self.color = color # 笔颜色 self.thickness = thickness # 笔迹宽度 self.sw = screen.get_width() self.sh = screen.get_height() def setxy(self,angle): self.x = int(self.sw//2 + angle) self.y = int(self.sh//2 - 100*math.sin(math.radians(angle))) def coloradd(self): h,l,s, = colorsys.rgb_to_hls(self.color[0]/255,self.color[1]/255,self.color[2]/255) h = h + 0.01 def main(): pygame.init() screenWidth,screenHeight=480,360 screen = pygame.display.set_mode((screenWidth,screenHeight)) pygame.display.set_caption("pygame慢画炫彩正弦曲线_作者:李兴球") pen = Pen(100,(255,0,0),2,screen) clock = pygame.time.Clock() for angle in range(-180,181): for event in pygame.event.get(): pass pen.setxy(angle) pen.coloradd() pygame.display.update() clock.tick(60) pygame.quit() if __name__=="__main__": main()
如需要查看完整代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
发表评论