zenozeng / p5.js-svg

SVG runtime for p5.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

this code doesn't work.

robottini opened this issue · comments

Hi, this code doesn't work with p5.js-svg. The code works well without the SVG option.
`
let shapes = [];
let colors = ["#ed3441", "#ffd630", "#329fe3", "#154296", "#ffffff", "#303030"];
let bgCol ;
let nScl = 0.002;
let offset = 100;

function setup() {
createCanvas(1120, 800, SVG);
rectMode(CENTER);

bgCol = colors[2];
background(bgCol);
colors.splice(2, 1);

divideRect(offset, offset, width-(offset * 2), height-(offset * 2));
shuffle(shapes, true);
stroke(bgCol);
strokeWeight(3);
for(let s of shapes){
	push();
	translate(s.x, s.y);
	rotate((noise(s.x*nScl, s.y*nScl)-0.5)*1.25);
	fill(random(colors));
	rect(0, 0, s.w, s.h, 2);
	pop();
}
save();

}

function draw() {

}

function divideRect(x, y, w, h) {
let rnd = int(random(2));
let cc = 5;
let w1 = int(random(1, cc)) * (w / cc);
let w2 = w - w1;
let h1 = int(random(1, cc)) * (h / cc);
let h2 = h - h1;
let min = 35;
if (w > min && h > min) {
if (w >= h) {
let rndw = int(random(1, cc)) * (w / cc);
divideRect(x, y, rndw, h, min);
divideRect(x + rndw, y, w - rndw, h, min);
}
if (w < h) {
let rndh = int(random(1, cc)) * (h / cc);
divideRect(x, y, w, rndh, min);
divideRect(x, y + rndh, w, h - rndh, min);
}
}
else {
shapes.push({x:x+w/2, y:y+h/2, w:w-2, h:h-2});
}
}
`

61F21042-ADCB-49CF-B695-6A7D1F911F7F

@robottini Hi, push/pop issue was fixed in p5.js-svg@1.1.1. Would you like to try the latest version?

<script src="https://unpkg.com/p5.js-svg@1.1.1"></script>

Thanks, it works very well!!