Main CodeThe supershape equation is an extension of the both the equation of the sphere and ellipse
(x / a)^2 + (y / b)^2 = r^2
Code: Select all
#include once "FBGfx.bi"
#include once "MouseObject.bi"
Using FB
Const xres = 800
Const yres = 600
Const midx = xres / 2
Const midy = yres / 2
Const As Single TwoPi = Atn(1.0f) * 8.0f
Screenres xres, yres, 32
Dim Shared As MouseObject Mouse
Function Overlap(x0 As Integer, y0 As Integer, w0 As Integer, h0 As Integer, cx As Integer, cy As Integer) As Integer
Dim As Integer testX = cX
Dim As Integer testY = cY
If TestX < x0 Then TestX = x0
If TestX > (x0 + w0) Then TestX = (x0 + w0)
If TestY < y0 Then Testy = y0
If TestY > (y0 + h0) Then Testy = (y0 + h0)
If ((cX - TestX) * (cX - TestX) + (cY - TestY) * (cY - TestY)) < 1 Then Return True Else Return False
End Function
Function TextWidth(text As String) As Integer
Return Len(text) * 8
End Function
Function TextHeight(text As String) As Integer
Return 8
End Function
Type TSlider
x As Single
y As Single
w As Single
h As Single
minvalue As Single
maxvalue As Single
text As String
slidervalue As Single
returnvalue As Single
mode As Integer = 1
retInt As Integer
Declare Sub Make(x As Single, y As Single, w As Single, h As Single, minvalue As Single, maxvalue As Single, text As String, defaultvalue As Single, returnInt As Integer)
Declare Function Update() As Single
End Type
Sub TSlider.Make(x As Single, y As Single, w As Single, h As Single, minvalue As Single, maxvalue As Single, text As String, defaultvalue As Single, returnInt As Integer = 0)
this.x = x
this.y = y
this.w = w
this.h = h
this.minvalue = minvalue
this.maxvalue = maxvalue
this.text = text
this.returnvalue = defaultvalue
this.returnvalue = defaultvalue
this.retInt = returnInt
this.slidervalue = (this.w * (this.returnvalue - this.minvalue)) / (this.maxvalue - this.minvalue)
End Sub
Function TSlider.Update() As Single
Static As Integer staticmy
If (Mouse.Hold(SC_LBUTTON) = False And Mouse.Hold(SC_RBUTTON) = False) Then staticmy = Mouse.GetY
If Mouse.Hold(SC_LBUTTON) Or Mouse.Hold(SC_RBUTTON) Then
If Overlap(this.x - 10, this.y + 10, this.w + 20, this.h - 10, Mouse.GetX, staticmy) Then
If Mouse.Hold(SC_LBUTTON) Then this.mode = 1
If Mouse.Hold(SC_RBUTTON) Then this.mode = 2
this.slidervalue = Mouse.GetX - this.x
End If
End If
If this.slidervalue < 0 Then this.slidervalue = 0
If this.slidervalue > this.w Then this.slidervalue = this.w
Line(this.x - 1, this.y + 9)-(this.x + this.w + 1, this.y + this.h + 1),, b
If this.mode = 1 Then
this.returnvalue = ((this.slidervalue / this.w) * (this.maxvalue - this.minvalue)) + this.minvalue
If this.retInt = 1 Then this.returnvalue = Int(this.returnvalue)
Draw String (this.x, this.y), this.text & ": " & this.returnvalue
Line(this.x, this.y + 10)-(this.x + this.slidervalue, this.y + this.h), Rgb(50, 50, 50), bf
Return this.returnvalue
Else
this.returnvalue = (this.slidervalue / this.w)
Draw String (this.x, this.y), this.text & ": " & this.returnvalue & " (1 / " & Int(1 / this.returnvalue) & ")"
Line(this.x, this.y + 10)-(this.x + this.slidervalue, this.y + this.h), Rgb(150, 50, 50), bf
Return this.returnvalue
End If
End Function
Sub Eval(m As Single, n1 As Single, n2 As Single, n3 As Single, phi As Single, a As Single, b As Single, Byref x As Single, Byref y As Single, radius As Single)
Dim As Single mPhi = (m * phi) / 4.0f
Dim As Single t1 = Cos(mPhi) / a
Dim As Single t2 = Sin(mPhi) / b
t1 = Abs(t1) ^ n2
t2 = Abs(t2) ^ n3
Dim As Single r = (t1 + t2) ^ (1 / n1)
If Abs(r) = 0 Then
x = 0
y = 0
Else
r = (1 / r) * radius
x = r * Cos(phi)
y = r * Sin(phi)
End If
End Sub
Dim As Single val_m = 1, val_n1 = 10.5, val_n2 = 10.5, val_n3 = 10.5, val_a = 1, val_b = 1, val_radius = 64, val_pointNum = 50
Dim As Tslider gui_m, gui_n1, gui_n2, gui_n3, gui_a, gui_b, gui_radius, gui_pointNum
gui_m.Make (10, 10 + (30 * 0), 200, 20, 0, 20, "m", val_m, 1)
gui_n1.Make (10, 10 + (30 * 1), 200, 20, 0, 60, "n1", val_n1, 1)
gui_n2.Make (10, 10 + (30 * 2), 200, 20, 0, 60, "n2", val_n2, 1)
gui_n3.Make (10, 10 + (30 * 3), 200, 20, 0, 60, "n3", val_n3, 1)
gui_a.Make (10, 10 + (30 * 4), 200, 20, 0, 2, "a", val_a, 0)
gui_b.Make (10, 10 + (30 * 5), 200, 20, 0, 2, "b", val_b, 0)
gui_radius.Make (10, 10 + (30 * 6), 200, 20, 10, 300, "Radius", val_radius, 1)
gui_pointNum.Make (10, 10 + (30 * 7), 200, 20, 1, 256, "Point Num", val_pointNum, 1)
Do
Mouse.Update
Screenlock
Cls
val_m = gui_m.Update
val_n1 = gui_n1.Update
val_n2 = gui_n2.Update
val_n3 = gui_n3.Update
val_a = gui_a.Update
val_b = gui_b.Update
val_radius = gui_radius.Update
val_pointNum = gui_pointNum.Update
Dim As Single xArray(val_pointNum + 1)
Dim As Single yArray(val_pointNum + 1)
For i As Integer = 0 To val_pointNum
Dim As Single phi = i * (TwoPi / val_pointNum)
Eval(val_m, val_n1, val_n2, val_n3, phi, val_a, val_b, xArray(i), yArray(i), val_radius)
xArray(i) += midx
yArray(i) += midy
Next
For i As Integer = 0 To val_pointNum - 1
Line(xArray(i), yArray(i))-(xArray(i + 1), yArray(i + 1))
Next
Screenunlock
Sleep 1
Loop Until Multikey(SC_ESCAPE)
Code: Select all
#ifndef False
#define False 0
#endif
#ifndef True
#define True NOT False
#endif
#if __FB_LANG__ = "fb"
Namespace FB
#Endif
Const As Integer SC_LBUTTON = 1
Const As Integer SC_RBUTTON = 2
Const As Integer SC_MBUTTON = 4
#If __FB_LANG__ = "fb"
End Namespace
#endif
Type MouseObject
x As Integer
y As Integer
z As Integer
buttons As Integer
scroll As Integer
old_x As Integer
old_y As Integer
old_z As Integer
old_buttons As Integer
Declare Function Pressed(procInput As Integer) As Integer
Declare Function Released(procInput As Integer) As Integer
Declare Function Hold(procInput As Integer) As Integer
Declare Function DeltaX() As Integer
Declare Function DeltaY() As Integer
Declare Function GetX() As Integer
Declare Function GetY() As Integer
Declare Function GetScroll() As Integer
Declare Function GetScrollClamped(mMin As Integer, mMax As Integer) As Integer
Declare Function GetScrollWrapped(mMin As Integer, mMax As Integer) As Integer
Declare Function GetAngle() As Single
Declare Function GetAngleFrom(inpX As Integer, inpY As Integer) As Single
Declare Sub SetPosition(inpX As Integer, inpY As Integer)
Declare Sub SetClip(mybool As Integer)
Declare Sub SetVisible(mybool As Integer)
Declare Sub Move(inpX As Integer, inpY As Integer)
Declare Sub Update()
End Type
Sub MouseObject.Update()
this.old_buttons = this.buttons
this.old_x = this.x
this.old_y = this.y
this.old_z = this.z
Getmouse this.x, this.y, this.z, this.buttons
If this.x = -1 And this.y = -1 And this.buttons = -1 And this.z = -1 Then
this.buttons = this.old_buttons
this.x = this.old_x
this.y = this.old_y
this.z = this.old_z
End If
this.scroll = this.z
End Sub
Function MouseObject.Pressed(procInput As Integer) As Integer
If (this.buttons And procInput) And Not(this.old_buttons And procInput) Then Return True
Return False
End Function
Function MouseObject.Released(procInput As Integer) As Integer
If Not(this.buttons And procInput) And (this.old_buttons And procInput) Then Return True
Return False
End Function
Function MouseObject.Hold(procInput As Integer) As Integer
If (this.buttons And procInput) And (this.old_buttons And procInput) Then Return True
Return False
End Function
Function MouseObject.DeltaX() As Integer
Return this.x - this.old_x
End Function
Function MouseObject.DeltaY() As Integer
Return this.y - this.old_y
End Function
Function MouseObject.GetX() As Integer
Return this.x
End Function
Function MouseObject.GetY() As Integer
Return this.y
End Function
Function MouseObject.GetScroll() As Integer
Return this.scroll
End Function
Function MouseObject.GetScrollClamped(mMin As Integer, mMax As Integer) As Integer
Dim As Integer toReturn = this.scroll
If mMin > mMax Then Swap mMin, mMax
If toReturn < mMin Then
Return mMin
Elseif toReturn > mMax Then
Return mMax
End If
Return toReturn
End Function
Function MouseObject.GetScrollWrapped(mMin As Integer, mMax As Integer) As Integer
If mMin > mMax Then Swap mMin, mMax
Dim As Integer toReturn = this.scroll
Dim As Integer diff = (mMax - mMin) + 1
If toReturn > mMax Then
While toReturn > mMax
toReturn -= diff
Wend
Elseif toReturn < mMin Then
While toReturn < mMin
toReturn += diff
Wend
End If
Return toReturn
End Function
Function MouseObject.GetAngle() As Single
Dim As Single dx = this.x - this.old_x
Dim As Single dy = this.y - this.old_y
Return Atan2(dy, dx)
End Function
Function MouseObject.GetAngleFrom(inpX As Integer, inpY As Integer) As Single
Dim As Single dx = this.x - inpX
Dim As Single dy = this.y - inpY
Return Atan2(dy, dx)
End Function
Sub MouseObject.Move(inpX As Integer, inpY As Integer)
Setmouse this.x + inpX, this.y + inpY
End Sub
Sub MouseObject.SetPosition(inpX As Integer, inpY As Integer)
Setmouse inpX, inpY
End Sub
Sub MouseObject.SetClip(mybool As Integer)
If mybool = True Then Setmouse ,,, 1 Else Setmouse ,,, 0
End Sub
Sub MouseObject.SetVisible(mybool As Integer)
If mybool = True Then Setmouse ,, 1 Else Setmouse ,, 0
End Sub