Log In  

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)

Cart #mijukohuko-0 | 2022-08-29 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

P#116534 2022-08-29 22:05

1

You may not have to use SIN or COS to get a true follow, @MrAwesome. Let me see here ...

Cart #rewobonaho-0 | 2022-08-29 | Code ▽ | Embed ▽ | No License
1

P#116540 2022-08-29 22:48 ( Edited 2022-08-29 23:38)

Thanks, @dw817. But, there seems to be a problem: sometimes the character just kinda... disappears?

(Don't mind the number at the top, just trying to understand the code better)
Also, which one would be faster? Is my solution inaccurate?

P#116541 2022-08-29 23:08

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.

P#116545 2022-08-29 23:31

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 ?

P#116547 2022-08-29 23:38 ( Edited 2022-08-29 23:58)

Alright, thanks @kimiyoribaka and @dw817.

P#116549 2022-08-30 00:07

@dw817
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.

P#116551 2022-08-30 00:23

Sounds like an interesting discussion, @kimiyoribaka. Yep, and I've got and have had some ideas to get around SIN and COS for years now.

If I have time I'll start a new thread of that very topic with your thanks - tomorrow.

P#116553 2022-08-30 00:28

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 08:13:44 | 0.049s | Q:30