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
14 changes: 7 additions & 7 deletions Documentation1.md
Original file line number Diff line number Diff line change
@@ -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
15 changes: 9 additions & 6 deletions Documentation2.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions Documentation3.md
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions FunctionsChallenge/FunctionsChallenge.pde
Original file line number Diff line number Diff line change
@@ -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);
}