Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Processing資料(2) 再帰

1,134 views

Published on

Processingについての授業の資料です。

Published in: Technology
  • Be the first to comment

Processing資料(2) 再帰

  1. 1. 再帰 Processing資料(2)
  2. 2. 関数について #include<stdio.h> int sum(int a, int b); int main(void){ int result = 0; result = sum(2,3); printf(“result = %dn”,result); return 0; } int sum(int a,int b){ int c = 0; c = a + b; return c; }
  3. 3. 関数について #include<stdio.h> int sum(int a, int b); int main(void){ int result = 0; result = sum(2,3); printf(“result = %dn”,result); return 0; } int sum(int a,int b){ int c = 0; c = a + b; return c; } main関数→sum関数
  4. 4. 関数について 関数A→関数B→関数C 関数A→関数A→関数A→...
  5. 5. 再帰 関数が自分自身を呼び出すこと  →無限ループになる   →終了条件を考える必要がある
  6. 6. Processingで再帰
  7. 7. Processingで再帰 最初に大きな円を描く 大きさを変えながら 左右に円を描く
  8. 8. void setup() { size(600, 350); colorMode(HSB, 360, 100, 100); background(360); strokeWeight(2); noLoop(); } void draw() { background(360); draw_circle(width/2, 300, 0); } void draw_circle(float x, float r, int level) { stroke(200); fill(level*60, 20, 100); ellipse(x, height/2, r, r); level++; if (r > 10.0) { draw_circle(x+r/2, r/2, level); draw_circle(x-r/2, r/2, level); } }
  9. 9. void setup() { size(600, 350); colorMode(HSB, 360, 100, 100); background(360); strokeWeight(2); noLoop(); } void draw() { background(360); draw_circle(width/2, 300, 0); } void draw_circle(float x, float r, int level) { stroke(200); fill(level*60, 20, 100); ellipse(x, height/2, r, r); level++; if (r > 10.0) { draw_circle(x+r/2, r/2, level); draw_circle(x-r/2, r/2, level); } }
  10. 10. void setup() { size(600, 350); colorMode(HSB, 360, 100, 100); background(360); strokeWeight(2); noLoop(); } void draw() { background(360); draw_circle(width/2, 300, 0); } void draw_circle(float x, float r, int level) { stroke(200); fill(level*60, 20, 100); ellipse(x, height/2, r, r); level++; 終了条件 if (r > 10.0) { draw_circle(x+r/2, r/2, level); draw_circle(x-r/2, r/2, level); } }

×