Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using for-loop and variables in path command #110

Open
allonestring opened this issue Apr 25, 2021 · 1 comment
Open

using for-loop and variables in path command #110

allonestring opened this issue Apr 25, 2021 · 1 comment

Comments

@allonestring
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants