/* square tiling copyright 2007 Elizabeth D Zwicky zwicky@otoh.org http://www.otoh.org */ float lineLength; float midPoint; int saveNum; void setup () { colorMode(HSB, 100); size (800,600); background(0); frameRate(8); loop(); } void draw () { float thisLayer; if ((layerNum < 0) ) { fill(random(0,100), random(0,100), random(0,100)); noStroke(); rect(0,0,width, height); noFill(); layerNum = 0; initVars(); } if (layerNum <= numLayers) { thisLayer = layerNum/numLayers; translate(-lineLength, -lineLength); drawIt(thisLayer); layerNum++; } if(layerNum > numLayers) { initGoals(); layerNum = 0; } } float numLayers; float layerNum = -1; float curveAX, curveAY, curveBX, curveBY; float goalAX, goalAY, goalBX, goalBY; float startGoalX, startGoalY, endGoalX, endGoalY; boolean flipAlter, doDouble, doTest; float hueStart, hueGoal, satStart, satGoal, brightStart, brightGoal; float strokeWeightStart, strokeWeightGoal; float setAlpha, hueCycle, brightCycle, satCycle; float [] goals = new float [13]; void initVars () { doTest = false; flipAlter = (random(0,3) < 2); //flipAlter = true; if (! flipAlter) { doDouble = (random(0,2) < 1); } else { doDouble = false; } // doDouble = false; lineLength = random(width/6, height/2); if ( doDouble) { numLayers = round(random(lineLength/30, lineLength/10)); } else { numLayers = round(random(lineLength/20,lineLength/4)); } // numLayers = 10; midPoint = lineLength/2; hueStart = random(0,100); hueStart = random(0,100); hueGoal = random (0,100); if (random(0,3) < 1) { hueCycle = PI; } else if (random(0,2) < 1){ hueCycle = HALF_PI; } else { hueCycle = TWO_PI; } if (random(0,2) < 1) { brightCycle = PI; } else { brightCycle = HALF_PI; } if (random(0,2) < 1) { satCycle = PI; } else{ satCycle = HALF_PI; } curveAX = random(-lineLength, lineLength); curveAY = random(-lineLength, lineLength); curveBX = random(-lineLength, lineLength); curveBY = random(-lineLength, lineLength); goals[0] = 0; goals[1] = lineLength; goals [2] = midPoint; goals [3] = -lineLength; goals[4] = -midPoint; goals[5] = curveAX; goals[6] = curveAY; goals[7] = -curveBX; goals[8] = -curveBY; goals[9] = -curveAX; goals[10] = -curveAY; goals[11] = curveBX; goals[12] = curveBY; // setAlpha = random(100/strokeWeightGoal, 100-strokeWeightStart); initGoals(); } void initGoals () { float setMode = random(0,3); if (setMode < 1) { brightStart = 100; brightGoal = 100; } else if (setMode < 2){ brightStart = 0; brightGoal = 100; } else { brightStart =100; brightGoal = 0; } setMode = random(0,3); if (setMode < 1) { satStart = 100; satGoal = 100; } else if (setMode < 2){ satStart = 0; satGoal = 100; } else { satStart =100; satGoal = 0; } goalAX = goals[round(random(0,(goals.length-1)))]; goalAY = goals[round(random(0,(goals.length-1)))]; goalBX = goals[round(random(0,(goals.length-1)))]; goalBY = goals[round(random(0,(goals.length-1)))]; startGoalX = goals[floor(random(1,9))]; startGoalY = goals[floor(random(1,9))]; if (random(0,2) <1) { endGoalX = lineLength - startGoalY; if (flipAlter) { endGoalY = -startGoalX; } else { endGoalY = startGoalX; } } else { endGoalX = lineLength + startGoalY; if (flipAlter) { endGoalY = startGoalX; } else { endGoalY = -startGoalX; } } if (random(0,2) < 1) { strokeWeightStart = random(0,lineLength/10); if (strokeWeightStart < lineLength/20 && random(0,3) < 2) { strokeWeightGoal = lineLength/10; } else if (strokeWeightStart > lineLength/20 && random(0,3) < 2) { strokeWeightGoal = 1; } else { strokeWeightGoal = strokeWeightStart; } } else { strokeWeightGoal = 0; strokeWeightStart = 0; } } void drawIt (float thisLayer){ noFill(); int xTimes = ceil(width/lineLength)+ 2; //xTimes = 2; int yTimes = ceil(height/lineLength)+ 2; //yTimes = 2; float strokeWeightSet; // for (float k = 0; k <= numLayers; k++){ for (int i = 0; i < xTimes; i++) { for (int j = 0; j < yTimes; j++) { // thisLayer = k/numLayers; */ strokeWeightSet = strokeWeightStart + ((strokeWeightGoal - strokeWeightStart) * sin(thisLayer * PI)); strokeWeight(strokeWeightSet); if (strokeWeightSet == 0){ setAlpha = 100; } else { setAlpha = (90/strokeWeightSet) + 10; } stroke((hueStart + ((hueGoal - hueStart) * (sin(thisLayer*hueCycle))))%100, satStart + ((satGoal - satStart) * (sin(thisLayer*satCycle))), brightStart + ((brightGoal - brightStart) * (sin(thisLayer*brightCycle))), setAlpha); if ((i%2 != j%2) && flipAlter){ drawSquare(lineLength, thisLayer, true); } else { drawSquare(lineLength, thisLayer, false); } translate(0, lineLength); } translate(lineLength,-(yTimes * lineLength)); } translate (-(xTimes * lineLength), 0); // } } void drawSquare (float lineLength, float thisLayer, boolean flip) { if (flip) { translate(midPoint,0); scale(-1,1); translate(-midPoint,0); } for (int i = 0; i < 4; i++){ drawLine(thisLayer); if (doDouble){ translate (midPoint, 0); scale (-1,1); translate(-midPoint,0); drawLine(thisLayer); translate (midPoint,0); scale (-1,1); translate(-midPoint,0); } translate(lineLength, 0); rotate(HALF_PI); } if (flip) { translate(midPoint,0); scale(-1,1); translate(-midPoint,0); } } void drawLine (float thisLayer){ if (doTest) { line(0 + (startGoalX * thisLayer), 0 + (startGoalY * thisLayer), lineLength + ((endGoalX - lineLength) * thisLayer), 0 + (endGoalY * thisLayer)); } else{ bezier(0 + (startGoalX * thisLayer), 0 + (startGoalY * thisLayer), curveAX + ((goalAX-curveAX) * thisLayer), curveAY + ((goalAY-curveAY) * thisLayer), curveBX + ((goalBX-curveBX) * thisLayer), curveBY + ((goalBY-curveBY) * thisLayer), lineLength + ((endGoalX - lineLength) * thisLayer), 0 + (endGoalY * thisLayer)); } } void mousePressed () { layerNum = -1; } void keyPressed () { saveNum++; String fileName = "squaretile"; fileName = fileName.concat(str(saveNum)); fileName = fileName.concat(".jpg"); save (fileName); }