Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions ReturningValues/ReturningValues.pde
Original file line number Diff line number Diff line change
@@ -1 +1,76 @@
float[] d = new float[15]; //arrays for the bouncy red and green balls
float[] x = new float[15];
float[] y = new float[15];
float[] velX = new float[15];
float[] velY = new float[15];

void setup() {
size(800, 600); //canvas 800 by 600
for (int i = 0; i < 15; i++) { //draw 15 bouncy red and green balls
d[i] = 3*powerThreeDividedByTwo(i); //look a function! determines diameter of ball
x[i] = random(width); //balls start off wherever
y[i] = random(width);
velX[i] = random(1, 10); //speed is random
velY[i] = random(1, 10);
}
}

void draw() {
background(0); //background refreshes so balls don't leave a trail of stationary christmas ornaments
for (int i = 0; i < 15; i++) {
noStroke(); //no stroke
if (i%2==0) { //if/else loop below means half of the balls are red and half are green
fill(0, 255, 0, 200);
ellipse(x[i], y[i], d[i], d[i]);
} else {
fill(255, 0, 0, 200);
ellipse(x[i], y[i], d[i], d[i]);
}
x[i] += (velX[i]); //position changes by velocity
y[i] += (velY[i]);
if (x[i] + d[i]/2 > width) { //next four if statements make ball bounce
x[i] = width;
velX[i] -=friction(velX[i]);//if the ball hits the right wall, assign x velocity the negative version of itself
velX[i] *= -1;
}
if (x[i] - d[i]/2 < 0) {
x[i] = 0;
velX[i] *= -1;
velX[i] -= friction(velX[i]); //if the ball hits the left wall, assign x velocity the positive version of itself
}
if (y[i] + d[i]/2 > height) {
y[i] = height;
velY[i] -= friction(velY[i]);
velY[i] *= -1;
}
if (y[i] - d[i]/2 < 0) {
y[i] = 0;
velY[i] -= friction(velY[i]);
velY[i] *= -1;
}
}
holidayCheer(); //pretty lights! i managed to decorate my code for the holidays
}

/*****************/

float powerThreeDividedByTwo(float num) { //returns a number^(3/2)
float result = (sqrt((sq(num))*(num)));
return result;
}

float friction(float vel) { //friction is velocity/20, just for simplicity (i was NOT making up a coefficient of kinetic friction for this)
float result = vel*.05;
return result;
}

void holidayCheer() {
float[] lx = new float[80]; //80 pretty lights
float[] ly = new float[80]; //80 pretty lights also have y-coordinates
for (int i = 0; i < 80; i++) {
lx[i] = 10*(i); //makes lights spaced out
ly[i] = 10+10*sin(i); //allows the lights to hang as if from a roof but also ensures they're not stuck offscreen
fill(255, 255, 230); //lights aren't pure white. i tried for a whitish-yellowish, but i'm colorblind, so if i'm wrong, i swear i really did try.
ellipse(lx[i], ly[i], 5, 5); //actually draw the lights, with diam of five
}
}
63 changes: 63 additions & 0 deletions VoidFunctions/VoidFunctions.pde
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
int p; //allows mouse ellipses to change color when clicked
int sz; //size of black hole. couldn't figure out how to declare it within the function and still have the black hole expand
float cx; //x of black hole
float cy; //y of black hole

void setup(){
size(800,600); //canvas
background(0); //black background
noStroke(); //no stroke
blueSquare(); //blue square
}

void draw(){
noStroke(); //also no stroke
drawARandomCircle(); //random circle
if(mousePressed){
drawACircleAt(mouseX, mouseY);
p = 255;//when you click the mouse, mouse ellipses have a blue value of 255
}
else{
p = 0; //no clicky, no blue :(
}
sz += random(-5,10); //size wobbles around but increases overall
if(sz >= 800){
sz = 200; //starts out w/ diameter of 200 when it regenerates
cx = random(width); //pops up randomly every time it regenerates
cy = random(height); //same as above line
background(0); //redraw black background
blueSquare(); //redraw blue square
}
pickAColorAnyColor(mouseX, mouseY, mouseX, mouseY, p); //mouse ellipse function
emptinessOfTheUniverse(); //black hole function
}
/*****************/
void drawARandomCircle(){
float d; //declare diameter
fill(0,random(255),random(255)); //random color
d = random(5,30); //random diameter
ellipse(random(width), random(height), d, d); //random x & y
}

void drawACircleAt(int x, int y){
fill(0, mouseX, mouseY); //mouse ellipse
ellipse(x, y, 10, 10); //mouse ellipse
}

void blueSquare(){
noStroke(); //no stroke
fill(0,0,255); //bright blue
rectMode(CENTER); //draw rectangle from center
rect(width/2, height/2, 50, 50); //middle of screen
}

void pickAColorAnyColor(int x, int y, int r, int g, int b){
fill(r, g, b); //also mouse ellipse? may have done extra code on accident
ellipse(x, y, 10, 10);
}

void emptinessOfTheUniverse(){
fill(0); //black
strokeWeight(5); //stroke of 5
stroke(200,200,200,100); //weird light gray border
ellipse(cx, cy, sz, sz); //enables black hole to move between regenerations
}