From 90be3e8a70fcabcc0b03beccd8ef866e49b8f7b4 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Thu, 3 Dec 2015 09:24:46 -0500 Subject: [PATCH 1/5] lotta functions --- VoidFunctions/VoidFunctions.pde | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/VoidFunctions/VoidFunctions.pde b/VoidFunctions/VoidFunctions.pde index 8b13789..6860583 100644 --- a/VoidFunctions/VoidFunctions.pde +++ b/VoidFunctions/VoidFunctions.pde @@ -1 +1,65 @@ +float d; +int p; +int c; +void setup(){ + size(800,600); + background(0); + noStroke(); + blueSquare(); +} + +void draw(){ + noStroke(); + drawARandomCircle(); + if(mousePressed){ + drawACircleAt(mouseX, mouseY); + p = 255; + } + else{ + p = 0; + } + pickAColorAnyColor(mouseX, mouseY, mouseX, mouseY, p); + emptinessOfTheUniverse(); + c += random(1,3); +} +/*****************/ +void drawARandomCircle(){ + fill(0,random(255),random(255)); + d = random(5,30); + ellipse(random(width), random(height), d, d); +} + +void drawACircleAt(int x, int y){ + fill(0, mouseX, mouseY); + ellipse(x, y, 10, 10); +} + +void blueSquare(){ + noStroke(); + fill(0,0,255); + rectMode(CENTER); + rect(width/2, height/2, 50, 50); +} + +void pickAColorAnyColor(int x, int y, int r, int g, int b){ + fill(r, g, b); + ellipse(x, y, 10, 10); +} + +void emptinessOfTheUniverse(){ + float sz; + sz = 250; + if(c >= 200 && c <= 499){ + sz += 10; + } + if(c >= 500){ + c = 0; + background(0); + sz = 250; + } + fill(0); + strokeWeight(5); + stroke(200,200,200,100); + ellipse(width/4, height/4, sz, sz); +} \ No newline at end of file From cdb81e6398f1377e608abea77636e4185f81b78a Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Mon, 7 Dec 2015 08:52:31 -0500 Subject: [PATCH 2/5] actually commented it --- VoidFunctions/VoidFunctions.pde | 75 ++++++++++++++++----------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/VoidFunctions/VoidFunctions.pde b/VoidFunctions/VoidFunctions.pde index 6860583..237e8fe 100644 --- a/VoidFunctions/VoidFunctions.pde +++ b/VoidFunctions/VoidFunctions.pde @@ -1,65 +1,64 @@ -float d; -int p; -int c; +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); - background(0); - noStroke(); - blueSquare(); + size(800,600); //canvas + background(0); //black background + noStroke(); //no stroke + blueSquare(); //blue square } void draw(){ - noStroke(); - drawARandomCircle(); + noStroke(); //also no stroke + drawARandomCircle(); //random circle if(mousePressed){ drawACircleAt(mouseX, mouseY); - p = 255; + p = 255;//when you click the mouse, mouse ellipses have a blue value of 255 } else{ - p = 0; + p = 0; //no clicky, no blue :( } - pickAColorAnyColor(mouseX, mouseY, mouseX, mouseY, p); - emptinessOfTheUniverse(); - c += random(1,3); + 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(){ - fill(0,random(255),random(255)); - d = random(5,30); - ellipse(random(width), random(height), d, d); + 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); - ellipse(x, y, 10, 10); + fill(0, mouseX, mouseY); //mouse ellipse + ellipse(x, y, 10, 10); //mouse ellipse } void blueSquare(){ - noStroke(); - fill(0,0,255); - rectMode(CENTER); - rect(width/2, height/2, 50, 50); + 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); + fill(r, g, b); //also mouse ellipse? may have done extra code on accident ellipse(x, y, 10, 10); } void emptinessOfTheUniverse(){ - float sz; - sz = 250; - if(c >= 200 && c <= 499){ - sz += 10; - } - if(c >= 500){ - c = 0; - background(0); - sz = 250; - } - fill(0); - strokeWeight(5); - stroke(200,200,200,100); - ellipse(width/4, height/4, sz, sz); + 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 } \ No newline at end of file From 56e561909a7890949f16407565f790a5464d3195 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Wed, 9 Dec 2015 09:20:29 -0500 Subject: [PATCH 3/5] i tried --- ReturningValues/ReturningValues.pde | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/ReturningValues/ReturningValues.pde b/ReturningValues/ReturningValues.pde index 8b13789..993fc91 100644 --- a/ReturningValues/ReturningValues.pde +++ b/ReturningValues/ReturningValues.pde @@ -1 +1,64 @@ +float[] w = new float[15]; +float[] h = new float[15]; +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); + for (int i = 0; i < 15; i++) { + w[i] = 3*powerThreeDividedByTwo(i); + h[i] = 3*powerThreeDividedByTwo(i); + x[i] = random(width); + y[i] = random(width); + velX[i] = random(-10, 10); + velY[i] = random(-10, 10); + } +} + +void draw() { + background(255); + for (int i = 0; i < 15; i++) { + noStroke(); + if (i%2==0) { + fill(0, 255, 0, 200); + ellipse(x[i], y[i], w[i], h[i]); + } else { + fill(255, 0, 0, 200); + ellipse(x[i], y[i], w[i], h[i]); + } + x[i] += (velX[i]); + y[i] += (velY[i]); + if (x[i] + w[i]/2 >= width) { + x[i] = width-1; + velX[i] -= friction(velX[i]);//if the ball hits the right wall, assign x velocity the negative version of itself + velX[i] *= -1; + } else if (x[i] - w[i]/2 <= 0) { + x[i] = 1; + velX[i] -= friction(velX[i]); //if the ball hits the left wall, assign x velocity the positive version of itself + velX[i] *= -1; + } + if (y[i] + h[i]/2 >= height) { + y[i] = height-1; + velY[i] -= friction(velY[i]); + velY[i] *= -1; + } else if (y[i] - h[i]/2 <= 0) { + y[i] = 1; + velY[i] -= friction(velY[i]); + velY[i] *= -1; + } + } +} + +/*****************/ + +float powerThreeDividedByTwo(float num) { + float result = (sqrt(sq(num)*(num))); + return result; +} + +float friction(float vel) { + float result = vel*.05; + return result; +} \ No newline at end of file From 038c4bf1906ddd07b7ad442a37d00286f8defad7 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Thu, 10 Dec 2015 09:24:28 -0500 Subject: [PATCH 4/5] *shrugs* --- ReturningValues/ReturningValues.pde | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ReturningValues/ReturningValues.pde b/ReturningValues/ReturningValues.pde index 993fc91..55a052c 100644 --- a/ReturningValues/ReturningValues.pde +++ b/ReturningValues/ReturningValues.pde @@ -1,5 +1,4 @@ -float[] w = new float[15]; -float[] h = new float[15]; +float[] d = new float[15]; float[] x = new float[15]; float[] y = new float[15]; float[] velX = new float[15]; @@ -8,12 +7,11 @@ float[] velY = new float[15]; void setup() { size(800, 600); for (int i = 0; i < 15; i++) { - w[i] = 3*powerThreeDividedByTwo(i); - h[i] = 3*powerThreeDividedByTwo(i); + d[i] = 3*powerThreeDividedByTwo(i); x[i] = random(width); y[i] = random(width); - velX[i] = random(-10, 10); - velY[i] = random(-10, 10); + velX[i] = random(1, 10); + velY[i] = random(1, 10); } } @@ -23,28 +21,30 @@ void draw() { noStroke(); if (i%2==0) { fill(0, 255, 0, 200); - ellipse(x[i], y[i], w[i], h[i]); + ellipse(x[i], y[i], d[i], d[i]); } else { fill(255, 0, 0, 200); - ellipse(x[i], y[i], w[i], h[i]); + ellipse(x[i], y[i], d[i], d[i]); } x[i] += (velX[i]); y[i] += (velY[i]); - if (x[i] + w[i]/2 >= width) { - x[i] = width-1; - velX[i] -= friction(velX[i]);//if the ball hits the right wall, assign x velocity the negative version of itself + if (x[i] + d[i]/2 > width) { + 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; - } else if (x[i] - w[i]/2 <= 0) { - x[i] = 1; - velX[i] -= friction(velX[i]); //if the ball hits the left wall, assign x velocity the positive version of itself + } + 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] + h[i]/2 >= height) { - y[i] = height-1; + if (y[i] + d[i]/2 > height) { + y[i] = height; velY[i] -= friction(velY[i]); velY[i] *= -1; - } else if (y[i] - h[i]/2 <= 0) { - y[i] = 1; + } + if (y[i] - d[i]/2 < 0) { + y[i] = 0; velY[i] -= friction(velY[i]); velY[i] *= -1; } @@ -54,7 +54,7 @@ void draw() { /*****************/ float powerThreeDividedByTwo(float num) { - float result = (sqrt(sq(num)*(num))); + float result = (sqrt((sq(num))*(num))); return result; } From 12495024442519991f307ade7acc1c2146f893e4 Mon Sep 17 00:00:00 2001 From: kevininthetardis Date: Sun, 13 Dec 2015 21:44:10 -0500 Subject: [PATCH 5/5] still having issues with the bouncy bit but i added the function that draws a thing --- ReturningValues/ReturningValues.pde | 40 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/ReturningValues/ReturningValues.pde b/ReturningValues/ReturningValues.pde index 55a052c..32d9a79 100644 --- a/ReturningValues/ReturningValues.pde +++ b/ReturningValues/ReturningValues.pde @@ -1,34 +1,34 @@ -float[] d = new float[15]; +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); - for (int i = 0; i < 15; i++) { - d[i] = 3*powerThreeDividedByTwo(i); - x[i] = random(width); + 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); + velX[i] = random(1, 10); //speed is random velY[i] = random(1, 10); } } void draw() { - background(255); + background(0); //background refreshes so balls don't leave a trail of stationary christmas ornaments for (int i = 0; i < 15; i++) { - noStroke(); - if (i%2==0) { + 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]); + x[i] += (velX[i]); //position changes by velocity y[i] += (velY[i]); - if (x[i] + d[i]/2 > width) { + 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; @@ -49,16 +49,28 @@ void draw() { velY[i] *= -1; } } + holidayCheer(); //pretty lights! i managed to decorate my code for the holidays } /*****************/ -float powerThreeDividedByTwo(float num) { +float powerThreeDividedByTwo(float num) { //returns a number^(3/2) float result = (sqrt((sq(num))*(num))); return result; } -float friction(float vel) { +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; -} \ No newline at end of file +} + +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 + } +}