CPCWiki forum

General Category => Programming => Topic started by: mr_lou on 19:12, 08 January 20

Title: Drawing a circle in BASIC - fast
Post by: mr_lou on 19:12, 08 January 20
As a kid, I used to do this all the time: Draw a circle using PLOT with SIN and COS - taking about 13 seconds. I had no clue that "render" time could be significantly reduced by using precalculations and other tricks.


10 MODE 1:INK 0,0:BORDER 0:INK 1,2:INK 2,6:INK 3,18
20 DEG:DIM s%(360),c%(360):x%=320:y%=298:p%=1
30 ORIGIN x%,y%:FOR n%=0 TO 360:s%(n%)=SIN(n%)*100:c%(n%)=COS(n%)*100:PLOT s%(n%),c%(n%),p%:NEXT
40 FOR t%=1 TO 15:LOCATE 1,1:PRINT CHR$(11)
50 p%=p%+1:IF p%=4 THEN p%=1
60 GOSUB 90:NEXT
70 LOCATE 1,1:PRINT CHR$(11):p%=p%+1:IF p%=4 THEN p%=1
80 GOSUB 90:GOTO 70
90 PLOT s%(0),c%(0),p%:FOR n%=0 TO 360 STEP t%:DRAW s%(n%),c%(n%),p%:NEXT:DRAW s%(0),c%(0),p%:RETURN
Title: Re: Drawing a circle in BASIC - fast
Post by: SRS on 20:14, 08 January 20
Remembers me of this Thread: http://www.cpcwiki.eu/forum/programming/drawing-fast-circles-in-locomotive-basic/msg12068/#msg12068

:)
Title: Re: Drawing a circle in BASIC - fast
Post by: AMSDOS on 11:16, 09 January 20
Quote from: SRS on 20:14, 08 January 20
Remembers me of this Thread: http://www.cpcwiki.eu/forum/programming/drawing-fast-circles-in-locomotive-basic/msg12068/#msg12068 (http://www.cpcwiki.eu/forum/programming/drawing-fast-circles-in-locomotive-basic/msg12068/#msg12068)

:)


Unfortunately that old thing isn't very practical if Circles of various sizes were used, by taking the centre point and radius and storing the DATA of it into a file and use the other routine to Draw it. But it did help me learn more about DATA and how Assembly could use it for routines.


@mr_lou (http://www.cpcwiki.eu/forum/index.php?action=profile;u=96) The other thread (http://www.cpcwiki.eu/forum/programming/bresenham-integer-circle-algorithm/) which is the more useful of the 2 uses the Bresenham algorithm and has some interesting routines as well as an article from Your Computer with some other Circle Routines.
Title: Re: Drawing a circle in BASIC - fast
Post by: roudoudou on 13:19, 09 January 20
there is many ways to draw circles fast in pure basic depending on what you really need

so, what do you need?  ;D
Powered by SMFPacks Menu Editor Mod