Recitation 6 Rainbow Circle Homework

I finished this by attending the rainbow group study session.

Make a black circle.

void setup(){
  size(600, 600);
}

void draw(){
  background(255);
  noFill();
  strokeWeight(30);
  ellipse(width/2, height/2, 300, 300);
}

Make it expand and contracts

float r = 300;
int changeSize = 5;

void setup(){
  size(600, 600);
}

void draw(){
  background(255);
  noFill();
  strokeWeight(30);
  ellipse(width/2, height/2, r, r);
  if (r > width -30 || r < 30){
    changeSize = -changeSize;// when it gets negative it will be positive
  }
  r = r + changeSize;
}

Make it colorful

//Recitation 6 homework
//moving Cicle feat. Rainbow study group
float r = 300;//set r variable
float colorM = 25;// set variable for HSB
int changeSize = 5;//a variable for circle to change size
int changeColor = 1;//set a variable for color change
int x = 300;
int y = 300;
int speed = 20;

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

void draw(){
  background(255);
  noFill();
  strokeWeight(20);//stroke to 30
  //color
  push();//leave the background alone in RGB, but within push and pop it is HSB mode.
  colorMode(HSB, 100);
  stroke(colorM, 100, 100);//leave the saturation alone.
  ellipse(x, y, r, r);//ellipse at x, y
  if (r > width -30 || r < 30){
    changeSize = -changeSize;// when it gets negative it will be positive
  }
  if (colorM>= 100 || colorM<= 0){
    changeColor = -changeColor;// change color
  }
  r = r + changeSize;
  colorM = colorM + changeColor;
  pop();//end push
  
  }

Make it move base on arrow key

螢幕錄製 2021-11-03 下午1.01.17

//Recitation 6 homework
//moving Cicle feat. Rainbow study group
float r = 300;//set r variable
float colorM = 25;// set variable for HSB
int changeSize = 5;//a variable for circle to change size
int changeColor = 1;//set a variable for color change
int x = 300;
int y = 300;
int speed = 20;

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

void draw(){
  background(255);
  noFill();
  strokeWeight(20);//stroke to 30
  //color
  push();//leave the background alone in RGB, but within push and pop it is HSB mode.
  colorMode(HSB, 100);
  stroke(colorM, 100, 100);//leave the saturation alone.
  ellipse(x, y, r, r);//ellipse at x, y
  if (r > width -30 || r < 30){
    changeSize = -changeSize;// when it gets negative it will be positive
  }
  if (colorM>= 100 || colorM<= 0){
    changeColor = -changeColor;// change color
  }
  r = r + changeSize;
  colorM = colorM + changeColor;
  pop();//end push
  
  }
  
  void keyPressed(){ //move the circle up down left and right.
    if (key == CODED){
      if (keyCode == UP) {
        y = y-speed;
      }
      if (keyCode == DOWN){
        y = y+speed;
      }
      if(keyCode == LEFT){
        x = x-speed;
      }
      if(keyCode == RIGHT){
        x = x+speed;
      }
    }
  }

Leave a Reply

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