Last active
September 13, 2015 13:08
-
-
Save krish85/cceffeda180ada27c6d4 to your computer and use it in GitHub Desktop.
Star table using processing
This file contains hidden or 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
<script src="http://cdnjs.com/libraries/processing.js"></script> | |
<canvas data-processing-sources="star_table.pde polygon.pde"></canvas> |
This file contains hidden or 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
<script> | |
void star(int sideCount, float innerRadius, float outerRadius) { | |
float theta = 0.0; // point count is 1/2 of total vertex count | |
int vertCount = sideCount*2; //if its 3 side then 6 vertex for start with inner and outer radius | |
float thetaRot = TWO_PI/vertCount; | |
float tempRadius = 0.0; | |
float x = 0.0, y = 0.0; | |
println(thetaRot); | |
beginShape(); | |
for (int i=0; i<sideCount; i++) { | |
for (int j=0; j<2; j++) { | |
tempRadius = innerRadius; | |
// true if j is even | |
if (j%2==0) { | |
tempRadius = outerRadius; | |
} | |
x = cos(theta)*tempRadius; | |
y = sin(theta)*tempRadius; | |
vertex(x, y); | |
theta += thetaRot; | |
} | |
} | |
endShape(CLOSE); | |
} // end star | |
</script> |
This file contains hidden or 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
<script> | |
void setup(){ | |
size(800,800); | |
background(255); | |
//noStroke(); | |
int rows = 4; | |
int cols = 4; | |
float outerRadius = width/cols; | |
int pointCount; | |
int steps; | |
float innerRadiusFactor; | |
float innerRadius; | |
float outerRadiusRatio; | |
float innerRadiusRatio; | |
float shadeRatio; | |
float rotationRatio; | |
translate(outerRadius/2, outerRadius/2); | |
for(int i=0;i<rows;i++){ | |
for(int j=0;j<cols;j++){ | |
pointCount = int(random(5,15)); | |
steps = int(random(3,20)); | |
innerRadius = outerRadius*random(.3, .9); | |
outerRadiusRatio = outerRadius/steps; | |
innerRadiusRatio = innerRadius/steps; | |
float randCol = random(225, 255); | |
shadeRatio = randCol/steps; | |
rotationRatio = random(90, 200)/steps; | |
pushMatrix(); | |
translate(outerRadius*j, outerRadius*i); | |
for (int k=0; k<steps; k++) { | |
fill(shadeRatio*k); | |
stroke(randCol-shadeRatio*k, 100); | |
pushMatrix(); | |
scale(.4); | |
rotate(rotationRatio*k*PI/180); | |
star(pointCount, outerRadius-outerRadiusRatio*k, innerRadius-innerRadiusRatio*k); | |
popMatrix(); | |
} | |
popMatrix(); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment