2020年5月1日 星期五

程式設計Week10

Lyto Different Color畫圓法


方法一 - 程式碼:

void setup( )
{
   size(300,500);
}

void draw( )   //畫圓:半徑50

 {  

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

    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);

}

方法二 - 程式碼:

void setup( )
{
   size(300,500);
}

void draw( )
 {
    for(int y=0;y<4;y++)
    {
      for(int x=0;x<4;x++)
      {
         ellipse(37.5+x*75 , 200+37.5+y*75 , 75 , 75);
      }
  }
}

Lyto Different Color圓由小到大

程式碼:

void setup( )
{
  size(300,500);
}

int n=5;
int R=300/n , w=R/2 , RR=0; //RR為變動直徑

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++;  //如果變動直徑RR小於直徑R,變動直徑不斷擴大
}



  

Lyto Different Color圓增值

程式碼:

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;  //如果RR變動直徑小於直徑R,不斷擴大
    else                                 否則圓個數增加,變動直徑=0開始增大
    {
        n++;
        RR=0;
    }
}

Lyto Different Color圓上顏色

程式碼:

void setup( )
{
  size(300,500);
  colorMode(HSB,256);   //TODO改色系統
}

int ansX=1,ansY=2;  //答案
int n=3,RR=0;
int H=0;  //Hum色調

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 )  //現在mouse 選中x,y
          {
            if(mousePressed && x==ansX && y==ansY) //選中的mouse是答案ans
            {
               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;
}

沒有留言:

張貼留言