From a2b338a1fc4a5f9526b532084017a1a8bf94640f Mon Sep 17 00:00:00 2001 From: allwhen Date: Wed, 9 Dec 2015 08:36:51 -0500 Subject: [PATCH 1/7] math function done --- FunctionsChallenge/FunctionsChallenge.pde | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 FunctionsChallenge/FunctionsChallenge.pde diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde new file mode 100644 index 0000000..e3c50e8 --- /dev/null +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -0,0 +1,24 @@ +//creates a fake fraction string very close to given float value +String frac(float x) { + for (int i = 1; i<1000000; i++) { + if (abs(i*x-round(i*x))<0.000001) { + String s = str(round(i*x)); + String t = str(i); + String a = s+ "/" +t; + return a; + } + } + //if we take denominator to a million and can't find something close enough + return "no approximation with desired precision"; +} + + + +void setup() { + size(150,150); +} + +void draw() { + background(0); + text(frac(8.8490396),width/2,height/2); +} \ No newline at end of file From 82d6dc66c1871869ac5910e9bbe4c032f63cb655 Mon Sep 17 00:00:00 2001 From: allwhen Date: Wed, 9 Dec 2015 09:13:26 -0500 Subject: [PATCH 2/7] Gravitational force function done --- FunctionsChallenge/FunctionsChallenge.pde | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde index e3c50e8..a9c98a2 100644 --- a/FunctionsChallenge/FunctionsChallenge.pde +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -1,4 +1,4 @@ -//creates a fake fraction string very close to given float value +//creates a fake fraction string very close to or exactly given float value String frac(float x) { for (int i = 1; i<1000000; i++) { if (abs(i*x-round(i*x))<0.000001) { @@ -12,6 +12,12 @@ String frac(float x) { return "no approximation with desired precision"; } +//gravitational force between two objects given positions and masses +float grav(float m1, PVector r1, float m2, PVector r2) { + float d = r1.dist(r2); + return 0.0000000000667408*m1*m2/d; +} + void setup() { From b038d653051878f79eb1c3da1ae7a48ae5b37660 Mon Sep 17 00:00:00 2001 From: allwhen Date: Wed, 9 Dec 2015 09:22:57 -0500 Subject: [PATCH 3/7] minor changes --- FunctionsChallenge/FunctionsChallenge.pde | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde index a9c98a2..5697c00 100644 --- a/FunctionsChallenge/FunctionsChallenge.pde +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -15,10 +15,12 @@ String frac(float x) { //gravitational force between two objects given positions and masses float grav(float m1, PVector r1, float m2, PVector r2) { float d = r1.dist(r2); - return 0.0000000000667408*m1*m2/d; + return 0.0000667408*m1*m2/d; } - +void koch() { + +} void setup() { size(150,150); From a703803556069e3ef499743e83005ca7c65ee232 Mon Sep 17 00:00:00 2001 From: allwhen Date: Thu, 10 Dec 2015 08:56:05 -0500 Subject: [PATCH 4/7] Sierpinsky triangle function Also change in size of window, fix to gravity function --- FunctionsChallenge/FunctionsChallenge.pde | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde index 5697c00..a3e0236 100644 --- a/FunctionsChallenge/FunctionsChallenge.pde +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -15,18 +15,28 @@ String frac(float x) { //gravitational force between two objects given positions and masses float grav(float m1, PVector r1, float m2, PVector r2) { float d = r1.dist(r2); - return 0.0000667408*m1*m2/d; + return 0.0000000000667408*m1*m2/(d*d); } -void koch() { - +//recurses a sierpinsky triangle. k is # of times to recurse +void sier(int k, float x, float y) { + if (k == 0) { + triangle(x,y,x+5,y+8.66,x+10,y); + } + else { + sier(k-1,x,y); + sier(k-1,x+(10*pow(2,k-1)),y); + sier(k-1,x+(5*pow(2,k-1)),y+(8.66*pow(2,k-1))); + } } void setup() { - size(150,150); + size(800,600); } void draw() { background(0); - text(frac(8.8490396),width/2,height/2); + text(frac(8.8490396),0,height); + fill(255); + sier(6,0,0); } \ No newline at end of file From 27c2c121df9cbe62dd9a5d9f34d5bf7ea0a8ef5a Mon Sep 17 00:00:00 2001 From: allwhen Date: Mon, 14 Dec 2015 23:44:49 -0500 Subject: [PATCH 5/7] Update Documentation1.md --- Documentation1.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Documentation1.md b/Documentation1.md index 28f94fa..11c24dd 100644 --- a/Documentation1.md +++ b/Documentation1.md @@ -1,19 +1,19 @@ -# Name: +# Name: frac() ## Examples: -Insert examples here. +frac(PI) = 335/113 ## Description: -Insert description here +Takes a float and returns a fractional approximation of it. ## Syntax: -Demonstrate syntax here +frac(float x); ##Parameters: -Name and describe parameters here +float x: the float you want to approximate ##Returns: -What type of data does it return? +String ##Other notes: -Anything else? +None From e2fa759224c3ff099914d142c0de98e5d061e853 Mon Sep 17 00:00:00 2001 From: allwhen Date: Mon, 14 Dec 2015 23:46:49 -0500 Subject: [PATCH 6/7] Update Documentation2.md --- Documentation2.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Documentation2.md b/Documentation2.md index 28f94fa..89d8fc4 100644 --- a/Documentation2.md +++ b/Documentation2.md @@ -1,19 +1,22 @@ # Name: +grav() ## Examples: -Insert examples here. +grav(25,r1,34,r2) = something ## Description: -Insert description here +gives gravitational force between two objects given their masses and positions ## Syntax: -Demonstrate syntax here +grav(m1,r1,m2,r2); ##Parameters: -Name and describe parameters here +m1: mass of 1st object +r1: position vector of 1st object +m2,r2: mass and position of 2nd object ##Returns: -What type of data does it return? +float ##Other notes: -Anything else? +None From 158e30f04376232479f67a9714efb25a9fc0bdef Mon Sep 17 00:00:00 2001 From: allwhen Date: Mon, 14 Dec 2015 23:48:18 -0500 Subject: [PATCH 7/7] Update Documentation3.md --- Documentation3.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Documentation3.md b/Documentation3.md index 28f94fa..5b5b079 100644 --- a/Documentation3.md +++ b/Documentation3.md @@ -1,19 +1,19 @@ -# Name: +# Name: sier() ## Examples: -Insert examples here. +sier(5) gives 6-iteration of sierpinsky triangle ## Description: -Insert description here +draws sierpinsky triangle recursively ## Syntax: -Demonstrate syntax here +sier(int k); ##Parameters: -Name and describe parameters here +k is the number of iterations to go through in making triangle, starting from 0 as one triangle. ##Returns: -What type of data does it return? +Does not return data ##Other notes: -Anything else? +None