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
68 changes: 68 additions & 0 deletions ReturningValues/ReturningValues.pde
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
//declare theta
float theta;

void setup() {
//set size
size(500, 500);
}

//definies float c as the hypotenuse of a right triangle with sides a and b
float c(float a, float b) {
return sqrt(sq(a)+sq(b));
}

void draw() {
//draw background
background(0);

//set modes, initial stroke, initial text size
rectMode(RADIUS);
noStroke();
textSize(15);

//define theta
theta = asin(mouseX/(c(mouseX,width-mouseX)));

pushMatrix();
translate(width/2,height/2);
rotate(theta);
fill(255);
rect(0,0,c(mouseX,width-mouseX)/2,c(mouseX,width-mouseX)/2);
fill(0);
pushMatrix();
translate(0,20-c(mouseX,width-mouseX)/2);
rotate(-theta);
text("c", 0,0);
popMatrix();

pushMatrix();
translate(20-c(mouseX,width-mouseX)/2,0);
rotate(-theta);
text("c", 0,0);
popMatrix();

pushMatrix();
translate(0,c(mouseX,width-mouseX)/2-20);
rotate(-theta);
text("c", 0,0);
popMatrix();

pushMatrix();
translate(c(mouseX,width-mouseX)/2-20,0);
rotate(-theta);
text("c", 0,0);
popMatrix();

pushMatrix();
rotate(-theta);
textSize(30);
text("c²", 0,0);
popMatrix();
popMatrix();

//set stroke and draw line to cursor to indicate what controls the values
stroke(255,0,0);
line(mouseX,0,mouseX,mouseY);

//print values and proof
println("a = " + mouseX + ", b = " + (width-mouseX) + ", c = " + round(c(mouseX, width-mouseX)) + ". (a + b)² = a² + 2ab + b². c² = (a + b)² - 2ab.");
}
62 changes: 62 additions & 0 deletions VoidFunctions/VoidFunctions.pde
Original file line number Diff line number Diff line change
@@ -1 +1,63 @@
//declare variables
int weight = 2;
float x;
float y;
float diam = 10;
int total = 50;
PVector [] lag = new PVector[total];

void setup() {
//set size and strokeweight
size(500, 500);
strokeWeight(weight);

//set lag values initially so that they are not visible
for (int i = 0; i < total; i++) {
lag[i] = new PVector(-diam-weight*total, -diam-weight*total);
}
}

//define square function to include color
void square(float c1, float c2, float c3, float alpha) {
fill(c1, c2, c3, alpha);
rect(width/2-25, height/2-25, 50, 50);
}

//define circle function to include position, diameter, color
void circle(float x, float y, float diam, float c1, float c2, float c3, float alpha) {
fill(c1, c2, c3, alpha);
ellipse(mouseX, mouseY, diam, diam);
}

void draw() {
//draw background
background(0);

//define x as mouseX in case mouse moves within frame
x = mouseX;
y = mouseY;

//set stroke and draw square
stroke(255);
square(255, 255, 255, 128);

//remove fill for ripples
noFill();

//shift values for lag
for (int i = 0; i < total-1; i++) {
lag[i].set(lag[i+1]);
}

//set final lag to mouse position
lag[total-1].set(x, y);

//draw all ripples at location
for (int i = 0; i < total; i++) {
stroke(255, 255*i/(total-1));
ellipse(lag[i].x, lag[i].y, diam+weight*(total-1-i), diam+weight*(total-1-i));
}

//draw circle
circle(x, y, diam, 255, 0, 0, 128);
}