Author Topic: Drawing a circle in BASIC - fast  (Read 814 times)

0 Members and 1 Guest are viewing this topic.

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 3.180
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1345
  • Likes Given: 2661
Drawing a circle in BASIC - fast
« on: 20: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.

Code: [Select]
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
« Last Edit: 07:49, 09 January 20 by mr_lou »

Offline SRS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 628
  • Country: de
  • Schneider CPC464 - what else ?
  • Liked: 627
  • Likes Given: 366

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1157
  • Likes Given: 1924
Re: Drawing a circle in BASIC - fast
« Reply #2 on: 12:16, 09 January 20 »
Remembers me of this Thread: 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 The other thread 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.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Online roudoudou

  • 6128 Plus
  • ******
  • Posts: 963
  • Country: fr
    • urban exploration
  • Liked: 1347
  • Likes Given: 802
Re: Drawing a circle in BASIC - fast
« Reply #3 on: 14: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
use RASM, the best assembler ever made :p

I will survive