We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi!
I am trying to switch to p5.js as much as I can, however I am fairly new at it.
The main problem I have is, when I do stuff with get() and double for loop, p5.js is incredibly slow.
When I run the following code with Processing (java mode) this runs pretty easy. When I do the same thing with p5.js, it is really really really slow.
var img;
function setup() {
createCanvas(480, 640);
img = loadImage("assets/Image2.jpg");
}
function draw() {
image(img, 0, 0);
var stepSize = 10;
for (var y = 0; y < width; y+=stepSize) {
for (var x = 0; x < height; x+=stepSize) {
var c = get(y, x);
fill(c);
noStroke();
rect(y, x, 5, 5);
}
}
}
So what is the problem here? What am I doing wrong with p5.js?? If I use the get() command outside of the for loops, it is fairly ok... If I change the stepSize from 10 to 1 then again, p5.js just freezes... Is this normal? Do I have to change something?
Answers
noStroke();
zillion times over? :-\"10
, you can make it a global constant at the top of your sketch:const STEP_SIZE = 10;
well, many of those mistakes are small things that I kept the same in both Processing and P5.js.
I understand the deal with get(). It is the same deal in both programs.
I was just wondering about all that performance issue because with get() method and setting up double for loops p5.js is significantly slower that processing. And mostly with get() it just crashes...
Is it a deal with javascript that makes everything so slower?
Does it make any difference in running the code with different browsers?
Thanks for the help :)
https://developer.Mozilla.org/en-US/docs/Web/API/HTMLCanvasElement
https://Processing.org/reference/color_datatype.html
http://p5js.org/reference/#/p5/pixelDensity
int
.