Creating a circular movement

Page 2/2
1 |

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

03-01-2014, 13:06

Daemos wrote:

I however need to move the sprite 1 pixel per frame. I also need to be able to variate the speed. I am not sure if I can pull it of with this routine because it makes a full 45 degrees movement per call right?. I can anyhow use it to generate a nice working table.

Is there also a way to apply such algorithm to create a smooth XY coord table in for example excel which I can export?

Ok, let's solve this in a traditional way...

10 SCREEN 5
20 AP=ATN(1)*2:AT=AP*4
30 SPRITE$(0)="@"
40 FOR I=0 TO 255
50 X=SIN(AT/256*I)*80
60 Y=SIN(AT/256*I+AP)*80
70 PUT SPRITE 0,(X+128,Y+106),8
80 IF INKEY$>"" THEN END
90 NEXT I:GOTO 40

Yes, I could have used COS-but this way you can see that you need only one table.
To compare the values, this listing exports both of them:

10 ' To Excel
20 DEFINT X,Y
30 OPEN "XY.CSV" FOR OUTPUT AS #1
40 AP=ATN(1)*2:AT=AP*4
50 FOR I=0 TO 499
60 X=SIN(AT/500*I)*80
70 Y=SIN(AT/500*I+AP)*80
80 PRINT#1,X;",";Y
90 NEXT I:CLOSE

By Daemos

Paragon (2044)

Daemos's picture

03-01-2014, 14:31

This is like. Take a man that doesn't know how to do something and put the whole concept working in his hands. Many thanks. I think I have all the info I need. Thank you all for your very informative responses.

By Daemos

Paragon (2044)

Daemos's picture

03-01-2014, 20:34

The Basic code works like a charm. It creates a circular movement that starts down and moves upwards in a counterclockwise motion. I will have to figure out how to change that but the circle looks smooth in game Smile

I executed this script on a real msx and boy the machine had to do some work (at least 1 minute if not longer in waiting time) but I just got a perfect XY table that does the trick.

Just to let you know it works.

By Vampier

Prophet (2409)

Vampier's picture

03-01-2014, 21:23

maybe a good idea to use only 64 steps and pre-calc the sin/cos values into an array.

By hit9918

Prophet (2927)

hit9918's picture

03-01-2014, 22:31

how many angle steps are needed, so many that painting would keep a closed circle.
not having a closed circle, only one speed, the speed "one angle step per frame" goes without wobble.

"I currently have 500 steps".
512 is better. to make things run in circles, instead of "if a > 500 then" kind of things, it simply will read AND 511, done.

Page 2/2
1 |