float xball;// 円の中心の X 座標 float yball; // 円の中心の Y 座標 float rball; // 円の半径 color cball; // 円の色 // 円を移動させる void updateball(){ yball -= 1; if(yball+rball< 0){ yball = height+rball; // 円を描く void drawball(){ stroke(cball); fill(cball); ellipse(xball,yball,2*rball,2*rball); colormode(hsb,359,99,99); // 円の初期状態の決定 rball = random(10,20); xball = random(rball,width-rball); yball = height+rball; cball =color(random(360), random(50,100), random(50,100)); background(0,0,99); updateball(); drawball(); 1 class Ball { (a) x;// 円の中心の X 座標 (b) y;// 円の中心の Y 座標 (c) r;// 円の半径 (d) c; // 円の色 (e) (){ // コンストラクタの設定 r = random(10,20); x = random(r,width-r); y = height+r; c = color(random(360), random(50,100), random(50,100)); (f) myball; // 円を移動させる void updateball(){ (g) -= 1; if( (h) + (i) < 0){ (j) = height+ (k) ; // 円を描く void drawball(){ stroke( (l) ); fill( (m) ); (n) ; colormode(hsb,359,99,99); myball = new (o) ();
background(0,0,99); updateball(); drawball(); class Ball { (a) x;// 円の中心の X 座標 (b) y;// 円の中心の Y 座標 (c) r;// 円の半径 (d) c; // 円の色 (e) (){ // コンストラクタの設定 r = random(10,20); x = random(r,width-r); y = height+r; c = color(random(360), random(50,100), random(50,100)); // 円を移動させる void update(){ (g) -= 1; if( (h) + (i) < 0){ (j) = height+ (k) ; // 円を描く stroke( (l) ); fill( (m) ); (n) ; (f) myball; colormode(hsb,359,99,99); myball = (o) ; background(0,0,99); (p).update(); (q).draw(); 2
class Ball { (a) x;// 円の中心の X 座標 (b) y;// 円の中心の Y 座標 (c) r;// 円の半径 (d) c; // 円の色 // コンストラクタの設定 (e) (float x0,float y0, float r0,color c0){ x = x0; y = y0; r = r0; c = c0; // 円を移動させる void update(){ (g) -= 1; if( (h) + (i) < 0){ (j) = height+ (k) ; // 円を描く stroke( (l) ); fill( (m) ); (n) ; 3 (f) myball; colormode(hsb,359,99,99); myball = new Ball(width/2, height, 20, color(0,99,99)); background(0,0,99); (p).update(); (q).draw(); (f) myball; colormode(hsb,359,99,99); myball = new Ball(width/2, height, 20, (z) );
background(0,0,99); (p).update(); (q).draw(); color c; int xpos; int ypos; int xspeed; size(200,200); c = color(255); xpos = width/2; ypos = height/2; xspeed = 1; void display(){ rectmode(center); stroke(c); fill(c); rect(xpos,ypos,20,10); (a) Car (b) color c; int (c) ; int (d) ; int (e) ; Car(){ // デフォルトコンストラクタ c = color( (f) ); xpos = (g) ; ypos = (h) ; xspeed = 1; void display(){ rectmode(center); stroke( (i) ); fill( (j) ); rect( (k), (l),20,10); void drive(){ (m) += (n) ; if( (o) > (p) ){ (r) = 0; void drive(){ xpos += xspeed; if(xpos > width){ xpos = 0; 4
background(0); drive(); display(); Car (r) ; size(200,200); // Car オブジェクトを作る mycar = (r) ; background(0); (s) (); (t) (); (a) Car (b) color c; int (c) ; int (d) ; int (e) ; // デフォルトコンストラクタ Car(){ c = color( (f) ); xpos = (g) ; ypos = (h) ; xspeed = 1; // 引数付きのコンストラクタ Car (color carcolor,int x,int y,int s){ c = carcolor; xpos = x; ypos = y; xspeed = s; void display(){ rectmode(center); stroke( (i) ); fill( (j) ); rect( (k), (l),20,10); void drive(){ (m) += (n) ; if( (o) > (p) ){ (r) = 0; Car (s) ; Car (t) ; mycar1 = (u) ; mycar2 = new (v) (color( (w) ), width/2,height/4,1); background(0); (x).drive(); (y).display(); (z).drive(); (aa).display(); 5
float x = 100; float y = 0; float speed = 3; float gravity = 0.5; size(200,400); background(100); fill(255); nostroke(); rectmode(center); rect(x,y,10,20); y = y+speed; speed = speed + gravity; if(y+10 > height){ speed = -0.95*speed; y = height-10; 6
float xcenter; // 円の中心の X 座標 float ycenter; // 円の中心の Y 座標 float xspeed; // X 軸方向の移動速度 float yspeed; // Y 軸方向の移動速度 float radius; // 円の半径 radius = 10; xcenter = -radius; ycenter = -radius; xspeed = 0.5; yspeed = 1.2; class (a) { float xcenter; // 円の中心の X 座標 float ycenter; // 円の中心の Y 座標 float xspeed; // X 軸方向の移動速度 float yspeed; // Y 軸方向の移動速度 float radius; // 円の半径 // デフォルトコンストラクタ (b) (float vx0,float vy0){ radius = 10; xcenter = radius; ycenter = radius; xspeed = vx0; yspeed = vy0; 7
background(255); // move xcenter += xspeed; ycenter += yspeed; // draw stroke(0); fill(0); ellipse(xcenter,ycenter,2*radius,2*radius); void move(){ xcenter += xspeed; ycenter += yspeed; stroke(0); fill(0); ellipse(xcenter,ycenter,2*radius,2*radius); (c) aball; aball = new (d) ( (e), (f) ); background(255); aball.move(); aball.draw(); 8
float xcenter; // 円の中心の X 座標 float ycenter; // 円の中心の Y 座標 float xspeed; // X 軸方向の移動速度 float yspeed; // Y 軸方向の移動速度 float radius; // 円の半径 radius = 10; xcenter = -radius; ycenter = -radius; xspeed = 0.5; yspeed = 1.2; background(255); if(isoutofrange()){ xcenter = -radius; ycenter = -radius; xspeed = random(0.4,2.0); yspeed = random(0.4,2.0); // move xcenter += xspeed; ycenter += yspeed; // draw stroke(0); fill(0); ellipse(xcenter,ycenter,2*radius,2*radius); class (a) { float xcenter; // 円の中心の X 座標 float ycenter; // 円の中心の Y 座標 float xspeed; // X 軸方向の移動速度 float yspeed; // Y 軸方向の移動速度 float radius; // 円の半径 // デフォルトコンストラクタ (b) (float vx0,float vy0){ radius = 10; xcenter = radius; ycenter = radius; xspeed = vx0; yspeed = vy0; void move(){ xcenter += xspeed; ycenter += yspeed; stroke(0); fill(0); ellipse(xcenter,ycenter,2*radius,2*radius); (c) isoutofrange(){ if(xcenter-radius > width){ return true; else if(ycenter-radius > height){ return true; return false; 9
boolean isoutofrange(){ if(xcenter-radius > width){ return true; else if(ycenter-radius > height){ return true; return false; (d) aball; aball = new (e) ( (f), (g) ); if(aball.isoutofrange()){ aball.xcenter = (h) ; aball.ycenter = (i) ; aball.xspeed = (j) ; aball.yspeed = (k) ; aball.move(); aball.draw(); 10