int leftBounds = 20; int topBounds = 20; int x = leftBounds; int y = topBounds; int rightBounds = 380; int bottomBounds = 380; int baseMax = 20; int randomMax = 10; int maxLines = 200; int counter = 0; PImage myImage, myMask; void setup(){ size(400, 400); background(255); smooth(); myMask = loadImage("mask.png"); } void draw(){ if(counter < maxLines){ int maxDistance = baseMax * int(random(0, 1) * randomMax); int minDistance = 2; int direction = random(0, 1) < 0.5 ? -1 : 1; int xEnd = x + (direction * (minDistance + int( random(0, 1) * maxDistance)) ); direction = random(0, 1) < 0.5 ? -1 : 1; int yEnd = y + (direction * (minDistance + int( random(0, 1) * maxDistance)) ); if(xEnd < leftBounds) xEnd = leftBounds; if(xEnd > rightBounds) xEnd = rightBounds; if(yEnd < topBounds) yEnd = topBounds; if(yEnd > bottomBounds) yEnd = bottomBounds; stroke(#006699, 20); strokeWeight(maxDistance/20); line(x, y, xEnd, yEnd); x = xEnd; y = yEnd; image(myMask, 0, 0); counter++; } // if(counter == maxLines){ // save("img.png"); // background(255); // myImage = loadImage("img.png"); // myImage.mask(myMask); // image(myImage, 0, 0); // noLoop(); // } } void keyPressed(){ if(key == 'r'){ background(255); counter = 0; } if(key =='q'){ save("p41_Lines08.jpg"); exit(); } }