Skip to content

Commit

Permalink
phyllotaxic spiral
Browse files Browse the repository at this point in the history
  • Loading branch information
mayakraft committed Jul 26, 2016
1 parent 057f61f commit f5857b5
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 212 deletions.
2 changes: 1 addition & 1 deletion 01-archimedean-spiral/002-in-out-sine-wave.c
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char **argv){
}
}

// OPTIONAL: pick up the pen when it gets to the middle
// // OPTIONAL: pick up the pen when it gets to the middle
// fprintf(file, "\"/>\n"); // closing quote
// fprintf(file, "<polyline fill=\"none\" stroke=\"#000000\" points=\""); // hanging open quote

Expand Down
75 changes: 75 additions & 0 deletions 01-archimedean-spiral/004-in-out-phyllotaxic-join.c
@@ -0,0 +1,75 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>

#include "../common/noise.c"

#define TWOPI 6.28318530718

// output
char filename[128] = "004-phyllotaxic-join.svg\0";
char path[128] = "out/\0";

// document
int width = 800;
int height = 800;

// shape
int REVOLUTIONS = 8;
float SPACING = 7.0f;

int main(int argc, char **argv){
time_t t;
srand((unsigned) time(&t));
float seed = rand()%1000/100.0;

strcat(path, filename);
FILE *file = fopen(path, "w");
// HEADER
fprintf(file, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
fprintf(file, "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" ");
fprintf(file, "x=\"0px\" y=\"0px\" width=\"%dpx\" height=\"%dpx\" ", width, height);
fprintf(file, "viewBox=\"0 0 %d %d\">\n", width, height);
// BODY
fprintf(file, "<g>\n");
fprintf(file, "<polyline fill=\"none\" stroke=\"#000000\" points=\""); // hanging open polyline

float divider = 10 * 60;
float wobbleFreq = 13.0;
float wobbleMag = 1;
// wobbleFreq = 7.0;
// wobbleMag = 0.33;

for(int i = REVOLUTIONS-1; i >= 0; i--){
for(float a = TWOPI; a >= 0; a -= TWOPI/divider){
float revolution = 2*(i+a/TWOPI);
float SCALE = 1.5 * revolution;
float x = width*.5 + cos(a) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag );
float y = height*.5 + sin(a) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag );
fprintf(file, "%.2f,%.2f ", x, y);
}
}

// // OPTIONAL: pick up the pen when it gets to the middle
// fprintf(file, "\"/>\n"); // closing polyline
// fprintf(file, "<polyline fill=\"none\" stroke=\"#000000\" stroke-miterlimit=\"10\" points=\""); // hanging open polyline

for(int i = 0; i < REVOLUTIONS; i++){
for(float a = 0; a < TWOPI; a += TWOPI/divider){
float revolution = 2*(i+a/TWOPI);
float SCALE = 1.5 * revolution;
float x = width*.5 + cos(a-TWOPI*.5) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag );
float y = height*.5 + sin(a-TWOPI*.5) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag );
fprintf(file, "%.2f,%.2f ", x, y);
}
}

fprintf(file, "\"/>\n"); // closing polyline

fprintf(file, "</g>\n");
fprintf(file, "</svg>");
fclose(file);
return 0;
}
89 changes: 89 additions & 0 deletions 01-archimedean-spiral/004-in-out-phyllotaxic.c
@@ -0,0 +1,89 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>

#include "../common/noise.c"

#define TWOPI 6.28318530718

// output
char filename[128] = "004-phyllotaxic.svg\0";
char path[128] = "out/\0";

// document
int width = 800;
int height = 800;

// shape
int REVOLUTIONS = 6;
float SPACING = 7.0f;

int main(int argc, char **argv){
time_t t;
srand((unsigned) time(&t));
float seed = rand()%1000/100.0;

strcat(path, filename);
FILE *file = fopen(path, "w");
// HEADER
fprintf(file, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
fprintf(file, "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" ");
fprintf(file, "x=\"0px\" y=\"0px\" width=\"%dpx\" height=\"%dpx\" ", width, height);
fprintf(file, "viewBox=\"0 0 %d %d\">\n", width, height);
// BODY
fprintf(file, "<g>\n");
fprintf(file, "<polyline fill=\"none\" stroke=\"#000000\" points=\""); // hanging open polyline

float divider = 5 * 60;
float SCALE = 26;
float wobbleFreq = 19.0;
float wobbleMag = 0.4;
// float SCALE = 45;
// float REVOLUTIONS = 7;
// float wobbleFreq = 7.0;
// float wobbleMag = 0.33;

for(int i = REVOLUTIONS-1; i >= 0; i--){
for(float a = TWOPI; a >= 0; a -= TWOPI/divider){
float revolution = 2*(i+a/TWOPI);
float x = width*.5 + cos(a) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag);
float y = height*.5 + sin(a) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag);
fprintf(file, "%.2f,%.2f ", x, y);
}
}

// // OPTIONAL: pick up the pen when it gets to the middle
// fprintf(file, "\"/>\n"); // closing quote
// fprintf(file, "<polyline fill=\"none\" stroke=\"#000000\" stroke-miterlimit=\"10\" points=\""); // hanging open quote

for(int i = 0; i < REVOLUTIONS; i++){
for(float a = 0; a < TWOPI; a += TWOPI/divider){
float revolution = 2*(i+a/TWOPI);
float x = width*.5 + cos(a-TWOPI*.5) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag);
float y = height*.5 + sin(a-TWOPI*.5) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag);
fprintf(file, "%.2f,%.2f ", x, y);
}
}

// fprintf(file, "\"/>\n"); // closing quote
// fprintf(file, "<polyline fill=\"none\" stroke=\"#000000\" stroke-miterlimit=\"10\" points=\""); // hanging open quote

// int i = 14;
// for(float a = 0; a <= TWOPI+.0001; a += TWOPI/divider){
// float wobbleIncr = 5*sqrt(i + 2*a/TWOPI);
// wobbleIncr = 1.0;
// x = width*.5 + SCALE * cos(a) * (i + sin(a*wobbleFreq)*wobbleMag*wobbleIncr );
// y = height*.5 + SCALE * sin(a) * (i + sin(a*wobbleFreq)*wobbleMag*wobbleIncr );
// fprintf(file, "%.2f,%.2f ", x, y);
// }

//+ cos(turn) * .2*sqrt(i + 2*a/TWOPI)
fprintf(file, "\"/>\n"); // closing quote

fprintf(file, "</g>\n");
fprintf(file, "</svg>");
fclose(file);
return 0;
}
97 changes: 0 additions & 97 deletions 01-archimedean-spiral/spiral-phyllotaxic-touching.c

This file was deleted.

109 changes: 0 additions & 109 deletions 01-archimedean-spiral/spiral-phyllotaxic.c

This file was deleted.

0 comments on commit f5857b5

Please sign in to comment.