Recitation 6 Documentation–Blog 10

     In this recitation, I get more familiar with functions such as size(), fill(), etc. The most interesting functions that I learned in this session are firstly the use of keyReleased() and mouseClicked(). By using these two functions I can then better interact with my product. When clicked on the mouse or the keyboard, the color of the ellipses can be changed to a random color. I think this is really interesting. And the most difficult function that I tried to use was how to make the ellipse to spin around a certain point. To achieve this goal I use the float() function and I need to calculate the angle that I want my ellipses to spin.

Here’s the video of my project:

Code for recitation:

int size = 50;
int value = 0;
int value1 = 0;
float r, theta;
float speed;
float r1=70;


void setup() {
  size(600, 600);
  background(0, 0, 45);
  r = 150.0;
  theta = 0.0; // theta = 0 to TWO_PI
  speed = 0.05;
}

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


  noStroke();
  fill(112, 27, 31, 150);
  circle(150, 100, 170);//the toppest circle(outside one)

  fill(0, 0, 0, 200);
  circle(150, 100, r1); //the toppest circle
  r1++;



  noStroke();
  fill(value1);
  circle(250, 490, 200); //biggest circle


  fill(value);
  pushMatrix();
  translate(310, 410);
  rotate(0.3);
  rect(15, -10, 20, 70);
  rect(-10, 15, 70, 20);
  popMatrix();

  theta += speed;
  float x = r/2 * cos(theta);
  float y = r/2 * sin(theta);
  fill(130, 130, 130);
  translate(x, y);
  circle(400, 260, 90); //the middle circle


  fill(0, 0, 45);
  stroke(150, 150, 150);
  circle(390, 250, 30); //smallest circle
}

void keyReleased() {
  if (value == 0) {
    value = color(255, 185, 15, 190);
  } else {
    value = color(random(360), 50, 75);
  }
}

void mouseClicked(){
  if (value1 == 0) {
    value1 = color(211, 211, 211);
  } else {
    value1 = color(random(360), 100, 200);
  }
}

Video for additional homework:

Code for additional homework:

int r=100;
int r1=100;
int x=300;
int y=300;
int state=0;
int colorchange=0;
int radius = 10;

void setup() {
  size(600, 600);
  colorMode(HSB, 100);
}

void draw() {
  stroke(colorchange, 100, 100);
  background(100);
  strokeWeight(15);
  if (r>=250 && r1>=250) {
    state=0;
  }
  if  (r<=100 && r1<=100) {
    state=1;
  }
  if (state==1) {
    r=r+2;
    r1=r1+2;
  }
  if (state==0) {
    r=r-2;
    r1=r1-2;
  }
  radius = round(sin(millis() * .001) * 50) + 100;
  colorchange = colorchange + 1;
  if (colorchange >= 100) {
    colorchange = 0;
  }

  ellipse(x, y, r, r1);
}

void keyPressed() {
  println(keyCode);
  if (keyCode==UP) {
    y-=20;
  }
  if (keyCode==DOWN) {
    y+=20;
  }
  if (keyCode==LEFT) {
    x-=20;
  }
  if (keyCode==RIGHT) {
    x+=20;
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *