<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Sun, 12 Jul 1998 00:57:14 +0100
From   : jgh@... (Jonathan Graham Harston)
Subject: Circle routines in Basic

HANSELL Mike <hanselm@...> wrote:
MH> As a Beeb years years ago I recall that BBC Basic doesn't have a
MH> circle function. I also recall that there were several techniques
MH> developed to produce them. I'd be very appreciative if anybody could
MH> supply the basic source code to any of them.
 
This is a routine that I use.  It does everything I want it to and it's
neat and tidy.  It has additional advantages in that it can EOR itself
with GCOL 4,x without leaving untidy residue, ie doing:
 
    GCOL 4,7:PROCcircle(640,515,512,TRUE):PROCcircle(640,512,512,TRUE)
 
will leave the screen in it's initial state, the second identical circle
completely erasing the first.  Try the following for a nice effect:
 
    GCOL 4,7:FOR A%=32 TO 512 STEP 32:PROCcircle(640,512,A%,TRUE):NEXT
 
Another advantage (to some people) is that SIN and COS are only ever used
once, with an invariant parameter that is independant of the circle
itself, so that could be hard-coded into a constant.  The loop only uses
addition (and subtraction) and multiplication (by those initial
constants).
 
  DEFPROCcircle(x%,y%,r%,f%):REM X posn, Y posn, Radius, Filled?
  LOCAL step,s,c,xp,yp,xr
  step=(2*PI/90)+50:      REM Length of each arc
  s=SINstep:              REM Precalculate sin of step
  c=COSstep:              REM Precalculate cosine of step
  xp=r%:yp=0:             REM Set initial position
  MOVEx%+xp,y%+yp:        REM Move to initial point on edge
  FOR segment=1 TO 31:    REM We'll do 31 segments here
  xr=xp*c-yp*s:           REM Calculate next point on edge
  yp=xp*s+yp*c
  xp=xr
  IF f%: DRAW x%,y%:PLOT85,x%+xp,y%+yp:          REM Do segment if filled
  IFNOTf%:DRAW x%+xp,y%+yp:PLOT 69,x%+xp,y%+yp:  REM ..else draw arc
  DRAW x%+xp,y%+yp:PLOT 69,x%+xp,y%+yp
  NEXT:                   REM And again
  IF f%: DRAW x%,y%:PLOT 85,x%+r%,y%+0:          REM Do final segment
  IFNOTf%:DRAW x%+r%,y%+0:PLOT 69,x%+r%,y%+0:    REM ..or arc
  ENDPROC
 
--
J.G.Harston (JGH BBC PD Library) 70 Camm Street, Walkley, SHEFFIELD S6 3TR
BBC+Master / Z80+6502 / CoPro+Tubes / Econet+SJ / Devolution / Transport /
Planning / Highways    http://homepages.nildram.co.uk/~amilton/walkley.htm
jgh@...                  (( Anti-UCE address added by Arcade, not by me ))
               - + - * NTAUS#3 24th-26th July 1998 * - + -
                 At my place again - Contact for details
-- 
    ___  ___  ___  ___  ___  ___   | Free Internet E-mail and Anti-UCE News | 
|  /   \/   \/   \/   \/   \/   \  | +44 181 654 2212 also +44 181 655 4412 |
|    A    R    C    A    D    E    |   Croydon  UK  -  Fidonet#2:254/27.0   |
|     The Definitive Acorn BBS     | http://arcade.demon.co.uk  at weekends |
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>