/*	polygon.oop
 
  	Example polygon drawing class.  Good example of multi-
		dimensional arrays.

		Copyright (c) Dan Ramage 2000
		Last update: Jan 17, 2000
*/

PROC Start:
	Main:
ENDP


// Since the class is not STATIC, we need cOBJECT class
// definition
#include <object.oop>


CLASS cPOLYGON : cOBJECT
	PROC
		cPOLYGON:					// Constructor
		_cPOLYGON:				// Destructor
		AddVertex:(x%,y%)	// Add a vertex
		Draw:(angle)			// Draw the polygon
	ENDP
	DATA
		point%(40,2)			// An array of up to 40 points 
		count%						// How many points are registered
	ENDD
ENDC


PROC cPOLYGON::cPOLYGON:
	me@->count% = 0
ENDP

PROC cPOLYGON::_cPOLYGON:
ENDP

PROC cPOLYGON::AddVertex:(x%,y%)
	me@->count%++
	me@->point%(me@->count%,1) = x%
	me@->point%(me@->count%,2) = y%
ENDP

PROC cPOLYGON::Draw:(angle)
	LOCAL c%,x%,y%
	
	x%=gX
	y%=gY
	
	c% = 1
	WHILE c% <= me@->count%
		gLINETO x%+COS(angle)*me@->point%(c%,1),y%+SIN(angle)*me@->point%(c%,2)
		c%++
	ENDWH
ENDP



PROC Main:
	LOCAL <cPOLYGON*>poly@

	poly@ = NEW cPOLYGON
	poly@.AddVertex:(0,0)
	poly@.AddVertex:(50,12)
	poly@.AddVertex:(40,18)
	poly@.AddVertex:(85,50)
	poly@.AddVertex:(30,40)
	poly@.AddVertex:(0,0)

	gAT 200,40
	poly@.Draw:(PI/4)
	
	GET
ENDP

