Assistance fixing my hypotrochoid illustration #4
-
I'm trying to get this code to work (basically copied from here: https://en.wikipedia.org/wiki/Hypotrochoid)
(this is modeled off the loop example more or less) I'm very new to macros and have no idea if this is correct, but hey, it compiles! But, now I get this in the error console and am not sure how to continue. I assume this means I am not returning the correct thing (
Thanks so much for your book, I'm excited to play more with toodle and janet! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
I was trying to recall if I was using macros just be fancy, or if there was a reason, and now I remember why. I needed to use a macro, because the formula for X and Y differ by swapping cos/sin functions. So, I just changed the code to be like this:
That still results in the same thing, but I thought the shape of the value I am returning looks better (two numbers, rather than one). But, same error. |
Beta Was this translation helpful? Give feedback.
-
Except that |
Beta Was this translation helpful? Give feedback.
-
Well, converting to a
Not I get |
Beta Was this translation helpful? Give feedback.
-
Hey! Happy to help. So there's not actually a reason to make this a macro -- you can pass functions as arguments to other functions and call them just fine. That'll simplify things a bit.
I renamed That gives the same error as before, but I think it's easier to spot the mistake: you have extra parentheses around the expression Taking these off gives you something that runs, but probably doesn't do what you want:
It just draws a line. This is because you have two arguments
That actually draws something! But it's very small. Let's multiply everything by
Okay, not exactly right yet. The line is because we start at
Instead of setting the position, we just return the new position, and we don't have to specify an initial position -- it will use the first returned value. So that's pretty good. This draws really fast; let's slow it down a little:
And I think that works! It's not a direct translation of the formula on the wikipedia page, though -- I think a more direct translation is this:
But it seems that swapping the trigonometric function has same effect as negating |
Beta Was this translation helpful? Give feedback.
Hey! Happy to help.
So there's not actually a reason to make this a macro -- you can pass functions as arguments to other functions and call them just fine. That'll simplify things a bit.
I renamed
fn
andfn2
tof
andf2
, becausefn
is a special-form -- you can create a variable calledfn
but you won't actually be able to call it -- not sure if that's what led yo…