You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not quite sure if this is me using the tool in the wrong way — I am just working my way through https://generativeartistry.com and it seems that when I save, the artwork gets redrawn on top of the previous canvas, then saves this double-exposure.
Is it something to do with the for loops included in the return?
My code is as follows:
constcanvasSketch=require("canvas-sketch");const{ lerp }=require("canvas-sketch-util/math");constrandom=require("canvas-sketch-util/random");constsettings={dimensions: [1000,1618]};constsketch=()=>{conststep=50;constlines=[];return({ context, width, height })=>{context.fillStyle="white";context.fillRect(0,0,width,height);context.lineWidth=10;// Create the linesfor(leti=step;i<=height-step;i+=step){constline=[];for(letj=step;j<=width-step;j+=step){constoffset=Math.random()*50;constpoint={x: j,y: i+offset};line.push(point);}lines.push(line);}console.log(lines);// Draw the linesfor(leti=0;i<lines.length;i++){console.log("why");context.beginPath();context.moveTo(lines[i][0].x,lines[i][0].y);console.log(lines[i].length);for(letj=0;j<lines[i].length;j++){context.lineTo(lines[i][j].x,lines[i][j].y);}context.stroke();}};};canvasSketch(sketch,settings);
The text was updated successfully, but these errors were encountered:
Hey @andrwrbnsn, hitting Cmd + S will trigger a re-render as some application props are changed during that keystroke.
It's best if your render function is a 'pure' function, i.e. each time you call it with the same inputs, it results in the same rendered output. This is a bit similar to React/Vue/etc. In your case, you will need to move Math.random() outside the render function.
One more note — right now your render function is adding to a lines array, so each time the canvas render, the lines array will grow again and again.
The best option is to move your logic outside of the rendering function (to where you have lines defined) so that the 'generative' structure is created only once, and then rendered multiple times.
I'm not quite sure if this is me using the tool in the wrong way — I am just working my way through https://generativeartistry.com and it seems that when I save, the artwork gets redrawn on top of the previous canvas, then saves this double-exposure.
Is it something to do with the for loops included in the return?
My code is as follows:
The text was updated successfully, but these errors were encountered: