Classic F-1 0.1.0

クラシック F-1 レーシングカーを描くに当たり、 ドライバーが細かいのでまず先にドライバーを作りました。 その後、そのドライバーのコードをクラシック F-1 レーシングカーのコードに埋め込みました。

実行結果

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

ソース

F-1Driver.txt

DrawDriver というサブルーチンが本体ですが、パラメーターとして中心の座標 (xo, yo) とドライバーヘルメットのサイズ size を渡しています。サブルーチンの中の座標、 サイズはこれらのパラメーターを元に計算しています。

' F-1 Driver
' Version 0.1.0
' Copyright © 2020 Nonki Takahshi.  The MIT License.
' Last update 2020-08-23
 
DrawGrid()

xo = 300
yo = 200
size = 200
DrawDriver()

Sub DrawDriver
    ' helmet
    GraphicsWindow.BrushColor = "Gold"
    GraphicsWindow.FillEllipse(xo - size / 2, yo - size / 2, size, size)
    GraphicsWindow.BrushColor = "DarkGreen"
    GraphicsWindow.FillEllipse(xo - size * 0.4, yo + size / 2, size * 0.8, size)
    GraphicsWindow.FillRectangle(xo - size * 0.4, yo + size, size * 0.8, size / 2)
    GraphicsWindow.BrushColor = "Peru"
    ' nose
    x1 = xo - size * 0.5
    y1 = yo
    GraphicsWindow.FillRectangle(x1, y1, size * 0.2, size * 0.2)
    x2 = xo - size * 0.6
    y2 = yo + size * 0.25
    x3 = xo - size * 0.4
    y3 = y2
    ' face
    GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
    x = xo - size * 0.5
    y = yo
    width = size * 0.2
    height = size * 0.5
    GraphicsWindow.FillEllipse(x, y, width, height)
    x = xo - size * 0.4
    width = size * 0.4
    GraphicsWindow.FillRectangle(x, y, width, height)
    ' helmet (side)
    GraphicsWindow.BrushColor = "Gold"
    GraphicsWindow.FillEllipse(xo - size * 0.2, yo - size / 2, size * 0.4, size)
    ' helmet peak
    GraphicsWindow.BrushColor = "Yellow"
    x1 = xo - size * 0.45
    y1 = yo - size * 0.2
    x2 = xo - size * 0.7
    y2 = yo
    x3 = xo - size * 0.1
    y3 = yo
    GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
EndSub

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

ClassicF-1.txt

上記の DrawDriver を組み込んでレーシングカー全体を描画しています。

' Classic F-1
' Version 0.1.0
' Copyright © 2020 Nonki Takahshi.  The MIT License.
' Last update 2020-08-23
 
DrawGrid()

' ground
GraphicsWindow.BrushColor = "Gray"
GraphicsWindow.FillRectangle(0, 400, gw, gh - 400)

' driver
xo = 380
yo = 280
size = 50
DrawDriver()

' cockpit
GraphicsWindow.PenColor = "Silver"
GraphicsWindow.PenWidth = 20
GraphicsWIndow.DrawLine(490, 320, 580, 310)
GraphicsWindow.BrushColor = "DarkGreen"
x1 = 290
y1 = 310
x2 = 330
y2 = 290
x3 = 340
y3 = 310
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
GraphicsWindow.BrushColor = "Black"
x = 410
y = 260
width = 20
height = 40
GraphicsWindow.FillEllipse(x, y, width, height)
GraphicsWindow.FillEllipse(x, y + height, width, height)
GraphicsWindow.BrushColor = "Silver"
x = 420
y = 255
width = 10
GraphicsWindow.FillEllipse(x, y, width, width)
y = 260
height = 60
GraphicsWindow.FillRectangle(x, y, width, height)
GraphicsWindow.BrushColor = "DarkGreen"
x = 440
y = 270
width = 60
height = 100
GraphicsWindow.FillEllipse(x, y, width, height)
x1 = 430
y1 = 260
x2 = 430
y2 = 350
x3 = 470
y3 = 270
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)

' body
GraphicsWindow.BrushColor = "DarkGreen"
x = 50
y = 310
width = 480
height = 80
GraphicsWindow.FillEllipse(x, y, width, height)
x = x + width / 2
width = 150
GraphicsWindow.FillRectangle(x, y, width, height)
x = 340
y = 310
width = 200
GraphicsWindow.FillEllipse(x, y, width, height)

' tire
xo = 200
yo = 350
size = 100
DrawTire()
xo = 500
DrawTire()

' number
xo = 370
yo = 345
size = 70
DrawNumber()

Sub DrawDriver
    ' helmet
    GraphicsWindow.BrushColor = "Gold"
    GraphicsWindow.FillEllipse(xo - size / 2, yo - size / 2, size, size)
    GraphicsWindow.BrushColor = "DarkGreen"
    GraphicsWindow.FillEllipse(xo - size * 0.4, yo + size / 2, size * 0.8, size)
    GraphicsWindow.FillRectangle(xo - size * 0.4, yo + size, size * 0.8, size / 2)
    GraphicsWindow.BrushColor = "Peru"
    ' nose
    x1 = xo - size * 0.5
    y1 = yo
    GraphicsWindow.FillRectangle(x1, y1, size * 0.2, size * 0.2)
    x2 = xo - size * 0.6
    y2 = yo + size * 0.25
    x3 = xo - size * 0.4
    y3 = y2
    ' face
    GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
    x = xo - size * 0.5
    y = yo
    width = size * 0.2
    height = size * 0.5
    GraphicsWindow.FillEllipse(x, y, width, height)
    x = xo - size * 0.4
    width = size * 0.4
    GraphicsWindow.FillRectangle(x, y, width, height)
    ' helmet (side)
    GraphicsWindow.BrushColor = "Gold"
    GraphicsWindow.FillEllipse(xo - size * 0.2, yo - size / 2, size * 0.4, size)
    ' helmet peak
    GraphicsWindow.BrushColor = "Yellow"
    x1 = xo - size * 0.45
    y1 = yo - size * 0.2
    x2 = xo - size * 0.7
    y2 = yo
    x3 = xo - size * 0.1
    y3 = yo
    GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
EndSub

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 DrawNumber
    GraphicsWindow.BrushColor = "White"
    GraphicsWindow.FillEllipse(xo - size / 2, yo - size / 2, size, size)
    _size = size * 0.8
    GraphicsWindow.FontSize = _size
    GraphicsWindow.BrushColor = "Black"
    GraphicsWindow.DrawText(xo - _size * 0.3, yo - size / 2, "8")
EndSub

Sub DrawTire
    GraphicsWindow.BrushColor = "#222222"
    GraphicsWindow.FillEllipse(xo - size / 2, yo - size / 2, size, size)
    _size = size * 0.5
    GraphicsWindow.BrushColor = "Gold"
    GraphicsWindow.FillEllipse(xo - _size / 2, yo - _size / 2, _size, _size)
    GraphicsWindow.PenWidth = size * 0.1
    GraphicsWindow.PenColor = "Silver"
    GraphicsWindow.DrawEllipse(xo - _size / 2, yo - _size / 2, _size, _size)
EndSub

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