locked
New programming style for Small Basic Online RRS feed

All replies

  • for sbd+LD only.

    made an visual upgrade: SVH897


    • Edited by Tryhest Wednesday, August 19, 2020 5:28 AM
    Wednesday, August 19, 2020 5:28 AM
  • Hi Nonki,
    why can't I import XXX848-1?

    Wednesday, August 19, 2020 9:07 AM
  • Hi backtothstart, it may be XXG848-1.  But, Small Basic program list server may down...  So, I pasted the program below.  Thanks.

    ' Lady Bug
    ' Version 0.2.1
    ' Copyright © 2020 Nonki Takahashi.  The MIT License.
    ' Last update 2020-08-19
    ' Program ID XXG848-1
    
    Init()
    
    angle = 0
    pw = 6
    pc = "Black"
    bc = "#EE2200"
    width = 260
    height = 300
    x = (gw - width) / 2
    y = (gh - height) / 2
    yb = y
    Ellipse()
    
    ' limbs upper
    pw = 0
    angle = 170
    bc = "Black"
    width = 10
    height = 60
    x = (gw - width) / 2 - 110
    y = yb + 20
    Triangle()
    
    angle = -170
    x = (gw - width) / 2 + 110
    Triangle()
    
    angle = 135
    height = 30
    x = (gw - width) / 2 - 125
    y = yb - 3
    Triangle()
    
    angle = -135
    x = (gw - width) / 2 + 125
    Triangle()
    
    angle = 135
    height = 20
    x = (gw - width) / 2 - 140
    y = yb - 13
    Triangle()
    
    angle = -135
    x = (gw - width) / 2 + 140
    Triangle()
    
    pw = 2
    pc = "Black"
    x = gw / 2 - 146
    y = yb - 8
    x1 = 0
    y1 = 0
    x2 = x1 - 15 * Math.Cos(Math.GetRadians(30))
    y2 = y1 - 15 * Math.Sin(Math.GetRadians(30))
    Line()
    
    x2 = x1 - 15 * Math.Cos(Math.GetRadians(60))
    y2 = y1 - 15 * Math.Sin(Math.GetRadians(60))
    Line()
    
    x = gw / 2 + 146
    x2 = x1 + 15 * Math.Cos(Math.GetRadians(30))
    y2 = y1 - 15 * Math.Sin(Math.GetRadians(30))
    Line()
    
    x2 = x1 + 15 * Math.Cos(Math.GetRadians(60))
    y2 = y1 - 15 * Math.Sin(Math.GetRadians(60))
    Line()
    
    ' limbs middle
    pw = 0
    angle = 40
    height = 70
    x = (gw - width) / 2 - 135
    y = yb + 70
    Triangle()
    
    angle = -40
    x = (gw - width) / 2 + 135
    Triangle()
    
    angle = 60
    height = 20
    x = (gw - width) / 2 - 165
    y = yb + 125
    Triangle()
    
    angle = -60
    x = (gw - width) / 2 + 165
    Triangle()
    
    angle = 60
    x = (gw - width) / 2 - 177
    y = yb + 132
    Triangle()
    
    angle = -60
    x = (gw - width) / 2 + 177
    Triangle()
    
    pw = 2
    x = gw / 2 - 185
    y = yb + 145
    x1 = 0
    y1 = 0
    x2 = x1 - 15 * Math.Cos(Math.GetRadians(15))
    y2 = y1 + 15 * Math.Sin(Math.GetRadians(15))
    Line()
    
    x2 = x1 - 15 * Math.Cos(Math.GetRadians(45))
    y2 = y1 + 15 * Math.Sin(Math.GetRadians(45))
    Line()
    
    x = gw / 2 + 185
    x2 = x1 + 15 * Math.Cos(Math.GetRadians(15))
    y2 = y1 + 15 * Math.Sin(Math.GetRadians(15))
    Line()
    
    x2 = x1 + 15 * Math.Cos(Math.GetRadians(45))
    y2 = y1 + 15 * Math.Sin(Math.GetRadians(45))
    Line()
    
    ' limbs lower
    pw = 0
    angle = -10
    height = 80
    x = (gw - width) / 2 - 115
    y = yb + 200
    Triangle()
    
    angle = 10
    x = (gw - width) / 2 + 115
    Triangle()
    
    angle = 40
    height = 20
    x = (gw - width) / 2 - 113
    y = yb + 275
    Triangle()
    
    angle = -40
    x = (gw - width) / 2 + 113
    Triangle()
    
    angle = 40
    x = (gw - width) / 2 - 122
    y = yb + 285
    Triangle()
    
    angle = -40
    x = (gw - width) / 2 + 122
    Triangle()
    
    pw = 2
    x = gw / 2 - 125
    y = yb + 300
    x1 = 0
    y1 = 0
    x2 = x1 - 15 * Math.Cos(Math.GetRadians(30))
    y2 = y1 + 15 * Math.Sin(Math.GetRadians(30))
    Line()
    
    x2 = x1 - 15 * Math.Cos(Math.GetRadians(60))
    y2 = y1 + 15 * Math.Sin(Math.GetRadians(60))
    Line()
    
    x = gw / 2 + 125
    x2 = x1 + 15 * Math.Cos(Math.GetRadians(30))
    y2 = y1 + 15 * Math.Sin(Math.GetRadians(30))
    Line()
    
    x2 = x1 + 15 * Math.Cos(Math.GetRadians(60))
    y2 = y1 + 15 * Math.Sin(Math.GetRadians(60))
    Line()
    
    ' pattern
    pw = 6
    angle = -45
    bc = "FloralWhite"
    width = 90
    height = 30
    x = (gw - width) / 2 - 70
    y = yb + 30
    Ellipse()
    
    angle = 45
    x = (gw - width) / 2 + 70
    Ellipse()
    
    angle = 0
    pw = 0
    width = 40
    height = 20
    x = gw / 2 - width - 3
    y = yb + 85
    Ellipse()
    
    x = gw / 2 + 3
    Ellipse()
    
    bc = "Black"
    width = 90
    height = 40
    x = (gw - width) / 2
    y = yb
    Ellipse()
    
    width = 150
    height = 65
    x = (gw - width) / 2
    y = yb + 30
    Ellipse()
    
    width = 220
    height = 40
    x = (gw - width) / 2
    y = yb + 55
    Ellipse()
    
    width = 80
    height = 30
    x = gw / 2 - width - 10
    y = yb + 10
    Triangle()
    
    x = gw / 2 + 10
    Triangle()
    
    ' mouth
    bc = "Black"
    width = 50
    height = 30
    x = (gw - width) / 2
    y = yb - 10
    Ellipse()
    
    ' antennae
    pw = 4
    x = gw / 2 - 25
    y = yb
    x1 = 0
    y1 = 0
    x2 = x1 - 15 * Math.Cos(Math.GetRadians(70))
    y2 = y1 - 15 * Math.Sin(Math.GetRadians(70))
    Line()
    
    pw = 2
    x1 = x2
    y1 = y2
    x2 = x1 - 20 * Math.Cos(Math.GetRadians(20))
    y2 = y1 - 20 * Math.Sin(Math.GetRadians(20))
    Line()
    
    x1 = x2
    y1 = y2
    x2 = x1 - 20 * Math.Cos(Math.GetRadians(40))
    y2 = y1 - 20 * Math.Sin(Math.GetRadians(40))
    Line()
    
    pw = 4
    x = gw / 2 + 25
    y = yb
    x1 = 0
    y1 = 0
    x2 = x1 + 15 * Math.Cos(Math.GetRadians(70))
    y2 = y1 - 15 * Math.Sin(Math.GetRadians(70))
    Line()
    
    pw = 2
    x1 = x2
    y1 = y2
    x2 = x1 + 20 * Math.Cos(Math.GetRadians(20))
    y2 = y1 - 20 * Math.Sin(Math.GetRadians(20))
    Line()
    
    x1 = x2
    y1 = y2
    x2 = x1 + 20 * Math.Cos(Math.GetRadians(40))
    y2 = y1 - 20 * Math.Sin(Math.GetRadians(40))
    Line()
    
    bc = "FloralWhite"
    width = 14
    height = 14
    x = gw / 2 - width - 14
    y = yb + 10
    Rectangle()
    
    x = gw / 2 + 14
    Rectangle()
    
    ' eyes
    bc = "#333333"
    width = 15
    height = 17
    x = gw / 2 - width - 30
    y = yb + 10
    Ellipse()
    
    x = gw / 2 + 30
    Ellipse()
    
    pw = 6
    x = gw / 2
    y = yb + 94
    x1 = 0
    y1 = 0
    x2 = 0
    y2 = 300 - 94
    Line()
    
    pw = 0
    bc = "Black"
    width = 60
    height = 50
    x = (gw - width) / 2
    y = yb + 100
    Ellipse()
    
    width = 35
    height = 40
    x = (gw - width) / 2 - 60
    y = yb + 160
    Ellipse()
    
    x = (gw - width) / 2 + 60
    Ellipse()
    
    angle = -45
    width = 30
    height = 40
    x = (gw - width) / 2 - 70
    y = yb + 230
    Ellipse()
    
    angle = 45
    x = (gw - width) / 2 + 70
    Ellipse()
    
    angle = 0
    width = 30
    height = 40
    x = (gw - width) / 2 - 110
    y = yb + 120
    Ellipse()
    
    angle = 0
    x = (gw - width) / 2 + 110
    Ellipse()
    
    Sub Ellipse
      func = "ell"
      SetProperty()
      If sb = "O" Then
        obj = Shapes.AddEllipse(width, height)
        Shapes.Move(obj, x, y)
      Else
        obj = Shapes.AddEllipse(width + pw, height + pw)
        Shapes.Move(obj, x - pw / 2, y - pw / 2)
      EndIf
      SetAngle()
    EndSub
    
    Sub Init
      gw = GraphicsWindow.Width
      gh = GraphicsWindow.Height
      If gw = 624 Then
        sb = "D"  ' Desktop
      ElseIf gw = 640 Then
        sb = "S"  ' Silverlight
      Else
        sb = "O"  ' Online
      EndIf
    EndSub
    
    Sub Line
      func = "line"
      SetProperty()
      obj = Shapes.AddLine(x1, y1, x2, y2)
      Shapes.Move(obj, x, y)
    EndSub
    
    Sub Rectangle
      func = "rect"
      SetProperty()
      If sb = "O" Then
        obj = Shapes.AddRectangle(width, height)
        Shapes.Move(obj, x, y)
      Else
        obj = Shapes.AddRectangle(width + pw, height + pw)
        Shapes.Move(obj, x - pw / 2, y - pw / 2)
      EndIf
      SetAngle()
    EndSub
    
    Sub SetAngle
      If angle <> 0 Then
        Shapes.Rotate(obj, angle)
        If sb = "S" And Text.IsSubText("line|tri", func) Then  ' Silverlight
          If func = "tri" Then
            cx = width / 2
            cy = height / 2
          Else
            cx = (x1 + x2) / 2
            cy = (y1 + y2) / 2
          EndIf
          _angle = Math.GetRadians(angle)
          _cx = cx * Math.Cos(_angle) - cy * Math.Sin(_angle)
          _cy = cx * Math.Sin(_angle) + cy * Math.Cos(_angle)
          _x = x - (_cx - cx)
          _y = y - (_cy - cy)
          Shapes.Move(obj, _x, _y)
        EndIf
      EndIf
    EndSub
    
    Sub SetProperty
      If Text.IsSubText("ell|rect|tri|line", func) Then
        GraphicsWindow.PenWidth = pw
        If 0 < pw Then
          GraphicsWindow.PenColor = pc
        EndIf
      EndIf
      If Text.IsSubText("ell|rect|tri|text", func) Then
        GraphicsWindow.BrushColor = bc
      EndIf
    EndSub
    
    Sub Triangle
      func = "tri"
      SetProperty()
      x1 = width / 2
      y1 = 0
      x2 = 0
      y2 = height
      x3 = width
      y3 = height
      obj = Shapes.AddTriangle(x1, y1, x2, y2, x3, y3)
      Shapes.Move(obj, x, y)
      SetAngle()
    EndSub
    


    Nonki Takahashi

    Monday, September 21, 2020 8:02 AM
  • This is an animation program.

    Screen shot of a program Classic F-1 v0.1.0

    ' Classic F-1
    ' Version 0.2.0
    ' Copyright © 2020 Nonki Takahshi.  The MIT License.
    ' Last update 2020-08-26
      
    carLength = 530
    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
    x1 = 490
    y1 = 320
    x2 = 580
    y2 = 310
    DrawLine()
    GraphicsWindow.BrushColor = "DarkGreen"
    x1 = 290
    y1 = 310
    x2 = 330
    y2 = 290
    x3 = 340
    y3 = 310
    FillTriangle()
    GraphicsWindow.BrushColor = "Black"
    x = 410
    y = 260
    width = 20
    height = 40
    FillEllipse()
    y = y + height
    FillEllipse()
    GraphicsWindow.BrushColor = "Silver"
    x = 420
    y = 255
    width = 10
    height = 10
    FillEllipse()
    y = 260
    height = 60
    FillRectangle()
    GraphicsWindow.BrushColor = "DarkGreen"
    x = 440
    y = 270
    width = 60
    height = 100
    FillEllipse()
    x1 = 430
    y1 = 260
    x2 = 430
    y2 = 350
    x3 = 470
    y3 = 270
    FillTriangle()
     
    ' body
    GraphicsWindow.BrushColor = "DarkGreen"
    x = 50
    y = 310
    width = 480
    height = 80
    FillEllipse()
    x = x + width / 2
    width = 150
    FillRectangle()
    x = 340
    y = 310
    width = 200
    FillEllipse()
     
    ' tire
    xo = 200
    yo = 350
    size = 100
    DrawTire()
    xo = 500
    DrawTire()
     
    ' number
    xo = 370
    yo = 345
    size = 70
    DrawNumber()
     
    Timer.Interval = 200
    Timer.Tick = MoveCar
     
    Sub DrawDriver
        ' helmet
        GraphicsWindow.BrushColor = "Gold"
        x = xo - size / 2
        y = yo - size / 2
        width = size
        height = size
        FillEllipse()
        GraphicsWindow.BrushColor = "DarkGreen"
        x = xo - size * 0.4
        y = yo + size / 2
        width = size * 0.8
        FillEllipse()
        y = yo + size
        height = size / 2
        FillRectangle()
        GraphicsWindow.BrushColor = "Peru"
        ' nose
        x = xo - size * 0.5
        y = yo
        width = size * 0.2
        height = size * 0.2
        FillRectangle()
        x1 = x
        y1 = y
        x2 = xo - size * 0.6
        y2 = yo + size * 0.25
        x3 = xo - size * 0.4
        y3 = y2
        FillTriangle()
        ' face
        x = xo - size * 0.5
        y = yo
        width = size * 0.2
        height = size * 0.5
        FillEllipse()
        x = xo - size * 0.4
        width = size * 0.4
        FillRectangle()
        ' helmet (side)
        GraphicsWindow.BrushColor = "Gold"
        x = xo - size * 0.2
        y = yo - size / 2
        width = size * 0.4
        height = size
        FillEllipse()
        ' 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
        FillTriangle()
    EndSub
     
    Sub DrawEllipse
        ' GraphicsWindow.DrawEllipse(x, y, width, height)
        GraphicsWindow.BrushColor = "Transparent"
        nShp = nShp + 1
        shp[nShp] = Shapes.AddEllipse(width, height)
        Shapes.Move(shp[nShp], x, y)
    EndSub
     
    Sub DrawGrid
        gw = GraphicsWindow.Width
        gh = GraphicsWindow.Height
        fn = GraphicsWindow.FontName
        If (fn = "Tahoma") Or (fn = "Segoe UI") Then
            c10 = "#33000000"
            c100 = "#66000000"
            bc = "#CC000000"
        Else    ' for SBO
            c10 = "#00000033"
            c100 = "#00000066"
            bc = "#000000CC"
        EndIf
        GraphicsWindow.FontName = "Courier New"
        GraphicsWindow.FontSize = 12
        GraphicsWindow.BrushColor = bc
        For x = 0 To gw Step 10
            If Math.Remainder(x, 100) = 0 Then
                GraphicsWindow.PenColor = c100
                GraphicsWindow.DrawText(x + 2, 0, x)
            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
                GraphicsWindow.DrawText(2, y, y)
            Else
                GraphicsWindow.PenColor = c10
            EndIf
            GraphicsWindow.DrawLine(0, y, gw, y)
        EndFor
    EndSub
     
    Sub DrawLine
        ' GraphicsWindow.DrawLine(x1, y1, x2, y2)
        nShp = nShp + 1
        shp[nShp] = Shapes.AddLine(x1, y1, x2, y2)
    EndSub
     
    Sub DrawNumber
        GraphicsWindow.BrushColor = "White"
        x = xo - size / 2
        y = yo - size / 2
        width = size
        height = size
        FillEllipse()
        _size = size * 0.8
        GraphicsWindow.FontName = "Arial"
        GraphicsWindow.FontSize = _size
        GraphicsWindow.BrushColor = "Black"
        x = xo - _size * 0.27
        y = yo - _size * 0.65
        txt = "8"
        DrawText()
    EndSub
     
    Sub DrawText
        ' GraphicsWindow.DrawText(x, y, txt)
        nShp = nShp + 1
        shp[nShp] = Shapes.AddText(txt)
        Shapes.Move(shp[nShp], x, y)
    EndSub
     
    Sub DrawTire
        GraphicsWindow.BrushColor = "#222222"
        x = xo - size / 2
        y = yo - size / 2
        width = size
        height = size
        FillEllipse()
        _size = size * 0.5
        GraphicsWindow.BrushColor = "Gold"
        x = xo - _size / 2
        y = yo - _size / 2
        width = _size
        height = _size
        FillEllipse()
        GraphicsWindow.PenWidth = size * 0.1
        GraphicsWindow.PenColor = "Silver"
        DrawEllipse()
    EndSub
     
    Sub FillEllipse
        ' GraphicsWindow.FillEllipse(x, y, width, height)
        GraphicsWindow.PenWidth = 0
        nShp = nShp + 1
        shp[nShp] = Shapes.AddEllipse(width, height)
        Shapes.Move(shp[nShp], x, y)
    EndSub
     
    Sub FillRectangle
        ' GraphicsWindow.FillRectangle(x, y, width, height)
        GraphicsWindow.PenWidth = 0
        nShp = nShp + 1
        shp[nShp] = Shapes.AddRectangle(width, height)
        Shapes.Move(shp[nShp], x, y)
    EndSub
     
    Sub FillTriangle
        ' GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
        GraphicsWindow.PenWidth = 0
        nShp = nShp + 1
        shp[nShp] = Shapes.AddTriangle(x1, y1, x2, y2, x3, y3)
    EndSub
     
    Sub MoveCar
        If Shapes.GetLeft(shp[18]) < -carLength Then
            dx = gw + carLength
        Else
            dx = -50
        EndIf
        For i = 1 To nShp
            x = Shapes.GetLeft(shp[i]) + dx
            y = Shapes.GetTop(shp[i])
            Shapes.Move(shp[i], x, y)
        EndFor
    EndSub


    Nonki Takahashi


    • Edited by Nonki Takahashi Monday, September 21, 2020 12:49 PM code updated
    Monday, September 21, 2020 12:43 PM
  • Thanks Nonki,

    The ID xxg848-1 and the import / publish function are running again.
    It's a nice thing, otherwise the forum would mainly consist of program code.

    The F1 racing car is also a success, but because of the speed the color should berather "Fer ...." "Firebrick" instead of "Darkgreen".


    Tuesday, September 22, 2020 8:14 AM
  • I wrote a blog and a program for 12th Small Basic anniversary.

    Screen shot of a program Happy 12th Birthday Small Basic!!

    In this program, I use a flag sbd to check the environment is Small Basic Desktop or not.

    GW_FillLinearGradientRectangle() is skipped on Small Basic Online because it's too slow...


    Nonki Takahashi

    Wednesday, October 21, 2020 10:01 AM
  • I rewrote a Halloween program for SBO.  The program ID is GDD325-22.

    Screen shot of a program Halloween Version 2.2


    Nonki Takahashi


    • Edited by Nonki Takahashi Monday, October 26, 2020 2:02 PM program updated
    Monday, October 26, 2020 1:12 PM
  • xtracted candies & added some effects: GDD325-23

    Thursday, October 29, 2020 10:37 AM
  • some CF bats:

    startshape qbats  background { h 222 sat 1 b -.761 }
    rule qbats{    CIRCLE{h 55 sat 1 b .8  s 12.1}bats{}}
    rule bats{ bat{ h 60  sat 1}bats{ r 4 s 0.8 y 1  x 5 h 2}}
    rule bats{ bat{ r 30   h 120  sat 1}bats{ f 90  s 1.1 y -6  x -5 h 6 }}
    rule bats{ bat{ r -48   h 180  sat 1}bats{ f 90  s 1.1 y 3  x 7 h 6 }}
    rule bats 0.1 {} rule bat{ head{ x -0.2 y 0.4}
     body{} leaf{ s 0.4 x 0.3  y -0.4}
     leaf{ s 0.4 x -0.3 y -0.4 flip 90}}
    rule head{ CIRCLE{s 0.8 0.3 r -65}
     CIRCLE{s 0.8 0.3 x 0.4 r 65} CIRCLE{ s 0.6 x 0.2 }
     CIRCLE{ s 0.1 0.05 x .05 sat 1 b 1}
     CIRCLE{ s 0.1 0.05 x 0.35 sat 1 b 1}
     CIRCLE{ s 0.2 0.08 x 0.2 y -0.2 b 1}
     TRIANGLE{ s 0.05 x 0.15 y -0.24 b 1 r 50}
     TRIANGLE{ s 0.05 x 0.25 y -0.24 b 1 r -50}
     CIRCLE{ s 0.2 0.08 x 0.5 y .2 b 1 r 60}
     CIRCLE{ s 0.2 0.08 x -0.1 y .2 b 1 r -60}}
    rule body{ CIRCLE{ y -.6 s 1 1.3}
     TRIANGLE{ x -0.2  y -1.1 s 0.4 r 60}
     TRIANGLE{ x 0.2 y -1.1 s 0.4 r 60}}
    rule leaf{ TRIANGLE{ a -0.4}
     leaf{r 9 s 0.74}
     leaf{r 25 x 2 f 1 s 0.74}}

    Friday, October 30, 2020 11:20 PM