Here is some code do do just that. Lets see if we can come up with even more shapes.
Each shape routine starts with the word Draw and the name of the shape (even shape is a routine). The options are position (x,y) and the size to draw it at. Can this be improved?
I hope ya enjoy the shaping adventure.
Code: Select all
#include "fbgfx.bi"
Const pi=3.14159265
Const Radian=pi/180
Const ScreenWidth=160
Const ScreenHeight=120
Sub DrawHeart(xPos As Integer,yPos As Integer,Size As Single)
For t as Single= 0 To 2*pi Step 0.01
Dim As Integer x=xPos+CInt(Size*16*Sin(t)^3)
Dim As Integer y=yPos-CInt(Size*(13*Cos(t)-5*Cos(2*t)-2*Cos(3*t)-Cos(4*t)))
PSet (x,y),RGB(255,0,0)
Next
End Sub
Sub DrawHeptagon(xPos As Integer,yPos As Integer,Size As Integer)
Dim As Single Angle,nextAngle
Dim As Integer Vertices(7,2)
For Hept as Integer= 0 To 6
Angle=(Hept*2*pi)/7
Vertices(Hept+1,1)=xPos+Cos(angle)*Size
Vertices(Hept+1,2)=yPos+Sin(angle)*Size
Next
For Hept as Integer= 1 To 7
Line (Vertices(Hept,1),Vertices(Hept,2))-(Vertices((Hept Mod 7)+1,1),Vertices((Hept Mod 7)+1,2)),RGB(255,255,255)
Next
End Sub
Sub DrawHexagon(xPos As Integer,yPos As Integer,Size As Integer)
Dim As Integer x(5),y(5)
For Hexa As Integer= 0 To 5
x(Hexa)=xPos+Size*Cos((Hexa*60)*Radian)
y(Hexa)=yPos+Size*Sin((Hexa*60)*Radian)
Next
For Hexa As Integer= 0 To 5
Line (x(Hexa),y(Hexa))-(x((Hexa+1) Mod 6),y((Hexa+1) Mod 6)),RGB(255,255,255)
Next
End Sub
Sub DrawOctagon(xPos as Integer,yPos as Integer,Size as Integer)
For Octagon as Integer= 0 To 7
Dim As Single Angle=Octagon*(2*pi/8)
Dim As Single x1=xPos+Cos(Angle)*Size
Dim As Single y1=yPos+Sin(Angle)*Size
Angle=(Octagon+1)*(2*pi/8)
Dim As Single x2=xPos+Cos(Angle)*Size
Dim As Single y2=yPos+Sin(Angle)*Size
Line (x1,y1)-(x2,y2),RGB(255,255,255)
Next
End Sub
Sub DrawPentagon(xPos As Integer,yPos As Integer,size As Single)
Dim As Single Radius=Size
Dim as Integer angleOffset=0,numVertices=5
Dim As Single x(numVertices-1),y(numVertices-1)
For Pentagon As Integer=0 To numVertices-1
Dim As Single Angle=(360/numVertices)*Pentagon+angleOffset
x(Pentagon)=xPos+Radius*Cos(Angle*Radian)
y(Pentagon)=yPos-Radius*Sin(Angle*Radian)
Next
For Pentagon As Integer=0 To numVertices-1
Line (x(Pentagon),y(Pentagon))-(x((Pentagon+1) Mod numVertices),y((Pentagon+1) Mod numVertices)),RGB(255,255,255)
Next
End Sub
Sub DrawRhombus(xPos As Integer,yPos As Integer,Size As Integer)
Dim as Integer x1=xPos,y1=yPos-Size
Dim as Integer x2=xPos + Size,y2=yPos
Dim as Integer x3=xPos,y3=yPos + Size
Dim as Integer x4=xPos-Size,y4=yPos
Line (x1,y1)-(x2,y2),RGB(255,255,255)
Line (x2,y2)-(x3,y3),RGB(255,255,255)
Line (x3,y3)-(x4,y4),RGB(255,255,255)
Line (x4,y4)-(x1,y1),RGB(255,255,255)
End Sub
Sub DrawShape(xPos as Integer,yPos as Integer,Size as Integer)
Dim Points(23) as Double
For Shape As Integer=0 to 4
Points(Shape*2)=xPos+COS((Shape*2*pi)/5)*Size
Points(Shape*2+1)=yPos-SIN((Shape*2*pi)/5)*Size
Points(Shape*2+10)=xPos+COS(((Shape*2+1)*pi)/5)*(Size*0.5)
Points(Shape*2+11)=yPos-SIN(((Shape*2+1)*pi)/5)*(Size*0.5)
Next
For Shape As Integer=0 To 4
Line (Points(Shape*2),Points(Shape*2+1))-(Points(((Shape+1) Mod 5)*2),Points(((Shape+1) Mod 5)*2+1)),RGB(255,255,255)
Line (Points(Shape*2),Points(Shape*2+1))-(Points(Shape*2+10),Points(Shape*2+11)),RGB(255,255,255)
Line (Points(Shape*2+10),Points(Shape*2+11))-(Points(((Shape+1) Mod 5)*2+10),Points(((Shape+1) Mod 5)*2+11)),RGB(255,255,255)
Next
End Sub
Sub DrawStar(xPos as Integer,yPos as Integer,Size as Integer)
Dim Points(23) as Double
Dim rotationOffset as Double=-pi/2
For Star As Integer=0 to 4
Points(Star*2)=xPos+COS((Star*2*pi)/5-rotationOffset)*Size
Points(Star*2+1)=yPos-SIN((Star*2*pi)/5-rotationOffset)*Size
Points(Star*2+10)=xPos+COS(((Star*2+1)*pi)/5-rotationOffset)*(Size*0.5)
Points(Star*2+11)=yPos-SIN(((Star*2+1)*pi)/5-rotationOffset)*(Size*0.5)
Next
For Star As Integer = 0 To 4
Line (Points(Star*2),Points(Star*2+1))-(Points(Star*2+10),Points(Star*2+11)),RGB(255,255,255)
Line (Points(Star*2+10),Points(Star*2+11))-(Points(((Star+1) Mod 5)*2),Points(((Star+1) Mod 5)*2+1)),RGB(255,255,255)
Next
End Sub
ScreenRes ScreenWidth,ScreenHeight,32
'DrawHeart(ScreenWidth\2,ScreenHeight\2,2)
'DrawPentagon(ScreenWidth\2,ScreenHeight\2,32)
'DrawHeptagon(ScreenWidth\2,ScreenHeight\2,32)
'DrawHexagon(ScreenWidth\2,ScreenHeight\2,32)
'DrawOctagon(ScreenWidth\2,ScreenHeight\2,32)
'DrawRhombus(ScreenWidth\2,ScreenHeight\2,16)
'DrawShape(ScreenWidth\2,ScreenHeight\2,32)
'DrawStar(ScreenWidth\2,ScreenHeight\2,32)
Sleep