Hello!
To make my first steps in creating a photo filter I decided to write a script that will take every pixel of some photo and redraw it to the left of the original. This way I planned to see two identical photos.
Strangely enough, only some percent of the picture is drawn. It seems as if the compiler can only do a certain number of operations and then just quits.
Could you please explain where the problem lies.
(in the example below I draw ellipses instead of pixels, and the “cellSize” variable is the aproximation number. Thus if cellsize is 1 then EVERY pixel is taken. If cellSize is 10 every 10th pixel is taken. If I choose cellSize 20 - the whole picture gets drawn, but with cellSize 2 onle a segment is reproduced)
var pic ;
var y_offset = 100;
var x_offset = 100;
var pixel_colour;
var counter = 0;
var cellSize = 2;
var image_h = 200;
var image_w = 300;
function preload() {
pic = loadImage('pic1.jpg');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
image (pic, x_offset ,y_offset, image_w,image_h);
for (pic_y = y_offset; pic_y < y_offset + image_h; pic_y += cellSize) {
counter ++;
for (pic_x = x_offset; pic_x < x_offset + image_w; pic_x += cellSize) {
pixel_colour = get (pic_x,pic_y);
fill(pixel_colour[0],pixel_colour[1],pixel_colour[2]);
ellipse (pic_x+image_w + 50 ,pic_y,cellSize,cellSize);
}
}
println ("counter " + counter);
}
function draw() {
// ellipse(mouseX, mouseY, 20, 20);
}
Also the link to openProcessing.org
>> HERE <<