Skip to content

Instantly share code, notes, and snippets.

@nonkit
Last active May 18, 2020 13:49
Show Gist options
  • Save nonkit/d2664e4195eda12fe27693181493d3a7 to your computer and use it in GitHub Desktop.
Save nonkit/d2664e4195eda12fe27693181493d3a7 to your computer and use it in GitHub Desktop.
Small Basic Workarounds
Sub SB_LineWorkaround
' Small Basic | line rotate workaround for SBD
' param x, y - coordinate of the position of the line
' param x1, y1 - coordinate of the first point
' param x2, y2 - coordinate of the second point
' param pw - pen width
' param alpha - to rotate [degree]
' return x, y - workaround value for the coordinate
Stack.PushValue("local", x)
Stack.PushValue("local", y)
x = x1 - x2
y = y1 - y2
Math_CartesianToPolar()
y = Stack.PopValue("local")
x = Stack.PopValue("local")
_a = Math.GetRadians(a)
_alpha = Math.GetRadians(a - alpha)
Δx = pw / 4 * (Math.Sin(_alpha) - Math.Sin(_a))
Δy = pw / 4 * (Math.Cos(_alpha) - Math.Cos(_a))
x = x - Δx
y = y - Δy
EndSub
Sub SB_RotateWorkaround
' Small Basic | rotate workaround for Silverlight
' param shp - current shape
' param x, y - original coordinate
' param _alpha - angle [radian]
' returns x, y - workaround coordinate
If shp["func"] = "tri" Then
x1 = -Math.Floor(shp["x3"] / 2)
y1 = -Math.Floor(shp["y3"] / 2)
ElseIf shp["func"] = "line" Then
x1 = -Math.Floor(Math.Abs(shp["x1"] - shp["x2"]) / 2)
y1 = -Math.Floor(Math.Abs(shp["y1"] - shp["y2"]) / 2)
EndIf
ox = x - x1
oy = y - y1
x = x1 * Math.Cos(_alpha) - y1 * Math.Sin(_alpha) + ox
y = x1 * Math.Sin(_alpha) + y1 * Math.Cos(_alpha) + oy
EndSub
Sub SB_Workaround
' Small Basic | workaround for Silverlight / SBD
' return silverlight - "True" if in remote
' return sbd - "True" if Small Basic Desktop
color = GraphicsWindow.GetPixel(0, 0)
sbd = "False"
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
_gw = GraphicsWindow.Width
_gh = GraphicsWindow.Height
If (_gw = 624) And (_gh = 441) Then
sbd = "True"
EndIf
EndIf
EndSub
@nonkit
Copy link
Author

nonkit commented May 16, 2019

Two subroutines are for Sliverlight. One will be added for Small Basic Desktop v1.0 and later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment