当前位置:网站首页>Processing random generation line animation
Processing random generation line animation
2022-06-26 13:05:00 【Harmony between man and nature Peng】
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)
function
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
边栏推荐
猜你喜欢
随机推荐
Software testing - concept
Photoshop 2022 23.4.1增加了哪些功能?有知道的吗
[esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3
倍福CX5130换卡对已有的授权文件转移操作
C# 结构体:定义、示例
自动化测试的局限性你知道吗?
zoopeeper设置acl权限控制(只允许特定ip访问,加强安全)
National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?
Summary of some application research cases of UAV Remote Sensing in forest monitoring
C# const详解:C#常量的定义和使用
记一次phpcms9.6.3漏洞利用getshell到内网域控
倍福PLC基于CX5130实现数据的断电保持
四类线性相位 FIR滤波器设计 —— MATLAB源码全集
.NET MAUI 性能提升
Verilog中的系统任务(显示/打印类)--$display, $write,$strobe,$monitor
Power Designer - Custom Comment button
Stream learning record
Electron official docs series: Examples
Group counting practice experiment 9 -- using cmstudio to design microprogram instructions based on segment model machine (2)
B - Bridging signals