[bb] Vector Graphics Functions by SSS [ 1+ years ago ]

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

Previous topic - Next topic

BlitzBot

Title : Vector Graphics Functions
Author : SSS
Posted : 1+ years ago

Description : hi all, in my spare time i made some vector geometry methods, and i thought after i made them that some people might find them usefull, i havnt added alot of features like color blending or collision but if people thought that they would like this then i would implement them :D

Please note, this was an exercise i set for myself in writing a linked list... but then i thought that it might be usefull, in the example, click the mouse in relation to the SQUARE in the center to append a vector in that direction + that magnetude


Code :
Code (blitzbasic) Select
here is the function set


Type Vector2
Field x,y
End Type
Type Vector3
Field x,y,z
End Type

Type VectorGeomObject
Field start.VectorGeomSet
Field size
Field position.Vector2
End Type

Type VectorGeomSet
Field movement.Vector2
Field StartColor.Vector3
Field EndColor.Vector3
Field NextSet.VectorGeomSet
End Type


Function Vec2.Vector2(x,y)
v.Vector2 = New Vector2
vx = x
vy = y
Return v
End Function

Function Vec3.Vector3(x,y,z)
v.Vector3 = New Vector3
vx = x
vy = y
vz = z
Return v
End Function

Function CreateVector(x = 0, y = 0)
v.VectorGeomObject = New VectorGeomObject
vsize = 0
vposition.Vector2 = New Vector2
vpositionx = x
vpositiony = y
Return Handle(v)
End Function

Function PositionVector(hVector,x,y)
v.VectorGeomObject = Object.VectorGeomObject(hVector)
vpositionx = x
vpositiony = y
End Function

Function AppendVector(hVector,vector.Vector2,startcolor.Vector3,endcolor.Vector3)
v.VectorGeomObject = Object.VectorGeomObject(hVector)
If vsize = 0
vstart.VectorGeomSet = New VectorGeomSet
vecset.VectorGeomSet = vstart
vecsetmovement.Vector2 = vector
vecsetStartColor = startcolor
vecsetEndColor = endcolor
vecsetNextSet.VectorGeomSet = New VectorGeomSet
vsize = vsize +1
Else
vecset.VectorGeomSet = vstart
For i = 1 To vsize-1
vecset = vecsetNextSet
Next
vecsetNextSet.VectorGeomSet = New VectorGeomSet
vecset = vecsetNextSet
vecsetmovement.Vector2 = vector
vecsetStartColor = startcolor
vecsetEndColor = endcolor
vsize = vsize+1
EndIf
End Function

Function GetNumVectors(hVector)
v.VectorGeomObject = Object.VectorGeomObject(hVector)
Return vsize
End Function

Function EditVector(hVector,Index,vector.Vector2,startcolor.Vector3,endcolor.Vector3)
v.VectorGeomObject = Object.VectorGeomObject(hVector)
If Index > vsize Then Return
vecset.VectorGeomSet = vstart
For i = 1 To Index-1
vecset = vecsetNextSet
Next
vecsetmovement = vector
vecsetStartColor = startcolor
vecsetEndColor = endcolor
End Function

Function VectorStartColor(hVector,Index,startcolor.Vector3)
v.VectorGeomObject = Object.VectorGeomObject(hVector)
If Index > vsize Then Return
vecset.VectorGeomSet = vstart
For i = 1 To Index-1
vecset = vecsetNextSet
Next
vecsetStartColor = startcolor
End Function

Function VectorMovement(hVector,Index,vector.Vector2)
v.VectorGeomObject = Object.VectorGeomObject(hVector)
If Index > vsize Then Return
vecset.VectorGeomSet = vstart
For i = 1 To Index-1
vecset = vecsetNextSet
Next
vecsetmovement = vector
End Function

Function DrawVectors()
Local x = 0
Local y = 0
For v.VectorGeomObject = Each VectorGeomObject
vecset.VectorGeomSet = vstart
x = vpositionx
y = vpositiony
For i = 1 To vsize
Color vecsetStartColorx,vecsetStartColory,vecsetStartColorz
Line x,y,vecsetmovementx+x,vecsetmovementy+y
x = x + vecsetmovementx
y = y + vecsetmovementy
vecset = vecsetNextSet
Next
Next
End Function

and here is an example

Graphics 640,480,32,2
SetBuffer BackBuffer()
xz = CreateVector(320,240)


While Not KeyDown(1)
Cls
;x = x + 3
;If x > 630 Then x = -10
Rect 310,230,20,20
If MouseDown(1)
AppendVector(xz,Vec2(MouseX()-320,MouseY()-240),Vec3(Rand(255),Rand(255),Rand(255)),Vec3(0,0,0))
Delay 100
EndIf
DrawVectors()
Flip
Wend


Comments :


iamdaman13(Posted 1+ years ago)

 Sorry, posted in wrong topic.