Processing系列 三角分形
http://yuanren.cc/wp-content/uploads/2015/03/Sierpinski.png经典分形图,基本学过计算机图形学的都写过这个作业
中级难度吧
void setup() {
size(300, 300);
translate(150, 175);
rotate(-HALF_PI);
background(55);
stroke(255);
Point[] points = {
new Point(cos(0)*140, sin(0)*140),
new Point(cos(TWO_PI/3)*140, sin(TWO_PI/3)*140),
new Point(cos(TWO_PI/3*2)*140, sin(TWO_PI/3*2)*140),
};
Point point = new Point(points);
for (int i=0; i<10000; i++) {
int index = int(random(3));
point.x = (point.x + points.x) * .5;
point.y = (point.y + points.y) * .5;
point(point.x, point.y);
}
}
class Point {
float x, y;
Point(float x, float y) {
this.x = x;
this.y = y;
}
Point(Point point) {
this.x = point.x;
this.y = point.y;
}
}
授权转载自 任远媒体实验室
页:
[1]