Trying to draw circles in basic.

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

Trying to draw circles in basic.

Post by Gigadave » 05 Mar 2019, 04:53

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: 178
Joined: 13 May 2018, 08:26

Re: Trying to draw circles in basic.

Post by marcelk » 05 Mar 2019, 22:28

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...

Disc.png
Screenshot
Disc.png (56.78 KiB) Viewed 118 times

Gigadave
Posts: 10
Joined: 03 Mar 2019, 10:50

Re: Trying to draw circles in basic.

Post by Gigadave » 06 Mar 2019, 06:44

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: 178
Joined: 13 May 2018, 08:26

Re: Trying to draw circles in basic.

Post by marcelk » 14 Mar 2019, 07:07

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