Turtle Sample 0.1.0

タートルを動かしてみました。テキストウィンドウにタートルの座標を出力しています。

実行結果

Small Basic オンラインで実行したスクリーンショットを以下に示します。

ソース

TurtleSample.txt

色と角度を変えながらタートルで6つの正方形を描いています。また、 最初の座標と移動後の座標をテキストウィンドウに表示しています。

' Turtle Sample
' Version 0.1.0
' Copyright © 2020 Nonki Takahshi.  The MIT License.
' Last update 2020-08-21

DrawGrid()

Turtle.Speed = 8
WriteTurtlePos()
For j = 1 To 6
    red = Math.GetRandomNumber(128)
    green = Math.GetRandomNumber(128)
    blue = Math.GetRandomNumber(128)
    GraphicsWindow.PenColor = GraphicsWindow.GetColorFromRGB(red, green, blue)
    For i = 1 To 4
        Turtle.Move(150)
        WriteTurtlePos()
        Turtle.Turn(90)
    EndFor
    Turtle.Turn(60)
EndFor

Sub DrawGrid
    gw = GraphicsWindow.Width
    gh = GraphicsWindow.Height
    fn = GraphicsWindow.FontName
    If (fn = "Tahoma") Or (fn = "Segoe UI") Then
        c10 = "#33000000"
        c100 = "#66000000"
    Else    ' for SBO
        c10 = "#00000033"
        c100 = "#00000066"
    EndIf
    For x = 0 To gw Step 10
        If Math.Remainder(x, 100) = 0 Then
            GraphicsWindow.PenColor = c100
        Else
            GraphicsWindow.PenColor = c10
        EndIf
        GraphicsWindow.DrawLine(x, 0, x, gh)
    EndFor
    For y = 0 To gh Step 10
        If Math.Remainder(y, 100) = 0 Then
            GraphicsWindow.PenColor = c100
        Else
            GraphicsWindow.PenColor = c10
        EndIf
        GraphicsWindow.DrawLine(0, y, gw, y)
    EndFor
EndSub

Sub WriteTurtlePos
    pos = Text.Append(Text.Append(Turtle.X, " , "), Turtle.Y) 
    TextWindow.WriteLine(pos)
EndSub

Copyright © 2020 たかはしのんき. All rights reserved.