python programming exercise facemove

概述python programming exercise facemove

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

from graphics import*from math import*from random import*class Face:    def __init__(self,win,center,size):        self.eyeSize = 0.15*size        self.eyeOff = size/3.0        mouthSize = 0.8*size        mouthOff = size/2.0        self.size = size        self.center = center        self.win = win         self.head = Circle(self.center,self.size)        self.head.draw(win)        self.leftEye = Circle(self.center,self.eyeSize)        self.leftEye.move(-self.eyeOff,-self.eyeOff)        self.rightEye = Circle(self.center,self.eyeSize)        self.rightEye.move(self.eyeOff,-self.eyeOff)        self.leftEye.draw(win)        self.rightEye.draw(win)        p1 = self.center.clone()        p1.move(-mouthSize/2,mouthOff)        p2 = self.center.clone()        p2.move(mouthSize/2,mouthOff)        self.mouth = line(p1,p2)        self.mouth.draw(win)    def moveface(self,x,y):        self.head.move(x,y)        self.leftEye.move(x,y)        self.rightEye.move(x,y)        self.mouth.move(x,y)        self.center.move(x,y)               def getCenter(self):        return self.center               def flinch(self):        self.leftEye.undraw()        self.leftEye = line(Point(self.center.getX()-self.eyeSize,self.center.getY()),Point(self.center.getX()+self.eyeSize,self.center.getY()))        self.leftEye.move(-self.eyeOff,-self.eyeOff)        self.leftEye.draw(self.win)        self.rightEye.undraw()        self.rightEye = line(Point(self.center.getX()-self.eyeSize,self.center.getY()))        self.rightEye.move(self.eyeOff,-self.eyeOff)        self.rightEye.draw(self.win)    def unflinch(self):        self.leftEye.undraw()        self.rightEye.undraw()        self.leftEye = Circle(self.center,-self.eyeOff)        self.leftEye.draw(self.win)        self.rightEye.draw(self.win)def main():    win = GraphWin("",300,300)        center = Point(150,150)    size = 20    face = Face(win,Point(280*random(),280*random()),size)    i = 0    x = 0.1    y = 0.2    face.flinch()    win.getMouse()    face.unflinch()    for i in range(100000):        face.unflinch()        face.moveface(x,y)        center = face.getCenter()        if center.getX() +size>=300 or center.getX() -size<=0:            x = -x            face.flinch()        if center.getY() +size>=300 or center.getY() -size<=0:            y = -y            face.flinch()        win.flush()   main()            

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的python programming exercise facemove全部内容,希望文章能够帮你解决python programming exercise facemove所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1198621.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存