Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
196 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <time.h> | ||
#include <math.h> | ||
|
||
#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, "<?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 x, y; | ||
for(int i = START_POLYGON; i < POLYGONS+START_POLYGON; i++){ | ||
float circleResolution = TWOPI/i; // angle of increment inside each circle | ||
for(float a = 0; a < TWOPI; a += circleResolution){ | ||
|
||
float revolution = a/TWOPI; // 0-1, progress of one revolution | ||
|
||
x = width*.5 + sinf(a) * radius; | ||
y = height*.5 - cosf(a) * radius; | ||
fprintf(file, "%.2f,%.2f ", x, y); | ||
} | ||
} | ||
fprintf(file, "\"/>\n"); // closing polyline | ||
|
||
fprintf(file, "</g>\n"); | ||
fprintf(file, "</svg>"); | ||
fclose(file); | ||
return 0; | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <time.h> | ||
#include <math.h> | ||
|
||
#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, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); | ||
fprintf(file, "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" "); | ||
fprintf(file, "x=\"0px\" y=\"0px\" width=\"%dpx\" height=\"%d", width, height); | ||
fprintf(file, "px\" viewBox=\"0 0 %d %d", width, height); | ||
fprintf(file, "\" xml:space=\"preserve\">\n<g>\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, "<polyline fill=\"none\" stroke=\"#000000\" points=\""); // hanging open quote | ||
for(float h = 0; h < height; h++){ | ||
|
||
float sine = sinf(h*FREQUENCY) * AMPLITUDE; | ||
float x = xGroup + xInternalSpacing + sine * direction * affine; | ||
float y = h; | ||
|
||
fprintf(file, "%.2f,%.2f ", x, y); | ||
} | ||
fprintf(file, "\"/>\n"); // closing quote | ||
} | ||
} | ||
|
||
fprintf(file, "</g>\n"); | ||
fprintf(file, "</svg>"); | ||
fclose(file); | ||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.