From b42b6c8584c547ffad841ce42e031442b5f6a34a Mon Sep 17 00:00:00 2001 From: robbykraft Date: Thu, 28 Jul 2016 00:07:46 -0400 Subject: [PATCH] archimedean / dual spiral sort --- .../000-base.c | 7 +- .../001-noise-mountain.c | 0 01-spiral-archimedean/002-polygons.c | 55 ++++++++++++ 01-spiral-archimedean/out/002-polygons.svg | 6 ++ .../000-in-out.c => 02-spiral-dual/000-base.c | 9 +- .../001-dual-sine-wave.c | 6 +- .../002-dual-logarithmic.c | 19 ++-- .../003-dual-phyllotaxic-2.c | 17 ++-- .../003-dual-phyllotaxic.c | 25 +++--- 02-spiral-dual/out/003-dual-phyllotaxic-2.svg | 6 ++ .../001-origami-mountain.c | 0 .../002-origami-mountain.c | 0 .../003-origami-mountain.c | 0 .../004-origami-mountain.c | 0 .../005-origami-mountain.c | 0 .../006-origami-mountain.c | 0 .../007-continuous.c | 0 .../008-origami-mountain.c | 0 .../lang-wave-curve-1-amplitude.c | 0 .../lang-wave-curve-2-uneven.c | 0 .../lang-wave-curve-3-balanced.c | 0 .../lang-wave-curve-4-tilt.c | 0 .../lang-wave-curve-5-grow.c | 0 .../outer-wave-circle.c | 0 {04-sinewaves => 05-sinewaves}/000-base.c | 0 .../001-study-dihedral-angle.c | 0 05-sinewaves/002-wrapping-sines.c | 86 +++++++++++++++++++ {05-stars => 06-stars}/stars.c | 0 {05-stars => 06-stars}/starsData.c | 0 readme.md | 10 ++- 30 files changed, 196 insertions(+), 50 deletions(-) rename {01-archimedean-spiral => 01-spiral-archimedean}/000-base.c (90%) rename {01-archimedean-spiral => 01-spiral-archimedean}/001-noise-mountain.c (100%) create mode 100644 01-spiral-archimedean/002-polygons.c create mode 100644 01-spiral-archimedean/out/002-polygons.svg rename 01-archimedean-spiral/000-in-out.c => 02-spiral-dual/000-base.c (90%) rename 01-archimedean-spiral/002-in-out-sine-wave.c => 02-spiral-dual/001-dual-sine-wave.c (97%) rename 01-archimedean-spiral/003-in-out-logarithmic.c => 02-spiral-dual/002-dual-logarithmic.c (86%) rename 01-archimedean-spiral/004-in-out-phyllotaxic-join.c => 02-spiral-dual/003-dual-phyllotaxic-2.c (86%) rename 01-archimedean-spiral/004-in-out-phyllotaxic.c => 02-spiral-dual/003-dual-phyllotaxic.c (84%) create mode 100644 02-spiral-dual/out/003-dual-phyllotaxic-2.svg rename {02-mountain => 03-spiral-origami-mountain}/001-origami-mountain.c (100%) rename {02-mountain => 03-spiral-origami-mountain}/002-origami-mountain.c (100%) rename {02-mountain => 03-spiral-origami-mountain}/003-origami-mountain.c (100%) rename {02-mountain => 03-spiral-origami-mountain}/004-origami-mountain.c (100%) rename {02-mountain => 03-spiral-origami-mountain}/005-origami-mountain.c (100%) rename {02-mountain => 03-spiral-origami-mountain}/006-origami-mountain.c (100%) rename {02-mountain => 03-spiral-origami-mountain}/007-continuous.c (100%) rename {02-mountain => 03-spiral-origami-mountain}/008-origami-mountain.c (100%) rename {03-lang-wave-curve => 04-lang-wave-curve}/lang-wave-curve-1-amplitude.c (100%) rename {03-lang-wave-curve => 04-lang-wave-curve}/lang-wave-curve-2-uneven.c (100%) rename {03-lang-wave-curve => 04-lang-wave-curve}/lang-wave-curve-3-balanced.c (100%) rename {03-lang-wave-curve => 04-lang-wave-curve}/lang-wave-curve-4-tilt.c (100%) rename {03-lang-wave-curve => 04-lang-wave-curve}/lang-wave-curve-5-grow.c (100%) rename {03-lang-wave-curve => 04-lang-wave-curve}/outer-wave-circle.c (100%) rename {04-sinewaves => 05-sinewaves}/000-base.c (100%) rename {04-sinewaves => 05-sinewaves}/001-study-dihedral-angle.c (100%) create mode 100644 05-sinewaves/002-wrapping-sines.c rename {05-stars => 06-stars}/stars.c (100%) rename {05-stars => 06-stars}/starsData.c (100%) diff --git a/01-archimedean-spiral/000-base.c b/01-spiral-archimedean/000-base.c similarity index 90% rename from 01-archimedean-spiral/000-base.c rename to 01-spiral-archimedean/000-base.c index 51ee4f8..267bcdf 100644 --- a/01-archimedean-spiral/000-base.c +++ b/01-spiral-archimedean/000-base.c @@ -15,8 +15,9 @@ int width = 800; int height = 800; // shape -int REVOLUTIONS = 50; -float SPACING = 7.0f; +int REVOLUTIONS = 24; +int START_RADIUS = 3; +float SPACING = 15.0f; int main(int argc, char **argv){ time_t t; @@ -35,7 +36,7 @@ int main(int argc, char **argv){ float x, y; for(int i = START_RADIUS; i < REVOLUTIONS; i++){ - float circleResolution = i * 10; // how many points in one full circle + float circleResolution = i * 20; // how many points in one full circle for(float a = 0; a < TWOPI; a += TWOPI/circleResolution){ float revolution = a/TWOPI; // 0-1, progress of one revolution diff --git a/01-archimedean-spiral/001-noise-mountain.c b/01-spiral-archimedean/001-noise-mountain.c similarity index 100% rename from 01-archimedean-spiral/001-noise-mountain.c rename to 01-spiral-archimedean/001-noise-mountain.c diff --git a/01-spiral-archimedean/002-polygons.c b/01-spiral-archimedean/002-polygons.c new file mode 100644 index 0000000..76f8f04 --- /dev/null +++ b/01-spiral-archimedean/002-polygons.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include + +#define TWOPI 6.28318530718 + +// output +char filename[128] = "002-polygons.svg\0"; +char path[128] = "out/\0"; + +// document +int width = 800; +int height = 800; + +// shape +int POLYGONS = 72; +int START_POLYGON = 3; +int radius = 360; + +int main(int argc, char **argv){ + time_t t; + srand((unsigned) time(&t)); + + strcat(path, filename); + FILE *file = fopen(path, "w"); + // HEADER + fprintf(file, "\n"); + fprintf(file, "\n", width, height); + // BODY + fprintf(file, "\n"); + fprintf(file, "\n"); // closing polyline + + fprintf(file, "\n"); + fprintf(file, ""); + fclose(file); + return 0; +} \ No newline at end of file diff --git a/01-spiral-archimedean/out/002-polygons.svg b/01-spiral-archimedean/out/002-polygons.svg new file mode 100644 index 0000000..5d15465 --- /dev/null +++ b/01-spiral-archimedean/out/002-polygons.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/01-archimedean-spiral/000-in-out.c b/02-spiral-dual/000-base.c similarity index 90% rename from 01-archimedean-spiral/000-in-out.c rename to 02-spiral-dual/000-base.c index 5840ec1..8084b80 100644 --- a/01-archimedean-spiral/000-in-out.c +++ b/02-spiral-dual/000-base.c @@ -7,7 +7,7 @@ #define TWOPI 6.28318530718 // output -char filename[128] = "000-in-out.svg\0"; +char filename[128] = "000-base.svg\0"; char path[128] = "out/\0"; // document @@ -18,6 +18,7 @@ int height = 800; int REVOLUTIONS = 4; float SPACING = 40.0f; float ROTATE_2ND = .5;//.3; // angle of the second spiral against the first (percent of 2pi) +float circleResolution = 5 * 60; int main(int argc, char **argv){ time_t t; @@ -34,11 +35,9 @@ int main(int argc, char **argv){ fprintf(file, "\n"); fprintf(file, "= 0; i--){ - for(float a = TWOPI; a >= 0 ; a -= TWOPI/divider){ + for(float a = TWOPI; a >= 0 ; a -= TWOPI/circleResolution){ float radius = 2 * (i + a/TWOPI); float x = width*.5 + cos(a) * radius * SPACING; float y = height*.5 + sin(a) * radius * SPACING; @@ -52,7 +51,7 @@ int main(int argc, char **argv){ // spiral out from the center for(int i = 0; i < REVOLUTIONS; i++){ - for(float a = 0; a <= TWOPI; a += TWOPI/divider){ + for(float a = 0; a <= TWOPI; a += TWOPI/circleResolution){ float radius = 2 * (i + a/TWOPI); float x = width*.5 + cos(a-TWOPI*ROTATE_2ND) * radius * SPACING; float y = height*.5 + sin(a-TWOPI*ROTATE_2ND) * radius * SPACING; diff --git a/01-archimedean-spiral/002-in-out-sine-wave.c b/02-spiral-dual/001-dual-sine-wave.c similarity index 97% rename from 01-archimedean-spiral/002-in-out-sine-wave.c rename to 02-spiral-dual/001-dual-sine-wave.c index e131543..3bb6bdf 100644 --- a/01-archimedean-spiral/002-in-out-sine-wave.c +++ b/02-spiral-dual/001-dual-sine-wave.c @@ -7,7 +7,7 @@ #define TWOPI 6.28318530718 // output -char filename[128] = "002-in-out-sine-wave.svg\0"; +char filename[128] = "001-dual-sine-wave.svg\0"; char path[128] = "out/\0"; // document @@ -42,10 +42,8 @@ int main(int argc, char **argv){ // spiral in toward the center for(int i = REVOLUTIONS-1; i >= 0; i--){ for(float a = TWOPI; a >= 0; a -= TWOPI/divider){ - float revolution = a/TWOPI; float radius = 2*(i+revolution) + sin(a*wobbleFreq) * wobbleMag * 2*(i+revolution); - float x = width*.5 + cos(a) * radius * SPACING; float y = height*.5 + sin(a) * radius * SPACING; fprintf(file, "%.2f,%.2f ", x, y); @@ -59,10 +57,8 @@ int main(int argc, char **argv){ // spiral out from the center for(int i = 0; i < REVOLUTIONS; i++){ for(float a = 0; a <= TWOPI; a += TWOPI/divider){ - float revolution = a/TWOPI; float radius = 2*(i+revolution) + sin(a*wobbleFreq) * wobbleMag * 2*(i+revolution); - float x = width*.5 + cos(a-TWOPI*ROTATE_2ND) * radius * SPACING; float y = height*.5 + sin(a-TWOPI*ROTATE_2ND) * radius * SPACING; fprintf(file, "%.2f,%.2f ", x, y); diff --git a/01-archimedean-spiral/003-in-out-logarithmic.c b/02-spiral-dual/002-dual-logarithmic.c similarity index 86% rename from 01-archimedean-spiral/003-in-out-logarithmic.c rename to 02-spiral-dual/002-dual-logarithmic.c index 809db04..d0ee125 100644 --- a/01-archimedean-spiral/003-in-out-logarithmic.c +++ b/02-spiral-dual/002-dual-logarithmic.c @@ -9,13 +9,17 @@ #define TWOPI 6.28318530718 // output -char filename[128] = "003-logarithmic.svg\0"; +char filename[128] = "002-dual-logarithmic.svg\0"; char path[128] = "out/\0"; // document int width = 800; int height = 800; +float SCALE = 6; +float REVOLUTIONS = 4;//15.0;//18.0; +float circleResolution = 5 * 60; + int main(int argc, char **argv){ time_t t; srand((unsigned) time(&t)); @@ -31,17 +35,10 @@ int main(int argc, char **argv){ fprintf(file, "\n"); fprintf(file, "= 0; i--){ - for(float a = TWOPI; a >= 0; a -= TWOPI/divider){ - + for(float a = TWOPI; a >= 0; a -= TWOPI/circleResolution){ float radius = SCALE * powf(i+a/TWOPI, 3); - float x = width*.5 + cos(a) * radius; float y = height*.5 + sin(a) * radius; fprintf(file, "%.2f,%.2f ", x, y); @@ -54,10 +51,8 @@ int main(int argc, char **argv){ // spiral out from the center for(int i = 0; i < REVOLUTIONS; i++){ - for(float a = 0; a <= TWOPI; a += TWOPI/divider){ - + for(float a = 0; a <= TWOPI; a += TWOPI/circleResolution){ float radius = SCALE * powf(i+a/TWOPI, 3); - float x = width*.5 + cos(a-TWOPI*.5) * radius; float y = height*.5 + sin(a-TWOPI*.5) * radius; fprintf(file, "%.2f,%.2f ", x, y); diff --git a/01-archimedean-spiral/004-in-out-phyllotaxic-join.c b/02-spiral-dual/003-dual-phyllotaxic-2.c similarity index 86% rename from 01-archimedean-spiral/004-in-out-phyllotaxic-join.c rename to 02-spiral-dual/003-dual-phyllotaxic-2.c index 6dd5aa3..3f5c707 100644 --- a/01-archimedean-spiral/004-in-out-phyllotaxic-join.c +++ b/02-spiral-dual/003-dual-phyllotaxic-2.c @@ -9,7 +9,7 @@ #define TWOPI 6.28318530718 // output -char filename[128] = "004-phyllotaxic-join.svg\0"; +char filename[128] = "003-dual-phyllotaxic-2.svg\0"; char path[128] = "out/\0"; // document @@ -19,6 +19,11 @@ int height = 800; // shape int REVOLUTIONS = 8; float SPACING = 7.0f; +float wobbleFreq = 13.0; +float wobbleMag = 1; +// wobbleFreq = 7.0; +// wobbleMag = 0.33; +float circleResolution = 10 * 60; int main(int argc, char **argv){ time_t t; @@ -36,14 +41,8 @@ int main(int argc, char **argv){ fprintf(file, "\n"); fprintf(file, "= 0; i--){ - for(float a = TWOPI; a >= 0; a -= TWOPI/divider){ + for(float a = TWOPI; a >= 0; a -= TWOPI/circleResolution){ float revolution = 2*(i+a/TWOPI); float SCALE = 1.5 * revolution; float x = width*.5 + cos(a) * SCALE * (revolution + sin(a*wobbleFreq)*wobbleMag ); @@ -57,7 +56,7 @@ int main(int argc, char **argv){ // fprintf(file, "\n"); fprintf(file, "= 0; i--){ - for(float a = TWOPI; a >= 0; a -= TWOPI/divider){ + for(float a = TWOPI; a >= 0; a -= TWOPI/circleResolution){ 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); @@ -59,7 +58,7 @@ int main(int argc, char **argv){ // fprintf(file, " + + + + + \ No newline at end of file diff --git a/02-mountain/001-origami-mountain.c b/03-spiral-origami-mountain/001-origami-mountain.c similarity index 100% rename from 02-mountain/001-origami-mountain.c rename to 03-spiral-origami-mountain/001-origami-mountain.c diff --git a/02-mountain/002-origami-mountain.c b/03-spiral-origami-mountain/002-origami-mountain.c similarity index 100% rename from 02-mountain/002-origami-mountain.c rename to 03-spiral-origami-mountain/002-origami-mountain.c diff --git a/02-mountain/003-origami-mountain.c b/03-spiral-origami-mountain/003-origami-mountain.c similarity index 100% rename from 02-mountain/003-origami-mountain.c rename to 03-spiral-origami-mountain/003-origami-mountain.c diff --git a/02-mountain/004-origami-mountain.c b/03-spiral-origami-mountain/004-origami-mountain.c similarity index 100% rename from 02-mountain/004-origami-mountain.c rename to 03-spiral-origami-mountain/004-origami-mountain.c diff --git a/02-mountain/005-origami-mountain.c b/03-spiral-origami-mountain/005-origami-mountain.c similarity index 100% rename from 02-mountain/005-origami-mountain.c rename to 03-spiral-origami-mountain/005-origami-mountain.c diff --git a/02-mountain/006-origami-mountain.c b/03-spiral-origami-mountain/006-origami-mountain.c similarity index 100% rename from 02-mountain/006-origami-mountain.c rename to 03-spiral-origami-mountain/006-origami-mountain.c diff --git a/02-mountain/007-continuous.c b/03-spiral-origami-mountain/007-continuous.c similarity index 100% rename from 02-mountain/007-continuous.c rename to 03-spiral-origami-mountain/007-continuous.c diff --git a/02-mountain/008-origami-mountain.c b/03-spiral-origami-mountain/008-origami-mountain.c similarity index 100% rename from 02-mountain/008-origami-mountain.c rename to 03-spiral-origami-mountain/008-origami-mountain.c diff --git a/03-lang-wave-curve/lang-wave-curve-1-amplitude.c b/04-lang-wave-curve/lang-wave-curve-1-amplitude.c similarity index 100% rename from 03-lang-wave-curve/lang-wave-curve-1-amplitude.c rename to 04-lang-wave-curve/lang-wave-curve-1-amplitude.c diff --git a/03-lang-wave-curve/lang-wave-curve-2-uneven.c b/04-lang-wave-curve/lang-wave-curve-2-uneven.c similarity index 100% rename from 03-lang-wave-curve/lang-wave-curve-2-uneven.c rename to 04-lang-wave-curve/lang-wave-curve-2-uneven.c diff --git a/03-lang-wave-curve/lang-wave-curve-3-balanced.c b/04-lang-wave-curve/lang-wave-curve-3-balanced.c similarity index 100% rename from 03-lang-wave-curve/lang-wave-curve-3-balanced.c rename to 04-lang-wave-curve/lang-wave-curve-3-balanced.c diff --git a/03-lang-wave-curve/lang-wave-curve-4-tilt.c b/04-lang-wave-curve/lang-wave-curve-4-tilt.c similarity index 100% rename from 03-lang-wave-curve/lang-wave-curve-4-tilt.c rename to 04-lang-wave-curve/lang-wave-curve-4-tilt.c diff --git a/03-lang-wave-curve/lang-wave-curve-5-grow.c b/04-lang-wave-curve/lang-wave-curve-5-grow.c similarity index 100% rename from 03-lang-wave-curve/lang-wave-curve-5-grow.c rename to 04-lang-wave-curve/lang-wave-curve-5-grow.c diff --git a/03-lang-wave-curve/outer-wave-circle.c b/04-lang-wave-curve/outer-wave-circle.c similarity index 100% rename from 03-lang-wave-curve/outer-wave-circle.c rename to 04-lang-wave-curve/outer-wave-circle.c diff --git a/04-sinewaves/000-base.c b/05-sinewaves/000-base.c similarity index 100% rename from 04-sinewaves/000-base.c rename to 05-sinewaves/000-base.c diff --git a/04-sinewaves/001-study-dihedral-angle.c b/05-sinewaves/001-study-dihedral-angle.c similarity index 100% rename from 04-sinewaves/001-study-dihedral-angle.c rename to 05-sinewaves/001-study-dihedral-angle.c diff --git a/05-sinewaves/002-wrapping-sines.c b/05-sinewaves/002-wrapping-sines.c new file mode 100644 index 0000000..eeda89b --- /dev/null +++ b/05-sinewaves/002-wrapping-sines.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include + +#define TWOPI 6.28318530718 + +// output +char filename[128] = "002-wrapping-sines.svg\0"; +char path[128] = "out/\0"; +// path[0] = '\0'; + +// document +int width = 1200; +int height = 900; + +// groups +float NUM_GROUPS = 6; +float GROUP_SPACING = 200.0; +float GROUP_NUM_VERTICALS = 4.0; + +// sine curve +float FREQUENCY = .028; +float AMPLITUDE = 10; + + +int mod2PosNeg(int iterator){ + if(iterator%2 == 0){ return -1; } + return 1; +} + +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"); + fprintf(file, "\n"); + fprintf(file, "\n\n"); + + for(int i = 0; i < NUM_GROUPS; i++){ + float xGroup = GROUP_SPACING * i; // the major X axis of each group + + // 4 sine waves in every group + for(int j = 0; j < GROUP_NUM_VERTICALS; j++){ + // pattern: L L R R L L ... + int direction = mod2PosNeg(j*.5); // -1 or +1 + + // spacing + float percentOfGroup = (j / GROUP_NUM_VERTICALS); + if(j == 0) percentOfGroup = .175; + if(j == 1) percentOfGroup = .3; + if(j == 2) percentOfGroup = .625; + if(j == 3) percentOfGroup = .75; + float xInternalSpacing = percentOfGroup * GROUP_SPACING; + + // affine scale + float affine = 1.0; // multiply to all + if(j == 0 || j == GROUP_NUM_VERTICALS-1){ // multiply to outer curves + // affine = 1.0 + 1.0 * (i/(NUM_GROUPS-1)); + affine = 1.75; + } + + fprintf(file, "\n"); // closing quote + } + } + + fprintf(file, "\n"); + fprintf(file, ""); + fclose(file); + return 0; +} \ No newline at end of file diff --git a/05-stars/stars.c b/06-stars/stars.c similarity index 100% rename from 05-stars/stars.c rename to 06-stars/stars.c diff --git a/05-stars/starsData.c b/06-stars/starsData.c similarity index 100% rename from 05-stars/starsData.c rename to 06-stars/starsData.c diff --git a/readme.md b/readme.md index c79d08a..8baa681 100644 --- a/readme.md +++ b/readme.md @@ -2,9 +2,13 @@ generate polyline coordinates directly into an SVG, using __stdio.h__ `FILE` -# draw the line like a pen would - * begin polyline `fprintf(file, "