float x = 0;
void setup() {
size(400, 400);
background(255);
stroke(255);
}
void draw() {
line(x, 200, x, 100);
x = x + 1;
if (x > width) {
x = 0;
}
// sometimes we decide to change the line color
if (random(100) > 70) {
// now we decide if to use black or white
if (random(100) > 50) {
stroke(0);
}
else {
stroke(255);
}
}
}
这段代码复制自fun programming. 用来让初学者理解随机数的使用。
Processing 练习(10) - 条形码
最新推荐文章于 2020-01-05 17:55:25 发布