
参数化绘图 花环图形
代码如下:
- void setup() {
- size(300, 300);
- translate(width/2, height/2);
- background(55);
- stroke(255);
- noFill();
-
- int n = 16, radius = 125;
- Point[] points = new Point[n];
- for (int i=0; i<n; i++) {
- float x = cos(TWO_PI/n*i)*radius;
- float y = sin(TWO_PI/n*i)*radius;
- points[i] = new Point(x, y);
- }
- for (int i=0; i<n; i++) {
- for (int j=i+1; j<n; j++) {
- line(points[i].x, points[i].y, points[j].x, points[j].y);
- }
- }
- }
-
- class Point {
- float x, y;
- Point(float x, float y) {
- this.x = x;
- this.y = y;
- }
- }
复制代码
授权转载自 任远媒体实验室
|