-
-
Save git2358/b38adabd137dcb6e0e044a0b03b2bce7 to your computer and use it in GitHub Desktop.
The Pico-8 code showing off rotations math.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --rotations by eis - kino | |
| --globals | |
| --The sprites, the position (x and y) of both star1 and star2 | |
| star1 ={sprite=2, x = 58, y = 58} | |
| star2 ={sprite=3, x = 0, y = 0} | |
| degrees = 0 | |
| function _update() | |
| --Here we rotate star2 around star1 by giving rotate star1's position(x, y). | |
| rotate(star1.x, star1.y, 10, star2) | |
| end | |
| function _draw() | |
| cls() | |
| map(0,0,0,0,16,16) | |
| spr(star1.sprite, star1.x, star1.y) | |
| spr(star2.sprite, star2.x, star2.y) | |
| end | |
| -- rotation logic | |
| function rotate(x, y, radius, star) | |
| degrees += 0.05 | |
| --We update star's position by incrementing the degrees and using our formula | |
| -- x + (radius * cosine(degrees)) = a point on the edge of the circle in the x-axis | |
| -- y + (radius * sine(degrees)) = a point of the edge of the circle in the y-axis | |
| star.x = x + (radius * cos(degrees)) | |
| star.y = y + (radius * sin(degrees)) | |
| end | |
| --draw debug inforatmion | |
| function drawdebug() | |
| print("star2\nx: "..star2.x.." y: "..star2.y) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment