Trying to draw circles in basic.

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
Post Reply
Gigadave
Posts: 10
Joined: 03 Mar 2019, 10:50

Trying to draw circles in basic.

Post by Gigadave »

Hi,

I have been trying to draw circles in Tiny Basic using the line command.

Can someone please share a small basic program I can use as a reference ?

Thanks
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: Trying to draw circles in basic.

Post by marcelk »

This is based on Bresenham's algorithm:

Code: Select all

'Draw filled circle with
'LINE statements
10 x=80:y=60:u=45:'Radius
20 cls:v=0:w=0
30 at x-u,y-v:line u+u,0
40 at x-u,y+v:line u+u,0
50 w=w+v+v+1:v=v+1
60 if w<0 goto 30
70 w=w-u-u+1:u=u-1
80 if u>0 goto 60
I wonder how fast a Commodore 64 can do this in BASIC...

Screenshot
Screenshot
Disc.png (56.78 KiB) Viewed 3290 times
Gigadave
Posts: 10
Joined: 03 Mar 2019, 10:50

Re: Trying to draw circles in basic.

Post by Gigadave »

Thanks, thats great.

I have made a colourful pattern.

5 poke 42,0:cls
6 a=61
7 a=a-1
8 poke 43,a
10 x=80:y=60:u=a
20 v=0:w=0
30 at x-u,y-v:line u+u,0
40 at x-u,y+v:line u+u,0
50 w=w+v+v+1:v=v+1
60 if w<0 goto 30
70 w=w-u-u+1:u=u-1
80 if u>0 goto 60
85 if a<2 goto 85
90 goto 7

Is there a way of drawing an empty circle ?

Thanks
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: Trying to draw circles in basic.

Post by marcelk »

Thanks for sharing :-)
Gigadave wrote: 06 Mar 2019, 06:44 Is there a way of drawing an empty circle ?
You can use the same algorithm and plot pixels instead of drawing lines, I suppose. I haven't tried.
Wikipedia has a lot of background: https://en.wikipedia.org/wiki/Midpoint_circle_algorithm
Post Reply