Processing_가을(벼는 익을수록 고개를 숙인다.)

그림 위에서 마우스를 움직여보면 벼가 자라 익어가는 모습을 표현하였다.



















소스코드
<head> 
<script src="//cloud.github.com/downloads/processing-js/processing-js/processing-1.4.1.js">
</script>
</head>
<body>
<script data-processing-target="mycanvas" type="text/processing">

float x, y;
float angle1 = 0.0;
float angle2 = 0.0;
float segLength = 80;
void setup() {
  size(300, 300);
  strokeWeight(10);
  stroke(181, 160, 45);
  x = width * 0.5;
  y = height * 0.5;
}
void draw() {
  background(165, 246, 255);
 
  angle1 = (mouseX/float(height) - 0.5) * -PI ;
  angle2 = (mouseY/float(height)- 0.5) * PI/2 ;
  pushMatrix();
  segment(x, y+200, angle1);
  segment(segLength, 0, angle2);
  popMatrix();
  pushMatrix();
  segment(x+20, y+200, angle1);
  segment(segLength, 0, angle2);
  popMatrix();
    pushMatrix();
  segment(x+40, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
      pushMatrix();
  segment(x+60, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
  pushMatrix();
  segment(x+80, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
  pushMatrix();
  segment(x+100, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
   pushMatrix();
  segment(x+120, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
   pushMatrix();
  segment(x+-140, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
   pushMatrix();
  segment(x-120, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
   pushMatrix();
  segment(x-100, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
   pushMatrix();
  segment(x-80, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
     pushMatrix();
  segment(x-60, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
   pushMatrix();
  segment(x-40, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
   pushMatrix();
  segment(x-20, y+200, angle1);
  segment(segLength, 0, angle2);
   popMatrix();
 
}
void segment(float x, float y, float a) {
  translate(x, y);
  rotate(a);
  line(0, 0, segLength, 0);
}
void keyPressed(){
if (key=='a') saveFrame("line-######.png");
}

</script><canvas id="mycanvas"></canvas></body>

댓글

  1. 프로그램이 겹쳐서 보이는 현상은 html 문서에서 mycanvas를 mycanvas1으로 바꿔보도록 합시다. 그럼 겹쳐서 보이는 현상이 많이 없어집니다.

    답글삭제

댓글 쓰기

이 블로그의 인기 게시물

움직이는 장난감 스케치

Product Interaction_Trash can light