NodeBox Strategy

2016/8/22 posted in  python

循环的使用

循环变量

size(400,400)

fill(0,0.6,0.9,0.1)
stroke(0,0.6,0.9)
strokewidth(0.25)

for i in range(100):
    fill(random(0.0,1.0),random(0.0,1.0),random(0.0,1.0),0.1)
    x = random(WIDTH)
    y = random(HEIGHT)
    r = random(50,100)
    oval(x,y,r,r)

执行结果:

这个就不多说了,其实在前面都有介绍,主要是将循环和随机结合。

函数

size(400,400)

def flower(x,y):
    fill(random(0.5,1),random(0.5,1),random(0.5,1))
    stroke(0.2)
    strokewidth(1)
    
    transform(CORNER)
    translate(x,y)
    
    for i in range(10):
        rotate(360/10)
        line(0,0,15,15)
        oval(10,10,10,10)
    reset()
    
for i in range(60):
    flower(random(WIDTH),random(HEIGHT))

这里主要处理的是函数关系的调用。也不需要多讲

Library 包

Nodebox同时可以使用各种Library包,用这些Library包来扩展整体的能力。

要安装扩展包的时候只需要将扩展包下载,然后让道NodeBox的目录,在使用的时候调用ximport()就可以了

同时也可以使用ximport来引入其他的python包。

list = [1, 2, 3, 4, 5]
rnd = ximport("random")
rnd.shuffle(list) 
print list  
>>> [3, 4, 1, 5, 2]