From fb74b12a0ef137c8d8d356c582881a2bd697f170 Mon Sep 17 00:00:00 2001 From: storm-lin Date: Wed, 9 Dec 2015 08:58:36 -0500 Subject: [PATCH 1/8] Set up Text and Function Parameters --- FunctionsChallenge/FunctionsChallenge.pde | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 FunctionsChallenge/FunctionsChallenge.pde diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde new file mode 100644 index 0000000..9ab85a9 --- /dev/null +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -0,0 +1,29 @@ +PFont fon; +void setup() +{ + fon = createFont("Trebuchet MS", 24); + size(800, 600); +} +void draw() +{ + background(255); + textFont(fon); + fill(0); + textAlign(LEFT); + text("Hello World!", 50, 50); +} +float geometricSeries(float a, float r, int n)//first term, common ratio, number of terms +{ + return 0; +} +float geometricSeries(float a, float r)//first term, common ratio(calculates to infinity) +{ + return 0; +} +float orbitalPeriod(float m1, float m2, float a)//first mass, second mass, average distance between them +{ + return 0; +} +void command(float x, float y, float d, float n)//x coordinate, y coordinate, diameter, number of rings +{ +} \ No newline at end of file From f9fdbfc5be2574cea9327d3ceeb5a81cc4053176 Mon Sep 17 00:00:00 2001 From: storm-lin Date: Wed, 9 Dec 2015 09:11:12 -0500 Subject: [PATCH 2/8] Completed Bullseye Function --- FunctionsChallenge/FunctionsChallenge.pde | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde index 9ab85a9..3129081 100644 --- a/FunctionsChallenge/FunctionsChallenge.pde +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -6,11 +6,14 @@ void setup() } void draw() { - background(255); + background(200); textFont(fon); fill(0); textAlign(LEFT); text("Hello World!", 50, 50); + 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 { @@ -24,6 +27,20 @@ float orbitalPeriod(float m1, float m2, float a)//first mass, second mass, avera { return 0; } -void command(float x, float y, float d, float n)//x coordinate, y coordinate, diameter, number of rings +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 + } } \ No newline at end of file From 81ecffdc66eb3f34f747e0da29f966e24b548b4f Mon Sep 17 00:00:00 2001 From: storm-lin Date: Wed, 9 Dec 2015 09:22:31 -0500 Subject: [PATCH 3/8] Completed Orbital Period Function --- FunctionsChallenge/FunctionsChallenge.pde | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde index 3129081..a466c86 100644 --- a/FunctionsChallenge/FunctionsChallenge.pde +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -1,4 +1,7 @@ PFont fon; +float planet = 100; +float star = 1000; +float distance = 25; void setup() { fon = createFont("Trebuchet MS", 24); @@ -10,7 +13,10 @@ void draw() textFont(fon); fill(0); textAlign(LEFT); - text("Hello World!", 50, 50); + text("Planet's Mass: "+planet, 25, 25); + text("Star's Mass: "+star, 25, 50); + text("Average Distance: "+distance, 25, 75); + text("Orbital Period: "+orbitalPeriod(planet, star, distance), 25, 100); bullseye(100, 500, 100, 5); bullseye(300, 450, 200, 5); bullseye(600, 450, 200, 13); @@ -25,6 +31,9 @@ float geometricSeries(float a, float r)//first term, common ratio(calculates to } 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 0; } void bullseye(float x, float y, float d, int n)//x coordinate, y coordinate, diameter, number of rings From 416052a36257931d6aa82f91dd80a7cdf85d1da8 Mon Sep 17 00:00:00 2001 From: storm-lin Date: Wed, 9 Dec 2015 09:23:30 -0500 Subject: [PATCH 4/8] Fixed Orbital Period Return Value --- FunctionsChallenge/FunctionsChallenge.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde index a466c86..f7fc29e 100644 --- a/FunctionsChallenge/FunctionsChallenge.pde +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -34,7 +34,7 @@ float orbitalPeriod(float m1, float m2, float a)//first mass, second mass, avera float numerator = 4*sq(PI)*pow(a,3); float denominator = 6.67*pow(10,-11)*(m1+m2); float answer = sqrt(numerator/denominator); - return 0; + return answer; } void bullseye(float x, float y, float d, int n)//x coordinate, y coordinate, diameter, number of rings { From cdd8793caba3ba3fa4ddd829fc01b3d86feafe37 Mon Sep 17 00:00:00 2001 From: storm-lin Date: Thu, 10 Dec 2015 08:12:51 -0500 Subject: [PATCH 5/8] Added Units and Geometric Series Function --- FunctionsChallenge/FunctionsChallenge.pde | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde index f7fc29e..18d9c8b 100644 --- a/FunctionsChallenge/FunctionsChallenge.pde +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -13,21 +13,28 @@ void draw() textFont(fon); fill(0); textAlign(LEFT); - text("Planet's Mass: "+planet, 25, 25); - text("Star's Mass: "+star, 25, 50); - text("Average Distance: "+distance, 25, 75); - text("Orbital Period: "+orbitalPeriod(planet, star, distance), 25, 100); + 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 { - return 0; + 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) { - return 0; + float answer = a/(1-r); + return answer; } float orbitalPeriod(float m1, float m2, float a)//first mass, second mass, average distance between them { From a0ae02e44133311efc89ec24cd3818396195b3df Mon Sep 17 00:00:00 2001 From: storm-lin Date: Thu, 10 Dec 2015 09:03:46 -0500 Subject: [PATCH 6/8] Documentation for Geometric Series --- Documentation1.md | 19 ------------------- geometricSeries.md | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 19 deletions(-) delete mode 100644 Documentation1.md create mode 100644 geometricSeries.md diff --git a/Documentation1.md b/Documentation1.md deleted file mode 100644 index 28f94fa..0000000 --- a/Documentation1.md +++ /dev/null @@ -1,19 +0,0 @@ -# Name: - -## Examples: -Insert examples here. - -## Description: -Insert description here - -## Syntax: -Demonstrate syntax here - -##Parameters: -Name and describe parameters here - -##Returns: -What type of data does it return? - -##Other notes: -Anything else? diff --git a/geometricSeries.md b/geometricSeries.md new file mode 100644 index 0000000..d2d8c0c --- /dev/null +++ b/geometricSeries.md @@ -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. \ No newline at end of file From 2eb78491d17d0aeee321f358e5e8bc5c70bc05f9 Mon Sep 17 00:00:00 2001 From: storm-lin Date: Thu, 10 Dec 2015 09:22:49 -0500 Subject: [PATCH 7/8] Added Orbital Period Documentation Partially --- Documentation2.md | 19 ------------------- orbitalPeriod.md | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 19 deletions(-) delete mode 100644 Documentation2.md create mode 100644 orbitalPeriod.md diff --git a/Documentation2.md b/Documentation2.md deleted file mode 100644 index 28f94fa..0000000 --- a/Documentation2.md +++ /dev/null @@ -1,19 +0,0 @@ -# Name: - -## Examples: -Insert examples here. - -## Description: -Insert description here - -## Syntax: -Demonstrate syntax here - -##Parameters: -Name and describe parameters here - -##Returns: -What type of data does it return? - -##Other notes: -Anything else? diff --git a/orbitalPeriod.md b/orbitalPeriod.md new file mode 100644 index 0000000..45de67c --- /dev/null +++ b/orbitalPeriod.md @@ -0,0 +1,22 @@ +# Name: +orbitalPeriod() + +## Examples: +float time = orbitalPeriod(20000, 80, 2800);//time holds a value close to 804160000.0 + +## Description: +Insert description here + +## 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: +Anything else? \ No newline at end of file From 82332e80f27ebd1dba69f91c9be7500236839205 Mon Sep 17 00:00:00 2001 From: storm-lin Date: Fri, 11 Dec 2015 08:49:21 -0500 Subject: [PATCH 8/8] Finished Function Documentation --- Documentation3.md | 19 ------------------- bullseye.md | 23 +++++++++++++++++++++++ orbitalPeriod.md | 4 ++-- 3 files changed, 25 insertions(+), 21 deletions(-) delete mode 100644 Documentation3.md create mode 100644 bullseye.md diff --git a/Documentation3.md b/Documentation3.md deleted file mode 100644 index 28f94fa..0000000 --- a/Documentation3.md +++ /dev/null @@ -1,19 +0,0 @@ -# Name: - -## Examples: -Insert examples here. - -## Description: -Insert description here - -## Syntax: -Demonstrate syntax here - -##Parameters: -Name and describe parameters here - -##Returns: -What type of data does it return? - -##Other notes: -Anything else? diff --git a/bullseye.md b/bullseye.md new file mode 100644 index 0000000..16595b0 --- /dev/null +++ b/bullseye.md @@ -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. \ No newline at end of file diff --git a/orbitalPeriod.md b/orbitalPeriod.md index 45de67c..89a6788 100644 --- a/orbitalPeriod.md +++ b/orbitalPeriod.md @@ -5,7 +5,7 @@ orbitalPeriod() float time = orbitalPeriod(20000, 80, 2800);//time holds a value close to 804160000.0 ## Description: -Insert description here +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) @@ -19,4 +19,4 @@ a float: average distance between the two objects during orbit float ##Other notes: -Anything else? \ No newline at end of file +None \ No newline at end of file