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
19 changes: 0 additions & 19 deletions Documentation1.md

This file was deleted.

19 changes: 0 additions & 19 deletions Documentation2.md

This file was deleted.

19 changes: 0 additions & 19 deletions Documentation3.md

This file was deleted.

36 changes: 36 additions & 0 deletions FunctionsChallenge/Functions.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
float findPermutation(float data, float places) {
//change the value of places to use it in the denominator
float denominator = data-places;
//set i equal to the denominator value minus one so that every time it goes through the for loop it multiplies by 1 less which simulates the factorial function
for (float i=denominator-1; i>=1; i--) {
denominator*=i;
}
//use the factorial method again for the numerator
for (float i=data-1; i>=1; i--) {
data=data*i;
}
//divide the two factorials found
float result= data/denominator;
//return the result
return result;
}

float findAcceleration(float vi, float vf, float t) {
//use the acceleration equation to find acceleration
float acceleration = (vf-vi)/t;
//return the value
return acceleration;
}
void addAcceleration() {
//add acceleration to the object
for (int i=0; i<count; i++) {
//if the acceleration is less than 1...
if (a<=1) {
//...add acceleration
vy[i]+=a;
} else { //if not...
//...reset the velocity to 1
vy[i]=1;
}
}
}
59 changes: 59 additions & 0 deletions FunctionsChallenge/FunctionsChallenge.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//declare and initialize variables
float vf, a;
int count=25;
//declare arrays
float []x= new float[count];
float []y= new float[count];
float []d= new float[count];
float []vx= new float[count];
float []vy= new float[count];
float []r= new float[count];
float []g= new float[count];
float []b= new float[count];

void setup() {
//draw canvas
size(500, 500);
//initialize arrays
for (int i=0; i<count; i++) {
x[i] = random(width);
y[i] = random(height);
d[i] = random(80);
vx[i] = random(-5, 5);
vy[i] = random(-5, 5);
r[i] = random(255);
g[i] = random(255);
b[i] = random(255);
}
}

void draw() {
//draw a background
background(255);
for (int i=0; i<count; i++) {
//draw ball
noStroke();
fill(r[i],g[i],b[i]);
ellipse(x[i], y[i], d[i], d[i]);
//add velocity
x[i] += vx[i];
y[i] += vy[i];
//bounce ball if it hits walls
if (x[i] + d[i]/2 >= width) {
vx[i] = -abs(vx[i]); //if the ball hits the right wall, assign x velocity the negative version of itself
} else if (x[i] - d[i]/2 <= 0) {
vx[i] = abs(vx[i]); //if the ball hits the left wall, assign x velocity the positive version of itself
}
if (y[i] + d[i]/2 >= height) {
vy[i] = -abs(vy[i]);
y[i] = height - d[i]/2;
} else if (y[i] - d[i]/2 <= 0) {
vy[i] = abs(vy[i]);
}
}
//initialize variables
vf=findPermutation(random(0, 1), random(0, 1));
a=findAcceleration(0, vf, 10);
//add acceleration to objects
addAcceleration();
}
26 changes: 26 additions & 0 deletions addAcceleration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Name: addAcceleration

## Examples:
Increase or decrease the speed that the objects move.

## Description:
Add acceleration to the objects by increasing or decreasing the velocity in each frame.

## Syntax:
void addAcceleration() {
for (int i=0; i<count; i++) {
if (a<=1) {
vy[i]+=a;
} else {
vy[i]=1;
}
}

##Parameters:
No parameters

##Returns:
No return.

##Other notes:
In my syntax, there is an if statement that will make sure the acceleration doesn't increase too much.
25 changes: 25 additions & 0 deletions findAcceleration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Name: findAcceleration

## Examples:
In 2 seconds, the ball goes from 3m/s to 5 m/s, determine its acceleration.

## Description:
If you know the initial and final velocity of an object over a certain amount of time, you can find the acceleration.
All you have to do is divide the change in velocity by the time.

## Syntax:
float findAcceleration(float vi, float vf, float t) {
float acceleration = (vf-vi)/t;
return acceleration;
}

##Parameters:
vi is the initial velocity which, in the example, is 3.
vf is the final velocity which, in the example, is 5.
t is the amount of time which, in the example, is 2.

##Returns:
This function returns a number that represents the acceleration of the object.

##Other notes:
You can add this value to the velocity that is there to give the object acceleration.
34 changes: 34 additions & 0 deletions findPermutation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Name: findPermutation

## Examples:
If there were 5 children running in a race, determine how many ways these children could win first, second, and third place. Using the permutation formula will give the answer quicker than trying to list every possibility.

## Description:
To find the number of ways that certain amount of data can be ordered in a certain amount of places, this function uses the permutation formula. The permutation formla is the factorial of the amount of data divided by the factorial of the data minus the number of places.

## Syntax:
float findPermutation(float data, float places) {
float denominator = data-places; //change the value of places to use it in the denominator
//set i equal to the denominator value minus one so that every time it goes through the for loop it multiplies by 1 less which simulates the factorial function
for (float i=denominator-1; i>=1; i--) {
denominator*=i;
}
//use the factorial method again for the numerator
for (float i=data-1; i>=1; i--) {
data=data*i;
}
float result= data/denominator; //divide the two factorials found
return result; //return the result
}

##Parameters:
The data parameter tells how many objects can be used to fill the requirement. In the example, this would be the 5 children.
The places parameter tells how many spaces can be filled by the objects. In the example, this would be the 3 places or 1st, 2nd, and 3rd place.
If you are using this function to return a random value you can put something like random(0,1) for the parameters in the loop so that you get a random value.

##Returns:
This function returns the number of ways the data can be put in the places.
If you are using it to get a random number you will get a random value in return.

##Other notes:
In my code, I used this functions to return a random value each time it went through the loop.