metafizzy / zdog

Flat, round, designer-friendly pseudo-3D engine for canvas & SVG
https://zzz.dog
10.39k stars 394 forks source link

using for-loop and variables in path command #110

Open allonestring opened 3 years ago

allonestring commented 3 years ago

In other languages, if I wanted to draw a star, say, I'd have something like this:

startShape();
for (i = 0;  i < numPoints; i++)
{
  angleR = TAU/numPoints * i;
  angler = TAU/numPoints * (i + 0.5);

  vertex(bigRadius * cos(angleR), bigRadius * sin(angleR));
  vertex(smallRadius * cos(angler), smallRadius * sin(angler));
}
endShape();

Can I do something similar in zdog? If so, I can't work out how, nor can I work out how to pass a variable to the path command.

var x1 = Math.random(-50, 50);
var y1 = Math.random(-50, 50);
var z1 = Math.random(-50, 50);
var x2 = Math.random(-50, 50);
var y2 = Math.random(-50, 50);
var z2 = Math.random(-50, 50);

new Zdog.Shape({
  ...
  path: [
    { x: x1, y: y1, z: z1 }, 
    { x: x2, y: y2, z: z2 }, 
  ],
  ...

Have I got the syntax wrong or am I hoping for too much? Thanks!

coder787 commented 3 years ago

I think you can have random paths, I've seen it in this demo.. study it to see how it's done..

https://codepen.io/jh3y/pen/JQJbaM