もどる

プログラミング入門

目標

実習の前に

学習のポイント

具体的な実習内容

ゴールとなる画像(動画)

実習の準備

ソースコード1:円を描く

size(800,800);

background(0,0,0);
noStroke();

ellipse(400,400,100,100);

ソースコード2:複数の円を描く

size(800,800);

background(0,0,0);
noStroke();

int a_x = 400; 
int a_y = 400;

fill(255,255,255);
ellipse(a_x,a_y,100,100);

int b_x = 500;
int b_y = a_y;

fill(255,255,0,100);
ellipse(b_x,b_y,200,200);

ソースコード3:繰り返し(for文)

size(800,800);

background(0,0,0);
noStroke();

int x = 400;

fill(71,234,126,100);
for( int y = 0; y <= 850; y += 50 ){
  ellipse(x,y,100,100);
}

ソースコード4:繰り返し(for文)

size(800,800);

background(0,0,0);
noStroke();

int x = 400;

for( int y = 0; y <= 850; y += 50 ){
  fill(71 + y*0.3, 234,126,100);
  ellipse(x,y,100,100);
}

ソースコード5:動きをつける

void setup(){
  size(800,800);

  background(0,0,0);
  noStroke();
  
  frameRate(10);
}

int y = 0;

void draw(){
  // background(0,0,0);

  int x = 400;

  y += 50;
  fill(71 + y*0.3, 234,126,100);
  ellipse(x,y,100,100);
}

ソースコード6:位置を変えながら何度も円と落とす

void setup(){
  size(800,800);

  background(0,0,0);
  noStroke();
  
  frameRate(10);
}

int y = 0;
int x = 100;

void draw(){
  background(0,0,0);

   y += 50;
   if( y > 850 ){
     y = -50;
     x += 100;
   }
   if( x > 700 ){
     x = 100;
   }
  
   fill(71 + y*0.3, 234,126,100);
   ellipse(x,y,100,100);

}

ソースコード7:円の大きさを変えながら

void setup(){
  size(800,800);

  background(0,0,0);
  noStroke();
  
  frameRate(10);
}

int   y = 0;
float x = 100;
float size = 100;

void draw(){
  background(0,0,0);

   y += 50;
   if( y > 850 ){
     y = -50;
     x = random(100,700);
     size = random(10,500);
   }
  
   fill(71 + y*0.3, 234,126,100);
   ellipse(x,y,size,size);

}

ソースコード8:複数の円を一緒に落とす

void setup(){
  size(800,800);

  background(0,0,0);
  noStroke();
  
  frameRate(10);
}

int   y = 0;
int[] x = {0,100,200,300,400,500,600,700,800,900};
float size = 100;

void draw(){
  background(0,0,0);

   y += 50;
   if( y > 850 ){
     y = -50;
   }
   
  fill(71 + y*0.3, 234,126,100);

  for( int i = 0; i < x.length; i += 1){
    ellipse(x[i], y,size,size);
  }
}

ソースコード9:円に番号を振る

void setup(){
  size(800,800);

  background(0,0,0);
  noStroke();
  
  frameRate(10);
  
  textSize(48);
}

int y = 0;
int x = 100;
int   n = 1;

void draw(){
  background(0,0,0);

   y += 50;
   if( y > 850 ){
     y = -50;
     x += 100;
   }
   if( x > 700 ){
     x = 100;
   }
  
   fill(71 + y*0.3, 234,126,100);
   ellipse(x,y,100,100);
   
   fill(255,255,255);
   text(n,x,y);
   n += 1;
}

ソースコード10:完成

void setup(){
  size(800,800);

  background(0,0,0);
  noStroke();
  
  frameRate(10);
  
  textSize(9);
}

int   y = 0;
int[] x = {0,100,200,300,400,500,600,700,800,900};
float size = 100;
int   c = 0;
int   n = 1;

void draw(){
  if(c == 3){
    background(0,0,0);
    c = 0;
    n = 1;
  }

   y += 50;
   if( y > 850 ){
     y = -50;
     c += 1;
   }
   
  for( int i = 0; i < 10; i += 1){
    float r1 = random(0,50);
    float r2 = random(-80,0);
    
    if( random(0,2) > 1 ){
      fill(71 + y*0.3+random(-50,50) ,234+random(-50,50),126+random(-50,50),100+random(-50,50));
      ellipse(x[i]+r1,y+r1,size+r2,size+r2);
      
      fill(255,255,255);
      text(n,x[i]+r1,y+r1);
      n += 1;
    }
  }  
}

演習

課題

もどる