2020年10月26日 星期一

迪克 第七週 畫圖形讓他轉!

 先試著畫點




接著把線連起來

調角度看看有甚麼差異、變化


讓圖形跟著滑鼠旋轉


圖形中心點跟著滑鼠移動又旋轉!



—————————————————————————————————————
///triangle(x1,y1,x2,y2,x3,y3);
void setup(){
  size(500,500);
}
void draw(){
  background(220);
  
  beginShape();
  for(int angle=30; angle<360; angle+=120){
    float angle2 = radians(angle+frameCount);
    float x = mouseX+cos(angle2)*20;
    float y = mouseY+sin(angle2)*20;
    vertex(x,y);
  }
  endShape(CLOSE);
}

—————————————————————————————————————

加分題!!!

程式碼!

—————————————————————————————————————

///triangle(x1,y1,x2,y2,x3,y3);
void setup(){
  size(500,500);
}
void draw(){
  background(220);
  
  for(int i=1;i<=10;i++){
    for(int j=1;j<=10;j++){
      if((i%2==1 && j%2==1) || (i%2==0 && j%2==0)) stroke(0,0,0);
      else stroke(255,0,0);
  beginShape();
  for(int angle=30; angle<360; angle+=120){
    if(i%2==1 && j%2==0)  angle+=5;
    if(i%2==0 && j%2==0)  angle-=5;
    float angle2 = radians(angle);
    float x = cos(angle2)*20;
    float y = sin(angle2)*20;
    vertex(x+45*i,y+45*j);
  }
  endShape(CLOSE);
    }
  }

  
  for(int i=1;i<=10;i++){
    for(int j=1;j<=10;j++){
      if((i%2==1 && j%2==1) || (i%2==0 && j%2==0)) stroke(0,0,0);
      else stroke(255,0,0);
  beginShape();
  for(int angle=30; angle<360; angle+=120){
    if(i%2==1 && j%2==0)  angle+=5;
    if(i%2==0 && j%2==0)  angle-=5;
    float angle2 = radians(angle);
    float x = cos(angle2)*12;
    float y = sin(angle2)*12;
    vertex(x+45*i,y+45*j);
  }
  endShape(CLOSE);
    }
  }
  

  for(int i=1;i<=10;i++){
    for(int j=1;j<=10;j++){
      if((i%2==1 && j%2==1) || (i%2==0 && j%2==0)) stroke(0,0,0);
      else stroke(255,0,0);
  beginShape();
  for(int angle=30; angle<360; angle+=120){
    if(i%2==1 && j%2==0)  angle+=5;
    if(i%2==0 && j%2==0)  angle-=5;
    float angle2 = radians(angle);
    float x = cos(angle2)*4;
    float y = sin(angle2)*4;
    vertex(x+45*i,y+45*j);
  }
  endShape(CLOSE);
    }
  }

}

—————————————————————————————————————

沒有留言:

張貼留言