Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,15 @@
|
|||
void setup() {
|
||||
size(410, 230);
|
||||
background(255);
|
||||
fill(0);
|
||||
sTriangle (10, 25, 100, 5);
|
||||
}
|
||||
|
||||
void sTriangle(int x, int y, int l, int n) {
|
||||
if( n == 0) text("*", x, y);
|
||||
else {
|
||||
sTriangle(x, y+l, l/2, n-1);
|
||||
sTriangle(x+l, y, l/2, n-1);
|
||||
sTriangle(x+l*2, y+l, l/2, n-1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
void setup() {
|
||||
print(getSierpinskiTriangle(3));
|
||||
}
|
||||
String getSierpinskiTriangle(int n) {
|
||||
if ( n == 0 ) {
|
||||
return "*";
|
||||
}
|
||||
String s = getSierpinskiTriangle(n-1);
|
||||
String [] split = s.split("\n");
|
||||
int length = split.length;
|
||||
// Top triangle
|
||||
String ns = "";
|
||||
String top = buildSpace((int)pow(2, n-1));
|
||||
for ( int i = 0; i < length; i++ ) {
|
||||
ns += top;
|
||||
ns += split[i];
|
||||
ns += "\n";
|
||||
}
|
||||
// Two triangles side by side
|
||||
for ( int i = 0; i < length; i++ ) {
|
||||
ns += split[i];
|
||||
ns += buildSpace(length-i);
|
||||
ns += split[i];
|
||||
ns += "\n";
|
||||
}
|
||||
return ns.toString();
|
||||
}
|
||||
|
||||
String buildSpace(int n) {
|
||||
String ns = "";
|
||||
while ( n > 0 ) {
|
||||
ns += " ";
|
||||
n--;
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue