My Animation and Code:
float d = 50;
float c = 1.5;
int r = 255;
int g = 255;
int b = 255;
float yPos = 0.0;
void setup() {
size(300, 300);
frameRate(30);
}
int value = 0;
void draw() {
background(r, g, b);
if (d > 150 || d < 30) {
c = c * -1;
}
d = d + c;
fill(value);
ellipse( 150, 150, d, d);
println(d);
}
void mousePressed() {
if (value == 0) {
value = 255;
} else {
value = 0;
}
}
void keyPressed() {
println(key);
if (key == ‘r’ || key == ‘R’) {
r = 255;
g = 0;
b = 0;
} else if (key == ‘g’ || key == ‘G’) {
r = 0; g = 255; b = 0;
} else if (key == ‘b’ || key == ‘B’) {
r = 0; g = 0; b = 255;
}
else if (key == ‘p’ || key == ‘P’) {
r = 252; g = 148; b = 255;
}
else if (key == ‘t’ || key == ‘T’) {
r = 148; g = 255; b = 234;
}
}
I liked using the mousePressed() function and the keyPressed() function because it definitely made it more interactive and I had more control. One of the fellows helped me with adding and subtracting from the d and c values in the right way for the expandoing which I was struggling with before. It wound up being very helpful and I was able to learn from that and do soemthign similar in my homework exercises.
Homework:
Step 1:
float d = 150;
float c = 4;
int r = 255;
int g = 255;
int b = 255;
void setup() {
size(600, 600);
frameRate(30);
}
void draw() {
background(r, g, b);
fill(255);
ellipse( 300, 300, d, d);
strokeWeight(15);
println(d);
}
Step 2:
float d = 50;
float c = 4;
int r = 255;
int g = 255;
int b = 255;
void setup() {
size(600, 600);
frameRate(30);
}
void draw() {
background(r, g, b);
if (d > 200 || d < 50) {
c = c * -1;
}
d = d + c;
fill(255);
ellipse( 300, 300, d, d);
strokeWeight(15);
println(d);
}
Step 3:
float d = 50;
float c = 4;
float a = 0;
void setup() {
size(600, 600);
frameRate(30);
colorMode(HSB);
}
void draw() {
background(255);
noFill();
ellipse( 300, 300, d, d);
strokeWeight(15);
stroke(a, 255,255);
if (d > 200 || d < 50) {
c = c * -1;
}
if (a<255){
a++;
}
else if (a>255){
a–;
}
d = d + c;
println(d);
}