Let me clear things up:
I don't know trigonometry.
I made this from my incredibly basic understanding of it.
Do not expect this to be great.
But I mean, it kinda gets the job done?
anyway, here it is.
PHOTOSENSITIVITY WARNING: If the character reaches the mouse, it moves left and right fast.
(Please explain to me how to do trig for this in the comments)
I ran a test of a couple ways to do this, then noticed the responses that happened in the meantime, so I'll just go ahead an post results. Just printing the cpu usage, drawing the character and placing the dot took %0.0085. Using dw817's code took %0.009. Using either your code in the first post took %0.0095. Using a more straight forward approach based on distance took %0.0096.
No, your solution isn't inaccurate. It's more accurate, but in a way that's unnecessary. What dw817 suggested is a variation on Bresenham's line drawing algorithm. It takes advantage of the fact that pico-8 can't draw between pixels and rounds implicitly while keeping track of the error so that it never reaches 1 full pixel of inaccuracy.
Did a test just now to see if the disappearing is for the (to me) obvious reason. Did you make sure your version of the code avoids division by 0? In dw817's code,
a=max(1,a) accomplishes that.
Sorry 'bout that vanishing act, @MrAwesome. I fixed it. I was not checking divided by zero earlier.
a=max(1,a) It should run perfectly now every time.
And yes, @kimiyoribaka. I truly hate SIN() and COS(). Wow. They give such inaccurate numbers when trying to draw perfectly curved surfaces.
-- ugly old circle x=96 y=64 cls() for i=0,359,2 do pset(x,y) x=x+sin(i/359) y=y+cos(i/359) flip() end
I was curious, is there some other way to draw a perfect circle every time in code just as brief ?
Probably should start another thread for circle questions. However, in the interest of keeping misleading info to a minimum, I feel compelled to point out what's actually wrong with that circle code. Mainly, the issue is that
pset() truncates numbers. It doesn't round. For proper rounding, you'd have to use
pset(x+.5,y+.5). There's other issues too, but they'd be more suitable to discuss in a "sine and cosine are terrible. fight me." thread.
[Please log in to post a comment]