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.

62 changes: 62 additions & 0 deletions FunctionsChallenge/FunctionsChallenge.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
PFont fon;
float planet = 100;
float star = 1000;
float distance = 25;
void setup()
{
fon = createFont("Trebuchet MS", 24);
size(800, 600);
}
void draw()
{
background(200);
textFont(fon);
fill(0);
textAlign(LEFT);
text("Planet's Mass: "+planet+" kg", 25, 25);
text("Star's Mass: "+star+" kg", 25, 50);
text("Average Distance: "+distance+" m", 25, 75);
text("Orbital Period: "+orbitalPeriod(planet, star, distance)+" s", 25, 100);
text("Geometric Sequence: 10*(0.5)^n", 25, 150);
text("Sum of First 10 Terms: "+geometricSeries(10, 0.5, 10), 25, 175);
text("Sum of Infinite Series: "+geometricSeries(10, 0.5), 25, 200);
bullseye(100, 500, 100, 5);
bullseye(300, 450, 200, 5);
bullseye(600, 450, 200, 13);
}
float geometricSeries(float a, float r, int n)//first term, common ratio, number of terms
{
float numerator = 1-pow(r,n);
float denominator = 1-r;
float answer = a*(numerator/denominator);
return answer;
}
float geometricSeries(float a, float r)//first term, common ratio(calculates to infinity)
{
float answer = a/(1-r);
return answer;
}
float orbitalPeriod(float m1, float m2, float a)//first mass, second mass, average distance between them
{
float numerator = 4*sq(PI)*pow(a,3);
float denominator = 6.67*pow(10,-11)*(m1+m2);
float answer = sqrt(numerator/denominator);
return answer;
}
void bullseye(float x, float y, float d, int n)//x coordinate, y coordinate, diameter, number of rings
{
boolean red = true;//stores whether or not the next circle is red
for(int i = n; i > 0; i--)//for each ring from the outside in
{
if(red)//fill the circle red
{
fill(255, 0, 0);
}
else//or fill the circle white
{
fill(255);
}
ellipse(x, y, i*(d/n), i*(d/n));//draw the ring
red = !red;//alternate between red and white
}
}
23 changes: 23 additions & 0 deletions bullseye.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Name:
bullseye()

## Examples:
bullseye(width / 2, height / 2, 200, 8);//draws a bullseye 200 pixels in diameter in the middle of the canvas with 8 rings which are each 25 pixels wide

## Description:
Draws a bullseye at the specified location. You can specify the diameter and number of rings. The rings are of equal width and alternate between red and white color.

## Syntax:
bullseye(x, y, d, n)

##Parameters:
x float: x-coordinate of the center of the bullseye
y float: y-coordinate of the center of the bullseye
d float: maximum diameter of the bullseye
n int: the number of rings the bullseye contains

##Returns:
void

##Other notes:
The outermost ring will always be red.
24 changes: 24 additions & 0 deletions geometricSeries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#Name:
geometricSeries()

##Examples:
float q = geometricSeries(10, 2, 3);//q now holds 70.0
float r = geometricSeries(0.9, 0.1);//r now holds 1.0

##Description:
Calculates the sum of a geometric series and returns that value. Defines a series by its first term and its common ratio. Can be calculated for a defined number of terms or to infinity.

##Syntax:
geometricSeries(a, r, n)
geometricSeries(a, r)

##Parameters:
a float: first term of the series
r float: common ratio between each term in the series
n int: number of terms of the series to sum

##Returns:
float

##Other notes:
Gives an error when r is 1. Returns incorrect values when r is not greater than or equal to 0 and less than 1.
22 changes: 22 additions & 0 deletions orbitalPeriod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Name:
orbitalPeriod()

## Examples:
float time = orbitalPeriod(20000, 80, 2800);//time holds a value close to 804160000.0

## Description:
Returns the orbital period of a two-body gravitational system given both masses and the average distance between them. Uses the equation from Kepler's Third Law. This takes the masses in kilograms and the distance in meters. It returns the period in seconds.

## Syntax:
orbitalPeriod(m1, m2, a)

##Parameters:
m1 float: mass of the first object
m2 float: mass of the second object
a float: average distance between the two objects during orbit

##Returns:
float

##Other notes:
None