// Routines for drawing stars and asters - Jim Bumgardner void setup() { size(500, 250); smooth(); noLoop(); } // Only looks star-like if skipPoints is relatively prime with nbrPoints void drawStar(int nbrPoints, float cx, float cy, float odiam, int skipPoints ) { float orad = odiam / 2.0; pushMatrix(); translate(cx, cy); rotate(radians(-90)); // Point upwards float a = TWO_PI / nbrPoints; beginShape(); int n = 0; for (int i = 0; i < nbrPoints; ++i) { vertex( cos( a * n) * orad, sin( a * n) * orad); n += skipPoints; } endShape(CLOSE); popMatrix(); } void drawAster(int nbrPoints, float cx, float cy, float odiam, float idiamRatio) { float orad = odiam / 2; float irad = orad * idiamRatio; pushMatrix(); translate(cx, cy); rotate(radians(-90)); // Point upwards float a = TWO_PI / nbrPoints; beginShape(); for (int i = 0; i < nbrPoints; ++i) { vertex( cos( a * i) * orad, sin( a * i) * orad); vertex( cos( a * (i+.5)) * irad, sin( a * (i+.5)) * irad); } endShape(CLOSE); popMatrix(); } void draw() { background(0); // Dim randomized stars on background stroke(100); strokeWeight(.5); noFill(); for (int y = 0; y < height; y += 24) { for (int x = 0; x < width; x += 24) { if (random(2) < 1) { int nbrPoints = ((int)random(2,6))*2+1; int skipPoints = (int) (nbrPoints/2); drawStar(nbrPoints, x, y, 24, skipPoints); } else { int nbrPoints = (int)random(5,13); drawAster(nbrPoints, x, y, 24, random(.1,.6)); } } } stroke(#FFCC00); strokeWeight(2); noFill(); drawStar(5, width*1/5, height*1/4, height*.4, 2); drawAster(5, width*2/4, height*1/4, height*.4, .25); drawAster(5, width*4/5, height*1/4, height*.4, .55); noStroke(); fill(#FFCC00); drawStar(5, width*1/5, height*3/4, height*.4, 2); drawAster(5, width*2/4, height*3/4, height*.4, .25); drawAster(5, width*4/5, height*3/4, height*.4, .55); }