Hi
This is the way I do the polygons.
CodeGuy showed me a cool formula to do it rather than use
my select case statements to set the degrees and angles etc.
I remmed out my select case so you can see how I was doing it.
Codeguys formula is in effect in this version. its just below the select case statments.
There are several comments in the code showing what is happening.
Just a suggestion: On my computer I have made the sub polygon into a 'bi' file
so it doesnt have to be in a program for me. and I can use it just like the basic circle
and line statements!
However if one was to share a prog that uses it this way he/she would have to send
it along with the bi file which might be a pain for some.
'Polygons by Dustie Bear
'_______________________
SCREEN 12
DO WHILE s <> 1
LOCATE 10, 28
INPUT " Number of sides "; s
LOCATE 12, 28
INPUT " Radius Length "; ss
LOCATE 14, 28
INPUT " Line color "; LC
LOCATE 16, 28
INPUT " Paint Color "; PC
CLS
'-- Notice I have x and y preset in the variable to send to the sub but you
'-- can put vars there so that you main program can set the x,y where ever you want it
Polygon 300, 200, ss, s, LC, PC, 1
DO WHILE INKEY$ = "": LOOP
COLOR 15, 0
CLS 0
LOOP
SYSTEM
'---------- Polygon Sub ---------------------------
SUB Polygon (PosX AS INTEGER, PosY AS INTEGER, Rad AS INTEGER, NumSides AS INTEGER, LClr AS INTEGER, FClr AS INTEGER, PaintDo AS INTEGER)
'__________________________________________
' PosX = 300 - - X Positon
' PosY = 200 - - Y Postion
' Rad = 150 - - - Radius
' NumSides = 12 - How Many sides
' LClr = 13 - - - Line Clolor
' FClr = 2 - - - Fill Color
' PaintDo = 1 - - Fill it with Color ? 1 = yes, anything else is no
' _________________________________________
' Angles are set so that the base is laying flat on the bottom!
' Rem them out it you want to set them from your main Program Them differantly
'__________________________________________
' ---- If no color enterd, at least make it so the polygon will show
IF LClr = 0 AND FClr = 0 THEN
LClr = 15 ' white
PaintDo = 0 ' Turn off the fill if its on - Fill is on only when PaintDo = 1
END IF
' ---- Degrees at each line intersection
' ---- Angle = angle at which the fist line starts from
'
' ---- This is how I figured out how to do the degrees using Select case for the
' ---- octygons. it only figures up to 13 sided polys, but more than that they just look like circles
' ---- in lower res screens
' --- Below the SELECT CASE STATMENTS is the formula which Codeguy showed me
' ----- which makes my SELECT CASE not needed.
'SELECT CASE NumSides
' CASE 3
' NumSides = 3: Degree = 120: angle = 30
' CASE 4
' NumSides = 4: Degree = 90: angle = 45
' CASE 5
' Numside = 5: Degree = 72: angle = 54
' CASE 6
' NumSides = 6: Degree = 60: angle = 60
' CASE 8
' NumSides = 8: Degree = 45: angle = 22.5
' CASE 9
' NumSides = 9: Degree = 40: angle = 30
' CASE 10
' NumSides = 10: Degree = 36: angle = 36
' CASE 11
' NumSides = 11: Degree = 32.727272: angle = 8
' CASE 12
' NumSides = 12: Degree = 30: angle = 15
' CASE ELSE
' PRINT "Sorry I only do 3 to 12 sided polygons";
' SLEEP
'END SELECT
'************** CodeGuy Showed me how to do the degrees with Math ************************
' ---- Degrees at each line intersection
' ---- Angle = angle at which the first line starts from
Degree = 360 / NumSides
angle = (180 - Degree) / 2
'**************************************
' ------- Draw the Poly
FOR t = 1 TO NumSides + 1
angle = angle + Degree
RADIAN = angle / 57.2958
x = COS(RADIAN) * Rad
y = SIN(RADIAN) * Rad
a = x + PosX: b = y + PosY
IF t = 1 THEN DRAW "c=" + VARPTR$(LClr) + "BM=" + VARPTR$(a) + ",=" + VARPTR$(b)
DRAW "M=" + VARPTR$(a) + ",=" + VARPTR$(b)
NEXT t
' ------ Fill the Poly with color
IF PaintDo = 1 THEN
PAINT (PosX + 1, PosY), FClr, LClr
END IF
END SUB