Sub Cubic
y = a * x * x * x + b * x * x + c * x + d
EndSub
Sub DrawCubic
' param gxo, gyo - center position in the graphics window
' param a, b - major and minor semi axis
' param n
' param scale
GraphicsWIndow.PenColor = "#00CCCC"
For x = x1 To x2 Step dx
Cubic()
Map()
gx2 = gx
gy2 = gy
If x <> x1 Then
GraphicsWindow.DrawLine(gx1, gy1, gx2, gy2)
EndIf
gx1 = gx2
gy1 = gy2
EndFor
EndSub
Sub DrawGrid
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
gxo = gw / 2
gyo = gh / 2
fn = GraphicsWindow.FontName
If (fn = "Tahoma") Or (fn = "Segoe UI") Then
c10 = "#33009999"
c100 = "#66009999"
bc = "#00CCCC"
Else ' for SBO
c10 = "#00999933"
c100 = "#00999966"
bc = "#00CCCC"
EndIf
GraphicsWindow.FontName = "Courier New"
GraphicsWindow.FontSize = 14
GraphicsWindow.BrushColor = bc
dx = 0.1
dy = -0.1
gx = Math.Remainder(gw / 2, dx * scale) - dx * scale
gy = Math.Remainder(gh / 2, dy * scale)
MapInv()
x1 = x
y1 = y
gx = gw - Math.Remainder(gw / 2, dx * scale) + dx * scale
gy = gh - Math.Remainder(gh / 2, dy * scale)
MapInv()
x2 = x
y2 = y
For x = x1 To x2 Step dx
Map()
rem = Math.Remainder(x, 1)
If rem = 0.0 Then
GraphicsWindow.PenColor = c100
GraphicsWindow.DrawText(gx + 2, gh / 2, x)
Else
GraphicsWindow.PenColor = c10
EndIf
GraphicsWindow.DrawLine(gx, 0, gx, gh)
EndFor
For y = y1 To y2 Step dy
Map()
If Math.Remainder(y, 1) = 0.0 Then
GraphicsWindow.PenColor = c100
If x <> 0 Then
GraphicsWindow.DrawText(gw / 2 + 2, gy, y)
EndIf
Else
GraphicsWindow.PenColor = c10
EndIf
GraphicsWindow.DrawLine(0, gy, gw, gy)
EndFor
EndSub
Sub Expression
expr = "y ="
plus = " "
If a = 1 Then
expr = expr + " x^3"
plus = " + "
ElseIf a = -1 Then
expr = expr + " - x^3"
plus = " + "
ElseIf a <> 0 Then
expr = expr + " " + a + " * x^3"
plus = " + "
EndIf
If b = 1 Then
expr = expr + plus + "x^2"
plus = " + "
ElseIf b = -1 Then
expr = expr + " - x^2"
plus = " + "
ElseIf 0 < b Then
expr = expr + plus + b + " * x^2"
plus = " + "
ElseIf b < 0 Then
expr = expr + " - " + Math.Abs(b) + " * x^2"
plus = " + "
EndIf
If c = 1 Then
expr = expr + plus + "x"
plus = " + "
ElseIf c = -1 Then
expr = expr + " - x"
plus = " + "
ElseIf 0 < c Then
expr = expr + plus + c + " * x"
plus = " + "
ElseIf c < 0 Then
expr = expr + " - " + Math.Abs(c) + " * x"
plus = " + "
EndIf
If 0 < d Then
expr = expr + plus + d
ElseIf d < 0 Then
expr = expr + " - " + Math.Abs(d)
EndIf
If (a = 0) And (b = 0) And (c = 0) And (d = 0) Then
expr = expr + " 0"
EndIf
EndSub
Sub Map
gx = gxo + scale * x
gy = gyo - scale * y
EndSub
Sub MapInv
x = (gx - gxo) / scale
y = -(gy - gyo) / scale
EndSub
Sub MovePoints
Shapes.SetText(shT, "k = " + k)
x12 = (1 - k) * x1 + k * x2
y12 = (1 - k) * y1 + k * y2
x = x12
y = y12
Map()
Shapes.Move(shP[1], gx - size / 2, gy - size / 2)
x23 = (1 - k) * x2 + k * x3
y23 = (1 - k) * y2 + k * y3
x = x23
y = y23
Map()
Shapes.Move(shP[2], gx - size / 2, gy - size / 2)
x34 = (1 - k) * x3 + k * x4
y34 = (1 - k) * y3 + k * y4
x = x34
y = y34
Map()
Shapes.Move(shP[3], gx - size / 2, gy - size / 2)
x13 = (1 - k) * x12 + k * x23
y13 = (1 - k) * y12 + k * y23
x = x13
y = y13
Map()
Shapes.Move(shP[4], gx - size / 2, gy - size / 2)
x24 = (1 - k) * x23 + k * x34
y24 = (1 - k) * y23 + k * y34
x = x24
y = y24
Map()
Shapes.Move(shP[5], gx - size / 2, gy - size / 2)
x = (1 - k) * x13 + k * x24
y = (1 - k) * y13 + k * y24
Map()
Shapes.Move(shP[6], gx - size / 2, gy - size / 2)
EndSub