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
64 changes: 64 additions & 0 deletions CalculateAngleVectors/CalculateAngleVectors.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
void setup(){
background(0);
size(800,800);
}

void draw(){
angleBetweenVectorsRect(5,5,-5,-5); //functions defined below...
//angleBetweenVectorsPol(sqrt(50), sqrt(50), 45, 225);
}

float angleBetweenVectorsRect(float ax, float ay, float bx, float by){ //this function finds the angle if components are given
textAlign(CENTER);
textSize(20);
text("The angle between a vector A with components " + ax + " and " + ay + "\n and a vector B with components " + bx + " and " + by + " is:", width/2, 200);
textSize(80);
text(round(degrees(acos(AxBx_AyBy(ax, ay, bx, by)/AB(ax, ay, bx, by)))), width/2, height/2); //uses dot product to find angle : https://en.wikipedia.org/wiki/Dot_product A.B = AxBx + AyBy = |A||B|cos angle
return acos(AxBx_AyBy(ax, ay, bx, by)/AB(ax, ay, bx, by));
}

float AxBx_AyBy(float ax, float ay, float bx, float by){ //part of the formula in line 16
return ax*bx+ay*by; //just a simple calculation that makes line 16 more legible
}

float AB(float ax, float ay, float bx, float by){ //also part of the formula in line 16
return sqrt(pow(ax, 2) + pow(ay,2))*sqrt(pow(bx,2) + pow(by, 2)); //using Pythagorean theorem to find the magnitude of the vectors and multiplying them together
}

/********************************************************************
//I just realized that the rest of this code is useless, because you can just do 225 - 45 = 180 and bypass all of these calculations. It still works, so if you want, get rid of the comment


float angleBetweenVectorsPol(float A, float B, float angleA, float angleB){ //this function finds the angle if the magnitude and ANGLE are given
float ax = XcomponentA(A, angleA); //finds components using trigonometry and functions below
float ay = YcomponentA(A, angleA);
float bx = XcomponentB(B, angleB);
float by = YcomponentB(B, angleB);
textSize(20);
text("The angle between a vector A of magnitude " + A + " at an angle of " + angleA + "\n and a vector B of magnitude " + B + " at an angle of " + angleB + " is:", width/2, 500);
textSize(80);
text(round(degrees(acos(AxBx_AyBy(ax, ay, bx, by)/AB(ax, ay, bx, by)))), width/2, 700);
return acos(AxBx_AyBy(ax, ay, bx, by)/AB(ax, ay, bx, by));
}

float XcomponentA(float A, float angleA){
float ax = A * cos(radians(angleA));
return ax;
}

float YcomponentA(float A, float angleA){
float ay = A * sin(radians(angleA));
return ay;
}

float XcomponentB(float B, float angleB){
float bx = B * cos(radians(angleB));
return bx;
}

float YcomponentB(float B, float angleB){
float by = B * sin(radians(angleB));
return by;
}

*********************************************************************/
Binary file added Documentation.docx
Binary file not shown.
118 changes: 118 additions & 0 deletions Galaga/Galaga.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
float circleX = 30; //declare and initialize variables
float start = -11;

void setup() {
frameRate(30); //this eases later calculations
size(400, 400);
background(0);
}

void draw() {
background(0);
noStroke();
displayShip(); //functions defined below
bubble();
if (mousePressed) { //if mouse pressed, ...
fireProjectile(); //create the projectile
moveProjectile(); //and move it (as long as the mouse is held
if(mouseX >= 10 && mouseX <= 50){ //if projectile is firing within range of the circle, ..
println("HIT"); //print HIT to the console
}
}
if(keyPressed){ //if a key is pressed, ...
start = -11; //projectile is reloaded
}
}

void displayShip() { //defines the shape of the ship (as a series of 8-bit squares)
rectMode(CENTER); //define rectangles according to the center; makes later calculations easier
fill(255); //let's start with white squares
rectangle(0, 0); //origin
rectangle(0, -1);
rectangle(0, -2);
rectangle(0, -3);
rectangle(-1, -2);
rectangle(1, -2);
rectangle(-2, -2);
rectangle(2, -2);
rectangle(-2, -3);
rectangle(2, -3);
rectangle(-2, -4);
rectangle(2, -4);
rectangle(-3, -2);
rectangle(3, -2);
rectangle(-3, -3);
rectangle(3, -3);
rectangle(4, -2);
rectangle(-4, -2);
rectangle(4, -1);
rectangle(-4, -1);
rectangle(5, 0);
rectangle(-5, 0);
rectangle(5, -1);
rectangle(-5, -1);
rectangle(5, -2);
rectangle(-5, -2);
rectangle(5, -3);
rectangle(-5, -3);
rectangle(-3, -5);
rectangle(3, -5);
rectangle(-3, -6);
rectangle(3, -6);
rectangle(0, -6);
rectangle(1, -6);
rectangle(-1, -6);
rectangle(1, -5);
rectangle(-1, -5);
rectangle(0, -7);
rectangle(1, -7);
rectangle(-1, -7);
rectangle(0, -8);
rectangle(0, -9);
rectangle(0, -10);
fill(255, 0, 0); //red squares
rectangle(1, -1);
rectangle(-1, -1);
rectangle(2, -1);
rectangle(-2, -1);
rectangle(1, -3);
rectangle(-1, -3);
rectangle(0, -4);
rectangle(1, -4);
rectangle(-1, -4);
rectangle(0, -5);
rectangle(5, -4);
rectangle(-5, -4);
rectangle(3, -7);
rectangle(-3, -7);
fill(0, 0, 255); //blue squares
rectangle(2, -5);
rectangle(-2, -5);
rectangle(3, -4);
rectangle(-3, -4);
}

void rectangle(float x, float y) { //defining the function rectangle() in relation to mouse's x-position and a constant height value
rect(mouseX + 3*x, (height-10) + 3*y, 3, 3); //squares are 3x3 pixels
}

void bubble() { //defining the target to be hit
stroke(100, 255, 50); //some type of green
strokeWeight(2); //outline of 2px
fill(100,255,50, 50); //fill with some transparency
ellipse(30, 120, 20, 20); //create the circle
}

void fireProjectile(){ //defining launching the projectile, which is basically a white 1x2 rectangle
noStroke();
fill(255);
rectangle(0, start);
rectangle(0, start-1);
}

void moveProjectile(){ //defining moving the projectile every frame
if(frameCount%1 == 0){
start = start - 1; //moves projectile up
fireProjectile(); //redisplay projectile
}
}
29 changes: 29 additions & 0 deletions primeNumbers.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
void setup() {
size(100, 100); //display is not necessary, but I couldn't find a way to bring it to text
background(0);
}

void draw() {
println(primeSieve(0, 100)); //executes function below
}

IntList primeSieve(int start, int finish) {
IntList list = new IntList(); //creates blank IntList
for (int number = start; number < finish; number++) { //tests if prime for numbers between start and finish
boolean prime = true; //originally every number is considered prime
for (int i = 2; i < number; i++) { //divides numbers by all numbers leading up to it
if (number%i == 0) { //if it turns out to factor out equally, ...
prime = false; //the number is no longer deemed prime
}
}
if (prime) { //adds all prime numbers to the blank IntList
list.append(number);
}
}
list.remove(0); //remove 0 from list (assuming you start at 0)
list.remove(0); //remove 1 from list (assuming you start at 0)
for(int x = 0; x < list.size(); x++){ //for each value in the IntList, ...
println(str(list.get(x))); //print it to the console
}
return list; //return the list (although it is not used for anything outside of the function)
}
29 changes: 29 additions & 0 deletions primeNumbers/primeNumbers.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
void setup() {
size(100, 100); //display is not necessary, but I couldn't find a way to bring it to text
background(0);
}

void draw() {
println(primeSieve(0, 100)); //executes function below
}

IntList primeSieve(int start, int finish) {
IntList list = new IntList(); //creates blank IntList
for (int number = start; number < finish; number++) { //tests if prime for numbers between start and finish
boolean prime = true; //originally every number is considered prime
for (int i = 2; i < number; i++) { //divides numbers by all numbers leading up to it
if (number%i == 0) { //if it turns out to factor out equally, ...
prime = false; //the number is no longer deemed prime
}
}
if (prime) { //adds all prime numbers to the blank IntList
list.append(number);
}
}
list.remove(0); //remove 0 from list (assuming you start at 0)
list.remove(0); //remove 1 from list (assuming you start at 0)
for(int x = 0; x < list.size(); x++){ //for each value in the IntList, ...
println(str(list.get(x))); //print it to the console
}
return list; //return the list (although it is not used for anything outside of the function)
}
Binary file added ~$cumentation.docx
Binary file not shown.