5173浏览
查看: 5173|回复: 0

[项目] Processing系列 三角分形

[复制链接]

经典分形图,基本学过计算机图形学的都写过这个作业
中级难度吧

  1. void setup() {
  2.   size(300, 300);
  3.   translate(150, 175);
  4.   rotate(-HALF_PI);
  5.   background(55);
  6.   stroke(255);
  7.   Point[] points = {
  8.     new Point(cos(0)*140, sin(0)*140),
  9.     new Point(cos(TWO_PI/3)*140, sin(TWO_PI/3)*140),
  10.     new Point(cos(TWO_PI/3*2)*140, sin(TWO_PI/3*2)*140),
  11.   };
  12.   Point point = new Point(points[0]);
  13.   for (int i=0; i<10000; i++) {
  14.     int index = int(random(3));
  15.     point.x = (point.x + points[index].x) * .5;
  16.     point.y = (point.y + points[index].y) * .5;
  17.     point(point.x, point.y);
  18.   }
  19. }
  20. class Point {
  21.   float x, y;
  22.   Point(float x, float y) {
  23.     this.x = x;
  24.     this.y = y;
  25.   }
  26.   Point(Point point) {
  27.     this.x = point.x;
  28.     this.y = point.y;
  29.   }
  30. }
复制代码

授权转载自 任远媒体实验室
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail