processing 随机生成线动画

网友投稿 790 2022-11-24

processing 随机生成线动画

processing 随机生成线动画

def setup(): size(600, 600) background(50)def draw(): draw_me_a_line() def draw_me_a_line(colour=200): stroke(colour) line(random(width), random(height), random(width), random(height))

SimpleForm.py

class Form: def __init__(self, x, y, r): # Constructor self.x = x; self.y = y # Set x and y position self.rad = r # Set radius self.x_speed = random(-10, 10) # Set random x speed self.y_speed = random(-10, 10) # Set random y speed def update_me(self): self.x = (self.x + self.x_speed) % width # Moves x and wrap self.y = (self.y + self.y_speed) % height # Moves y and wrap def draw_me(self): stroke(200) point(self.x, self.y) # Draw a dot noStroke(); fill(200,50) circle(self.x, self.y, self.rad) # Draw a circle def line_to(self, other): stroke(200) line(self.x, self.y, other.x, other.y)

运行

from SimpleForm import Formdef setup(): size(600, 600) background(50) global f1, f2 # Make f1 and f2 visible f1 = Form(random(width), random(height), 10) f2 = Form(random(width), random(height), 10)def draw(): f1.update_me() # Update f1 position f2.update_me() # Update f2 position f1.draw_me() # Draw f1 f2.draw_me() # Draw f2 f1.line_to(f2) # Draw line from f1 to f2

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Learning Processing Zoog
下一篇:LeetCode Algorithm 剑指 Offer 24. 反转链表
相关文章

 发表评论

暂时没有评论,来抢沙发吧~