Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Draw a circle without using trigonometry
#1
This is totally useless, as the "draw ellipse" routine is far more useful in N7, but I was struck by the simplicity and effectiveness of this code, which I found on the "Basic programming language" group on Facebook.

Code:
visible screen_w = 640,screen_h = 480
'Open a window
set window "Easy circle",screen_w,screen_h
'enable double buffering
set redraw off

do

'clear the screen
set color 255,255,255
cls
set color 0,0,0
'draw some pixels
e = 1/32
x = 30 ' radius
y = 0
for i = 0 to 199
    x = x - y*e
    y = y + x*e
    draw pixel x + 200,y + 200 ' 200,200 is the center of the circle
next

'copy back buffer to the screen
redraw
'cap FPS to 60
fwait 60

until keydown(KEY_ESCAPE)
Reply
#2
Haha, very cool!
Reply
#3
Impressive! A pixel at a time with NO trig! Yes. Very cool, indeed.
Logic is the beginning of wisdom.
Reply
#4
(01-17-2026, 03:21 PM)kevin Wrote: ... I was struck by the simplicity and effectiveness of this code...

It's genial. Thanks for sharing !

Let me animate the pixels in circles ...
Code:
constant screen_w = 640,screen_h = 480

set window "Easy circle Animation",screen_w,screen_h
set redraw off


'----------------
' INITIALIZATION
'----------------
black = [0,0,0]
white = [255,255,255]

e = 1/32
x = 30   ' radius
y = 0

'clear the screen
set color black ; cls
cls
set color white


'-----------
' MAIN LOOP
'-----------
do
    'draw some pixels
    for i = 0 to 199+10
        x = x - y*e
        y = y + x*e
        draw pixel x + width()/2,y + height()/2
        redraw
        fwait 60
    next
   
    x = x + 20
    y = y + 20
   
until keydown(KEY_ESCAPE)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)