  
参数化绘图中级难度 
背后的是一个数学故事。 
 
分形原理如下: 
  
 
 
			
			
			- void setup() {
 -   size(300, 300);
 -   translate(45, 85);
 -   background(55);
 -   stroke(255);
 -   noFill();
 -  
 -   String str = "F-F+F-F";
 -   float l = 70;
 -  
 -   for (int i=0; i<5; i++) {
 -     String temp = "";
 -     for (int j=0; j<str.length (); j++) {
 -       char c = str.charAt(j);
 -       if (c == 'F') {
 -         temp += "F-F+F-F";
 -       } else {
 -         temp += c;
 -       }
 -     }
 -     str = temp;
 -     l /= 3;
 -   }
 -  
 -   for (int i=0; i<3; i++) {
 -     for (int j=0; j<str.length (); j++) {
 -       char c = str.charAt(j);
 -       if (c == 'F') {
 -         line(0, 0, l, 0);
 -         translate(l, 0);
 -       } else if (c == '-') {
 -         rotate(-PI/3);
 -       } else if (c == '+') {
 -         rotate(TWO_PI/3);
 -       }
 -     }
 -     rotate(TWO_PI/3);
 -   }
 - }
 
  复制代码
  
 
 
 
授权转载自 任远媒体实验室 
 |