[net.micro.cbm] C-Power graphics package part 5 of 6

prindle@nadc (10/21/86)

From: prindle@NADC

/* Graphics Package - Part 2
** Filename: grafpak2.c
** Author: Mark R. Rinfret
** Date:   12/14/85
** Description:
**
** This is part 2 of a multi-part graphics package, written in C (C-Power)
** for the Commodore 64.  The routines contained in this segment are:
**
** arc     - draws arcs, line segments, circles, ellipses, polygons
** circle  - simplified call to arc
**  
**  
*/
#include <stdio.h>
#include <strings.h>
#include <math.h>
#include "grafpak.h"

/* Plot an arc. 
** Parameters:
** xorigin,yorigin - center point
** xrad,yrad - x and y radii
** start,end - starting, ending point for arc, in degrees 
** angl - degrees of rotation (not used yet)
** incr - degrees between steps (FLOAT!); 120.0 yields a triangle
** pen - (0-3) pen number to draw with
*/
arc(xorigin,yorigin,xrad,yrad,
    start,end,angl,incr,pen)
unsigned xorigin,yorigin,xrad,yrad,start,end,angl; float incr; unsigned pen;
{
  register unsigned cnt,x,y,px,py;
  float arad,fstart,fend,fincr,fxrad,fyrad,xo,yo;

  cnt = 0;
  fincr = incr;          /* copy to local */
  fyrad = yrad;
  fxrad = xrad * aspect; /* adjust to aspect ratio */
  xo = xorigin; yo = yorigin;
  for (fstart=start,fend=end;fstart<=fend;fstart += fincr) {
    arad = fstart/RADCON;
    x = xo + fxrad * cos(arad);
    y = yo + fyrad * sin(arad);
    if (!cnt) pset(x,y,pen);
    else line(px,py,x,y,pen);
    px=x; py=y;
    cnt++;
  }
}

/* Plot a circle */
circle(xorigin,yorigin,radius,pen)
unsigned xorigin,yorigin,radius,pen;
{
  arc(xorigin,yorigin,radius,radius,
      0,360,0,1.0,1);
}