Microsoft Small Basic

Program Listing: KJG712
' Curve Demo
' Copyright © 2015 Nonki Takahashi. The MIT License.
' Version 0.1
'
title = "Curve Demo"
ver = "0.1"
GraphicsWindow.Title = title + " " + ver + " - Quadratic Bezier Curve"
Not = "False=True;True=False;"
nth = "1=first;2=second;3=third;4=fourth;"
Form()
For i = 1 To 3
msg = "Click "+ nth[i] + " point on the screen."
ShowInstruction()
GetPoint()
ShowPoint()
px[i] = x
py[i] = y
EndFor
msg = ""
ShowInstruction()
GraphicsWindow.PenColor = "Gray"
GraphicsWindow.DrawLine(px[1], py[1], px[2], py[2])
GraphicsWindow.DrawLine(px[2], py[2], px[3], py[3])
DrawQuadraticBezier()
Sub Form
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontSize = 20
instruction = Shapes.AddText("")
Shapes.Move(instruction, 10, 10)
GraphicsWindow.MouseDown = OnMouseDown
EndSub
Sub DrawQuadraticBezier
' param px, py - array of three control points for quadratic Bezier curve
For k = 0 To 1 Step 0.05
x1 = px[1] + k * (px[2] - px[1])
y1 = py[1] + k * (py[2] - py[1])
x2 = px[2] + k * (px[3] - px[2])
y2 = py[2] + k * (py[3] - py[2])
GraphicsWindow.PenColor = "Gray"
line = Shapes.AddLine(x1, y1, x2, y2)
x = x1 + k * (x2 - x1)
y = y1 + k * (y2 - y1)
If 0 < k Then
GraphicsWindow.PenColor = "Black"
GraphicsWindow.DrawLine(_x, _y, x, y)
EndIf
_x = x ' last x
_y = y ' last y
msg = "k = " + k
ShowInstruction()
Program.Delay(500)
Shapes.Remove(line)
EndFor
EndSub
Sub GetPoint
' return x, y - clicked point
mouseDown = "False"
While Not[mouseDown]
Program.Delay(300)
EndWhile
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY
EndSub
Sub OnMouseDown
mouseDown = "True"
EndSub
Sub ShowInstruction
' param msg - instruction message to show
Shapes.SetText(instruction, msg)
EndSub
Sub ShowPoint
' param x, y - point to draw
GraphicsWindow.PenColor = "Black"
GraphicsWindow.DrawLine(x - 4, y - 4, x + 4, y + 4)
GraphicsWindow.DrawLine(x - 4, y + 4, x + 4, y - 4)
EndSub