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 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 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 diff --git a/FunctionsChallenge/FunctionsChallenge.pde b/FunctionsChallenge/FunctionsChallenge.pde new file mode 100644 index 0000000..a3e0236 --- /dev/null +++ b/FunctionsChallenge/FunctionsChallenge.pde @@ -0,0 +1,42 @@ +//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) { + 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"; +} + +//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*d); +} + +//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(800,600); +} + +void draw() { + background(0); + text(frac(8.8490396),0,height); + fill(255); + sier(6,0,0); +} \ No newline at end of file