2020年5月1日 星期五

柯基 week_10


size(300 , 500);     先把輪廓打出來
ellipse(75 , 200+75 , 150,150);      這是下面圓形的位置還有半徑
ellipse(75+150 , 200+75 , 150 , 150);
ellipse(75 , 200+75+150 , 150 , 150);
ellipse(75+150 , 200+75+150 , 150 ,  150);


---------------------------------------------------------------------------------



size(300,500);
ellipse(50,200+50,100,100);     #如此一來就可以寫出3*3的
ellipse(50+100,200+50,100,100);
ellipse(50+100+100,200+50,100,100);

ellipse(50,200+50+100,100,100);
ellipse(50+100,200+50+100,100,100);
ellipse(50+100+100,200+50+100,100,100);

ellipse(50,200+50+100+100,100,100);
ellipse(50+100,200+50+100+100,100,100);
ellipse(50+100+100,200+50+100+100,100,100);
---------------------------------------------------------------------------------



size(300,500);
for(int y=0;y<3;y++)
{
  for(int x=0;x<3;x++)    #用for 迴圈就可以寫出原本看起來很複雜的程式
  {
    ellipse(50+x*100,200+50+y*100,100,100);
  }

}
---------------------------------------------------------------------------------
 void setup(){
  size(300,500);
 }
int n=5;        #n等於多少就是會有n*n的圓圈
int R=300/n,w=R/2,RR=0;
void draw(){
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      ellipse(w+x*R,200+w+y*R,RR,RR);
    }
  }
  if(RR<R)RR++;     #這是會把圈圈從小變到大的

}
---------------------------------------------------------------------------------



 void setup(){
  size(300,500);
 }
int n=3,RR=0;
void draw(){
  background(0);
  int R=300/n,w=R/2;
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      ellipse(w+x*R,200+w+y*R,RR,RR);
    }
  }
  if(RR<R)RR+=R/30;
  else{
    n++;     #這樣圈圈就會慢慢變多變大
    RR=0;
  }

}
---------------------------------------------------------------------------------
 void setup(){
  size(300,500);
 }
int ansX=1,ansY=2;   #這個就是答案
int n=3,RR=0;
void draw(){
  background(0);
  int R=300/n,w=R/2;
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      if(x==ansX && y==ansY) fill(128);
      else fill(255);
      if( dist(mouseX,mouseY,w+x*R,200+w+y*R)<w)fill(255,0,0);
      ellipse(w+x*R,200+w+y*R,RR,RR);
    }
  }
  if(RR<R)RR+=R/30;

}

---------------------------------------------------------------------------------

if( dist(mouseX,mouseY,w+x*R,200+w+y*R)<w){
  if(mousePressed && x==ansX &&y==ansY){
  ansX=int (random(n));
  ansY=int (random(n));
}
---------------------------------------------------------------------------------

 void setup(){
  size(300,500);
  colorMode(HSB,256);  #色調
 }
int ansX=1,ansY=2;
int n=3,RR=0;
int H=0;
void draw(){
  background(0);
  int R=300/n,w=R/2;
  for(int y=0;y<n;y++)
  {
    for(int x=0;x<n;x++)
    {
      if(x==ansX && y==ansY) fill(H-10,243,234);
      else fill(H,255,255);
      if( dist(mouseX,mouseY,w+x*R,200+w+y*R)<w){
        if(mousePressed && x==ansX &&y==ansY){
          ansX=int (random(n));
          ansY=int (random(n));
          H+=20;
          if(H>256)H=0;
        }
      }
      ellipse(w+x*R,200+w+y*R,RR,RR);
    }
  }
  if(RR<R)RR+=R/30;

}

沒有留言:

張貼留言