processing的Python模式代码:向上生长的滕蔓

0 Comments

processing的Python模式向上生长的滕

processing的Python模式向上生长的滕

"""向上生长的绿色藤蔓"""

from random import randint

x = 0
y = 0
g = 0
b = 0

def setup():
    global x,y,g,b
    size(600,300)
    x =width/2
    y = height
    g = randint(0,255)
    b = g
    background(0,0,randint(0,255))

def draw():
    global x,y,g,b
    x += randint(-1,1)
    y -= randint(0,1)
    if x<0:x=width
    if x>width:x=0
    if y<0:y=height
    g += randint(-10,10)
    g = constrain(g,0,255)
    
    b += randint(-10,10)
    b = constrain(b,0,g)
    
    stroke(0,g,b)
    point(x,y)
    

发表评论