[bb] Multisided geometric shapes by TartanTangerine (was Indiepath) [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : Multisided geometric shapes
Author : TartanTangerine (was Indiepath)
Posted : 1+ years ago

Description : This little snippit of code allows you to draw a geometric shape of any size with any amount of sides, well more than 2 sides would be a good start.

Code :
Code (blitzbasic) Select
; Written by Tim Fisher of Indiepath 2005. http://www.indiepath.com

; *******************************************************************************
; DrawGeom - Will draw a polygon of n Sides.
; x#,y# = Screen Co-ordinates
; Sides# = Number of sides on Polygon
; Length# = Length of Side
; Angle# = Angle of Rotation
; *******************************************************************************

Function DrawGeom(x#,y#,sides#,length#,angle#)

Local aStep# = 360 / sides
Length# = (length/2)/Sin(aStep#/2) ;Calculate the correct length of a side
For a = 0 To sides-1
x1# = x# - (Sin(angle + (aStep * a))*length)
y1# = y# - (Cos(angle + (aStep * a))*length)
x2# = x# - (Sin(angle + (aStep * (a+1)))*length)
y2# = y# - (Cos(angle + (aStep * (a+1)))*length)
Color 150,150,150
Oval x1-5,y1-5,11,11,False ; Draw Circle at Vertex
Color 255,255,255
Line x1,y1,x2,y2 ; Draw Connecting Lines
Next

End Function


Comments :


TartanTangerine (was Indiepath)(Posted 1+ years ago)

 UPdated with new Length Calculation.


Ian Thompson(Posted 1+ years ago)

 Very nice, very nice indeed. Well done and thankyou. :)


Rck(Posted 1+ years ago)

 Good one