/** * Draw some Parametric Paisley. woohoo. :) */ boolean needsRendered = false; boolean startingup = true; float S_STEP = 0.01; // step size (from 0.0 to 1.0) int SEED = 0; // COLOR Information color[] clrLines = { color(0,0,0,100), color(0,0,0,100)}; float[] wgtLines = { 1.0, 1.0}; color[] clrCurles = { color(0,0,0,50), color(22139,176,111,80), // light green color(103,158,147,80), // light blue color(115,122,147,80), // medium blue }; float[] wgtCurles = { 0.0, 1.0, 1.0, 1.0}; color[] clrCrinkles = { color(139,176,111,10), // light green color(103,158,147,10), // light blue color(103,176,74,10), // darker green color(40,67,178,10), // light blue color(177,176,50,10), // medium yellow color(187,151,93,10), // light orange color(187,102,103,10), // medium pink color(148,93,147,10), // medium purple color(115,122,147,10), // medium blue }; float[] wgtCrinkles = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; void setup() { size(300, 300); background(0,0,0); frameRate(5); } void draw(){ if(startingup){ background(0,0,0); fill(0,0,0); rect(0,0,width,height); pushMatrix(); resetMatrix(); // move to intuitive coordinate system translate(width/2,height*(1.0/4.0)); PFont font; font = loadFont("FFScala-16.vlw"); textFont(font, 16); fill(255, 255, 255); text("Click to create some\n Crazzzy Paisley! :P",-115,50); popMatrix(); delay(30); } if(needsRendered){ render(); needsRendered = false; } } void mousePressed(){ SEED = int(random(mouseX*1000+mouseY)); // generate a new SEED if(startingup){ background(0,0,0); delay(30); } pushMatrix(); resetMatrix(); // move to intuitive coordinate system translate(width/2,height*(3.0/4.0)); PFont font; font = loadFont("FFScala-16.vlw"); textFont(font, 16); fill(255, 255, 255); text("Making new pattern...",-90,70); repaint(); delay(1000); popMatrix(); startingup = false; needsRendered = true; } void render() { background(0,0,0); // move to intuitive coordinate system //translate(width/2,height*(3.0/4.0)); rotate(PI); delay(50); println("SEED=" + SEED); randomSeed(SEED); stroke(128,128,255); strokeWeight(2); /* line(-width/2,0,width/2,0); line(-width/2,300,width/2,300); line(-width/2,-300,width/2,-300); line(0,-height/4,0,height*0.75); line(300,-height/4,300,height*0.75); line(-300,-height/4,-300,height*0.75); */ translate(-275,-300); drawPaisleyTile(); /* translate(-300,0); drawPaisleyTile(); translate(0,300); drawPaisleyTile(); translate(300,0); drawPaisleyTile(); translate(300,0); drawPaisleyTile(); translate(0,-300); drawPaisleyTile(); */ } void drawPaisleyTile(){ pushMatrix(); // start in home coordintates translate(125,75); drawPaisleySet(0.70, true); translate(20,180); rotate(PI); drawPaisleySet(0.25, true); /* rotate(PI); // home coordintates translate(-150, 0); rotate(PI/3); drawPaisleySet(0.32, false); rotate(-PI/3); // home coordintates translate(-50, 0); rotate(-PI/1.5); drawPaisleySet(0.8, true); rotate(PI/1.5); // home coordintates translate(100,-175); rotate(-PI/2.7); drawPaisleySet(0.5, false); rotate(PI/2.7); // home coordintates translate(200,-85); rotate(PI-PI/8); drawPaisleySet(0.55, false); */ popMatrix(); } void drawPaisleySet(float p_scale, boolean clockwise){ pushMatrix(); scale(p_scale); drawPaisley(random(0.94,1.00), 3.0, true, 0.10, clockwise); drawPaisley(random(0.70,0.85), 4.0, false, 0.25, clockwise); drawPaisley(random(0.45,0.58), 4.0, false, 0.25, clockwise); drawPaisley(random(0.32,0.36), 4.0, false, 0.25, clockwise); S_STEP = S_STEP*3; drawPaisley(random(0.22,0.27), 4.0, false, 0.15, clockwise); drawPaisley(random(0.12,0.18), 4.0, false, 0.15, clockwise); drawPaisley(random(0.04,0.09), 4.0, false, 0.15, clockwise); S_STEP = S_STEP / 3; popMatrix(); repaint(); delay(50); } void drawPaisley(float p_scale, float p_weight, boolean allowCurls, float crinkle, boolean clockwise){ float s = 0.0; float[] lastPoint = getPaisleyPoint(s, p_scale, clockwise); float[] nextPoint; color p_color = getRandColor(clrLines, wgtLines); color c_color = getRandColor(clrCrinkles, wgtCrinkles); color s_color = getRandColor(clrCurles, wgtCurles); for(s = S_STEP; s <= 1.0; s += S_STEP){ nextPoint = getPaisleyPoint(s, p_scale, clockwise); stroke(p_color); strokeWeight(p_weight); line(lastPoint[0], lastPoint[1], nextPoint[0], nextPoint[1]); //stroke(200,0,0); //NORMAL: line(lastPoint[0], lastPoint[1], (nextPoint[1]-lastPoint[1])+lastPoint[0], -(nextPoint[0]-lastPoint[0])+lastPoint[1]); if(allowCurls && random(100) > 90.0 && ((s > 0.65 && s < 0.9) || (s > 0.2 && s < 0.4))){ pushMatrix(); strokeWeight(p_weight*2); translate(lastPoint[0], lastPoint[1]); rotate(getAngle(-lastPoint[1], lastPoint[0], -nextPoint[1], nextPoint[0])); float seg_length = dist(-lastPoint[1], lastPoint[0], -nextPoint[1], nextPoint[0]); drawSpiral(random(5.0,30)*seg_length, random(0.25,0.4), s_color); popMatrix(); } if(crinkle > 0.0){ pushMatrix(); strokeWeight(p_weight*2); translate(lastPoint[0], lastPoint[1]); rotate(getAngle(-lastPoint[1], lastPoint[0], -nextPoint[1], nextPoint[0])); float seg_length = dist(-lastPoint[1], lastPoint[0], -nextPoint[1], nextPoint[0]); drawCrinkle(4*seg_length, crinkle, c_color); popMatrix(); } lastPoint = nextPoint; } } float[] getPaisleyPoint(float s, float p_scale, boolean clockwise){ float[] xy = {0.0, 0.0}; float twoPIs = 2*PI*s; //xy[0] = 100*cos(twoPIs); //xy[1] = 50*sin(twoPIs) - 50*cos(twoPIs + 0.75*(cos(twoPIs)-0.7)); xy[0] = (1-(1-p_scale)*(1-p_scale))*100*cos(twoPIs)+100; xy[1] = p_scale*50*sin(twoPIs); // swirl points float point_dist = dist(0,0,xy[0],xy[1]); // float rotation = (PI/80000.0)*point_dist*point_dist; // for standard paisley float sub = max(0,point_dist-55); float rotation = (PI/10000.0)*point_dist*point_dist - sub*sub/(145.0*145.0)*PI*3.5; // crazy paisley if(clockwise){ float[] r_xy = {cos(rotation)*xy[0] - sin(rotation)*xy[1], sin(rotation)*xy[0] + cos(rotation)*xy[1]}; return r_xy; } float[] r_xy = {cos(-rotation)*xy[0] - sin(-rotation)*xy[1], sin(-rotation)*xy[0] + cos(-rotation)*xy[1]}; return r_xy; } void drawSpiral(float s_length, float s_rotation, color s_color){ pushMatrix(); stroke(s_color); float s = 0.0; for(s = S_STEP; s <= 1.0; s += S_STEP){ line(0,0,0,0.01*s_length); translate(0,0.01*s_length); rotate(s_rotation*s*(S_STEP/0.01)); } popMatrix(); } void drawCrinkle(float s_length, float crinkle, color c_color){ pushMatrix(); stroke(c_color); float s = 0.0; float rotation = 0.0; float c_min = random(-crinkle, 0); float c_max = random(0, crinkle); for(s = S_STEP; s <= 1.0; s += 2*S_STEP){ rotation = random(c_min, c_max); line(0,0,0,0.01*s_length); translate(0,0.01*s_length); rotate(rotation*s*(S_STEP/0.01)); } popMatrix(); } float getAngle(float x1, float y1, float x2, float y2){ float x_dif = x2-x1; float y_dif = y2-y1; if(x_dif == 0.0){ if(y_dif > 0.0) return PI/2.0; if(y_dif < 0.0) return -PI/2.0; return 0.0; } if(y_dif == 0.0){ if(x_dif < 0.0) return -PI; return 0.0; } if(x_dif > 0.0){ return atan(y_dif / x_dif); } return atan(y_dif / x_dif) + PI; } void setStrokeLines(){ stroke(getRandColor(clrLines, wgtLines)); } void setStrokeCurles(){ stroke(getRandColor(clrCurles, wgtCurles)); } void setStrokeCrinkles(){ stroke(getRandColor(clrCrinkles, wgtCrinkles)); } /** * Take in an array of weights and color array to pick one at random * clrAry color array * weights array of weights */ color getRandColor(color[] clrAry, float[] weights){ int i = 0; float sum = 0; // find sum of weights given for(i=0; i