In the Commodore 64's version of BASIC (2.0), there's no built-in command to directly draw a circle. But we can create a circle using a simple mathematical concept.
Here's a small program that will draw a circle on the screen using PRINT statements:
BASIC
10 PRINT CHR$(147)
20 FOR T = 0 TO 6.28 STEP 0.1
30 X = 20 + 10 * COS(T)
40 Y = 11 + 10 * SIN(T)
50 POKE (1024 + INT(Y) * 40 + INT(X)), 81
60 NEXT T
70 GET A$: IF A$="" THEN 70
80 PRINT CHR$(147)
Here's how it works:
• Line 10 clears the screen.
• Lines 20 to 60 draw the circle:
◦ We're looping over the angles of the circle (from 0 to 2π or roughly 6.28).
◦ We're using the trigonometric functions COS and SIN to get the X and Y coordinates of a point on the circle.
◦ We're adding offsets to the X and Y coordinates to position the circle in the middle of the screen.
◦ The POKE statement puts a character at the calculated screen position.
• Line 70 waits for a key press.
• Line 80 clears the screen again.
Note that the circle might not look perfect because of the aspect ratio of the C64's text mode, and we're using a text character (81) to draw the circle. In high-resolution graphics mode, you would be able to draw a more perfect circle, but that requires a much more complex program.
Ei kommentteja:
Lähetä kommentti