xxxxxxxxxx
51
// based on sketch https://www.youtube.com/watch?v=me04ZrTJqWA
let img;
let cnv;
function preload (){
img = loadImage('assets/test_image.jpg');
}
function setup() {
noLoop();
cnv = createCanvas(img.width, img.height);
let newCanvasX = (windowWidth - img.width)/2;
let newCanvasY = (windowHeight - img.height)/2;
cnv.position(newCanvasX, newCanvasY);
}
function draw() {
// loop to access the pixel info of the image
for(let col = 0; col < img.width; col+=2) {
for(let row = 0; row < img.height; row+=2){
let xPos = col;
let yPos = row;
let c = img.get(xPos,yPos);
// arcs n curves
push();
translate(xPos, yPos);
rotate(radians(random(360)));
noFill();
stroke(color(c));
strokeWeight(random(5));
point(xPos, yPos);
strokeWeight(random(3));
//curve(x1, y1, x2, y2, x3, y3, x4, y4);
curve(xPos, yPos, sin(xPos) * random(60), cos(xPos) * sin(xPos) * random(90), random(10), random(80), cos(yPos) * sin(yPos) * random(140), cos(xPos) * sin(xPos) * 50)
ellipse(col,row, 15, 15);
pop();
}
}
}
function keyPressed(){
if (key === 's'){
saveCanvas("portrait.jpg");
}
}