Recitation 7—-Tao Wen

Question 1:

When the for loop is only in setup(), the graphic will only repeat 100 times. However, if there’s another loop under void draw(), than the action of “repeating 100 times” itself would be repeated 100 times, so the number of graphics is HUGE.

Question 2:

The benefit of using arrays is enabling us to store a number of data that satisfy certain requirements, so that we can pick data to fulfill a function in our own way. 

I would probably set a number of quizes in my project. When the user-controlled robot bumps into something, a question would jump out and the user has to answer it correctly in order to make the next move. Arrays can help me store a certain number of questions, so that they can pop out in a certain order or randomly, according to the way I want it.

Step 1

float x;
float y;
float r;

void setup(){
size(800,800);
background(255);
  colorMode(HSB);
}

void draw() {  
  display(200, width*0.25,  color(145,207,250),width*0.75);
  display(100, width*0.75,  color(250,106,166), width*0.75);
  display(400,height/5,  color(250,106,166),width*0.25);
}

void display(float x, float y, color c,float r) {
  fill(c);
  stroke(0);
  strokeWeight(5);
  rect(x,y,r,r);
  arc(x, y, r*0.6, r*0.6, 0, PI-QUARTER_PI);
  stroke (0);
  strokeWeight(5);
  rect(x+r*0.1,y-r*0.2,r*0.1, r*0.2);
  rect(x-r*0.1,y-r*0.2,r*0.1, r*0.2);
  ellipse(x-r*0.05,y-r*0.1,r*0.01, r*0.02);
  ellipse(x+r*0.15,y-r*0.1,r*0.01, r*0.02);
  delay(1);
}

Step 2

float x;
float y;
float r;

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

for(int i = 0; i < 100; i = i+1) {
    display((random(width)),(random(height)),color(round(random(255)),175,255),random(255));
} 
  colorMode(HSB);
}

void display(float x, float y, color c,float r) {
  fill(c);
  stroke(0);
  strokeWeight(5);
  rect(x,y,r,r);
  arc(x, y, r*0.6, r*0.6, 0, PI-QUARTER_PI);
  stroke (0);
  strokeWeight(5);
  rect(x+r*0.1,y-r*0.2,r*0.1, r*0.2);
  rect(x-r*0.1,y-r*0.2,r*0.1, r*0.2);
  ellipse(x-r*0.05,y-r*0.1,r*0.01, r*0.02);
  ellipse(x+r*0.15,y-r*0.1,r*0.01, r*0.02);
  delay(1);//Use these parameters to create your graphics
}

Step 3

float[] x=new float [100];
float[] y=new float [100];
float[] r=new float [100];

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

for(int i = 0; i < 100; i = i+1) {
 x[i]=random(width);
 y[i]=random(height);
 r[i]=random(255);
  colorMode(HSB);
}
}

void draw() {
  for(int i = 0; i < 100; i++) {
    display(x[i],y[i],color(round(random(255)),175,255),r[i]);
} 
}

void display(float x, float y, color c,float r) {
  fill(c);
  stroke(0);
  strokeWeight(5);
  rect(x,y,r,r);
  arc(x, y, r*0.6, r*0.6, 0, PI-QUARTER_PI);
  stroke (0);
  strokeWeight(5);
  rect(x+r*0.1,y-r*0.2,r*0.1, r*0.2);
  rect(x-r*0.1,y-r*0.2,r*0.1, r*0.2);
  ellipse(x-r*0.05,y-r*0.1,r*0.01, r*0.02);
  ellipse(x+r*0.15,y-r*0.1,r*0.01, r*0.02);//Use these parameters to create your graphics
}

step 4

Based on step3, I added these two lines under “void dispay(){”

  x=x+random(-2,2);
  y=y+random(-2,2);

Leave a Reply