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 Form

def 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

 

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值