Microsoft Small Basic

Program Listing:
Embed this in your website
' mahreen miangul Smiley Animation DecEmber 2018
' Blink and Move added by Nonki Takahashi
' A, S, D, F and Arrow keys to move Smiley

GraphicsWindow.top = 0
GraphicsWindow.left = 0
GraphicsWindow.Title = "mahreen miangul | Use A, S, D, F and Arrow keys"
gw = 1288
gh = 666
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor="skyblue"

'----------------- Draw Hill-------------------------------------------------------------------------------------------------------
' Hill
GraphicsWindow.brushColor = "tan"
colorHill = GraphicsWindow.BrushColor
GraphicsWindow.fillEllipse(-88,505,620,288)
GraphicsWindow.fillEllipse(211,388,622,366)
GraphicsWindow.fillEllipse(211,388,1888,666)

GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "Black"
mask = Shapes.AddRectangle(1288, 666)
Shapes.SetOpacity(mask, 0)

'Makesprite()
SPRITE_init()         ' <--------- all shape data is input here!!
add_shapes()          ' <--------- all shapes are added here!!
balloons[2] = "1=10;2=11;3=12;"
opBl[2] = "1=100;2=100;"
eyes[2] = "1=6;2=7;"
StartBlink()
keys[2][1] = "Left=←;Up=↑;Down=↓;Right=→;"
keys[2][2] = "A=←;S=↑;D=↓;F=→;"
helloSpots[2][1] = "x1=930;y1=120;x2=970;y2=160;"
helloSpots[2][2] = "x1=390;y1=120;x2=430;y2=160;"
dx = "←=-20;→=20;"
dy = "↑=-20;↓=20;"
StartKeyInput()
For _op = 1 To 80
  Program.Delay(500)
  Shapes.SetOpacity(mask, _op)
  If _op = 30 Then
    snowing = "True"
  EndIf
EndFor
Program.Delay(2000)
For i = 1 To 90
  Program.Delay(500)
  dir = "←"
  _iSp = 1
  _iRp = 1
  MoveShapes()
EndFor

Sub add_shapes
  For M=1 to Array.GetItemCount(s)      ' 5 types shapes // Kong , trees , House , Apple , sprite
    For N=1 to Array.GetItemCount(s[M]) ' repeat number //Kong=1 , trees =12 , House=1 , Apple=16 , sprite=1
      ss=s[M][N]      ' scale
      _shx=shx[M][N]  ' base point _X
      _shY=shY[M][N]  ' base point _Y
      _shape=shape[M] ' temporary shape data
      NMB=M+":"+N     ' shape index
      for i=1 To Array.GetItemCount(_shape)
        GraphicsWindow.PenWidth = _shape[i]["pw"]
        GraphicsWindow.BrushColor = _shape[i]["bc"]
        GraphicsWindow.penColor = _shape[i]["pc"]
        If _shape[i]["func"]="ell" Then
          shp[NMB][i] = Shapes.AddEllipse(_shape[i]["width"]*ss, _shape[i]["height"]*ss)
        ElseIf _shape[i]["func"]="rect" Then
          shp[NMB][i] = Shapes.AddRectangle(_shape[i]["width"]*ss, _shape[i]["height"]*ss)
        ElseIf _shape[i]["func"]="tri" Then
          shp[NMB][i] = Shapes.Addtriangle(_shape[i]["x1"]*ss, _shape[i]["y1"]*ss,_shape[i]["x2"]*ss, _shape[i]["y2"]*ss, _shape[i]["x3"]*ss, _shape[i]["y3"]*ss)
        ElseIf shape[N][i]["func"]="line" Then
          shp[NMB][i] = Shapes.Addline(_shape[i]["x1"]*ss, _shape[i]["y1"]*ss,_shape[i]["x2"]*ss, _shape[i]["y2"]*ss)
        ElseIf _shape[i]["func"]="text" Then
          GraphicsWindow.FontName = _shape[i]["fn"]
          GraphicsWindow.FontSize = _shape[i]["fs"]
          shp[NMB][i] = Shapes.AddText(_shape[i]["text"])
        EndIf
        Shapes.Animate(shp[NMB][i], _shape[i]["x"]*ss+_shX, _shape[i]["y"]*ss+_shY, 500)
        Shapes.Rotate(shp[NMB][i], _Shape[i]["angle"])
      EndFor
    Endfor
  Endfor
EndSub

' Smiley//mahreen miangul
Sub SPRITE_init
  ' Santaclaus
  s[1] = "1=1;"
  shX[1] = "1=1300;"  ' x offset
  shY[1] = "1=10;"    ' y offset
  shape[1][1] = "func=ell;x=35;y=114;width=104;height=50;bc=#814A27;pw=0;"
  shape[1][2] = "func=rect;x=44;y=150;width=9;height=65;bc=#814A27;pw=0;"
  shape[1][3] = "func=rect;x=57;y=150;width=9;height=65;bc=#814A27;pw=0;"
  shape[1][4] = "func=rect;x=107;y=150;width=9;height=65;bc=#814A27;pw=0;"
  shape[1][5] = "func=rect;x=121;y=150;width=9;height=65;bc=#814A27;pw=0;"
  shape[1][6] = "func=rect;x=40;y=85;width=24;height=47;bc=#814A27;pw=0;"
  shape[1][7] = "func=ell;x=131;y=116;width=18;height=20;bc=#814A27;pw=0;"
  shape[1][8] = "func=rect;x=51;y=43;width=7;height=30;bc=#A7842A;pw=0;"
  shape[1][9] = "func=rect;x=61;y=50;width=7;height=30;bc=#A7842A;pw=0;"
  shape[1][10] = "func=rect;x=41;y=26;width=7;height=30;angle=297;bc=#A7842A;pw=0;"
  shape[1][11] = "func=rect;x=71;y=30;width=7;height=30;angle=55;bc=#A7842A;pw=0;"
  shape[1][12] = "func=rect;x=29;y=6;width=7;height=30;angle=352;bc=#A7842A;pw=0;"
  shape[1][13] = "func=rect;x=83;y=10;width=7;height=30;angle=7;bc=#A7842A;pw=0;"
  shape[1][14] = "func=rect;x=38;y=116;width=27;height=7;angle=349;bc=#000000;pw=0;"
  shape[1][15] = "func=ell;x=28;y=117;width=16;height=16;bc=#C3AB6F;pw=0;"
  shape[1][16] = "func=rect;x=165;y=205;width=241;height=9;bc=#8C8C8C;pw=0;"
  shape[1][17] = "func=rect;x=185;y=185;width=9;height=23;bc=#8C8C8C;pw=0;"
  shape[1][18] = "func=rect;x=377;y=185;width=9;height=23;bc=#8C8C8C;pw=0;"
  shape[1][19] = "func=rect;x=156;y=191;width=9;height=23;angle=317;bc=#8C8C8C;pw=0;"
  shape[1][20] = "func=rect;x=69;y=114;width=9;height=52;angle=355;bc=#000000;pw=0;"
  shape[1][21] = "func=rect;x=73;y=143;width=111;height=9;bc=#000000;pw=0;"
  shape[1][22] = "func=ell;x=299;y=75;width=92;height=88;bc=#EBE4D0;pw=0;"
  shape[1][23] = "func=ell;x=239;y=87;width=84;height=88;bc=#9D1010;pw=0;"
  shape[1][24] = "func=ell;x=258;y=51;width=49;height=57;bc=#EBE4D0;pw=0;"
  shape[1][25] = "func=rect;x=266;y=66;width=33;height=21;bc=#DBB9A9;pw=0;"
  shape[1][26] = "func=ell;x=275;y=79;width=13;height=13;bc=#9D1010;pw=0;"
  shape[1][27] = "func=rect;x=271;y=47;width=32;height=14;angle=13;bc=#9D1010;pw=0;"
  shape[1][28] = "func=rect;x=274;y=43;width=36;height=13;bc=#9D1010;pw=0;"
  shape[1][29] = "func=ell;x=306;y=37;width=18;height=20;bc=#EBE4D0;pw=0;"
  shape[1][30] = "func=rect;x=264;y=89;width=10;height=45;angle=333;bc=#E2D8BB;pw=0;"
  shape[1][31] = "func=rect;x=283;y=89;width=10;height=63;angle=33;bc=#EBE4D0;pw=0;"
  shape[1][32] = "func=rect;x=184;y=143;width=202;height=43;bc=#563A1A;pw=0;"
  shape[1][33] = "func=ell;x=210;y=65;width=24;height=24;bc=#EBE4D0;pw=0;"
  shape[1][34] = "func=rect;x=215;y=83;width=26;height=34;angle=347;bc=#9D1010;pw=0;"
  shape[1][35] = "func=rect;x=225;y=90;width=26;height=34;angle=272;bc=#9D1010;pw=0;"
  shape[1][36] = "func=ell;x=16;y=71;width=56;height=30;bc=#814A27;pw=0;"
  shape[1][37] = "func=ell;x=41;y=75;width=12;height=12;bc=#000000;pw=0;"
  shape[1][38] = "func=ell;x=7;y=79;width=14;height=14;bc=#9D1010;pw=0;"
  shape[1][39] = "func=ell;x=64;y=72;width=24;height=12;angle=340;bc=#814A27;pw=0;"
  shape[1][40] = "func=rect;x=259;y=71;width=17;height=4;angle=350;bc=#EBE4D0;pw=;"
  shape[1][41] = "func=rect;x=288;y=71;width=17;height=4;angle=18;bc=#EBE4D0;pw=;"
  shape[1][42] = "func=rect;x=98;y=19;width=7;height=30;angle=81;bc=#A7842A;pw=0;"
  shape[1][43] = "func=rect;x=17;y=16;width=7;height=30;angle=287;bc=#A7842A;pw=0;"
  shape[1][44] = "func=rect;x=115;y=5;width=7;height=30;angle=16;bc=#A7842A;pw=0;"
  shape[1][45] = "func=rect;x=0;y=0;width=7;height=30;angle=338;bc=#A7842A;pw=0;"
  shape[1][46] = "func=ell;x=289;y=81;width=21;height=22;bc=#EBE4D0;pw=0;"
  shape[1][47] = "func=ell;x=255;y=83;width=21;height=22;bc=#EBE4D0;pw=0;"
  shape[1][48] = "func=ell;x=265;y=71;width=14;height=14;bc=#FFFFFF;pc=#000000;pw=2;"
  shape[1][49] = "func=ell;x=285;y=71;width=14;height=14;bc=#FFFFFF;pc=#000000;pw=2;"
  shape[1][50] = "func=line;x=277;y=77;x1=0;y1=0;x2=10;y2=0;pc=#000000;pw=2;"
  ' Smikey
  s[2]   ="1=1.7;2=1.7;"
  shX[2] ="1=-800;2=-800;"
  shY[2] ="1=-1188;2=-1188;"
  shape[2][1] = "func=ell;x=800;y=800;width=120;height=120;bc=orangered;pw=0;"
  shape[2][2] = "func=ell;x=813;y=805;width=95;height=95;bc=greenyellow;pw=0;"
  shape[2][3] = "func=ell;x=827;y=807;width=65;height=35;bc=white;pw=0;"
  shape[2][4] = "func=rect;x=822;y=833;width=25;height=4;angle=10;bc=red;pw=0;"
  shape[2][5] = "func=rect;x=877;y=844;width=25;height=4;angle=10;bc=red;pw=0;"
  shape[2][6] = "func=ell;x=822;y=822;width=25;height=25;bc=red;pw=0;"
  shape[2][7] = "func=ell;x=877;y=833;width=25;height=25;bc=red;pw=0;"
  shape[2][8] = "func=ell;x=833;y=855;width=40;height=35;angle=30;bc=red;pw=0;"
  shape[2][9] = "func=rect;x=838;y=850;width=40;height=20;angle=20;bc=greenyellow;pw=0;"
  shape[2][10] = "func=ell;x=850;y=730;width=120;height=60;bc=white;pw=0;"
  shape[2][11] = "func=tri;x=920;y=775;x1=10;y1=0;x2=0;y2=30;x3=20;y3=30;angle=-150;bc=white;pw=0;"
  shape[2][12] = "func=text;x=878;y=747;text=Hello!;fn=Trebuchet MS;fs=40;bc=black;"
EndSub

Sub StartBlink
  Timer.Interval = 100
  Timer.Tick = OnTick
EndSub

Sub OnTick
  ' work t - times
  t = t + 1
  If Math.Remainder(t, 30) = 0 Then
    open = "False"
    Blink()
  ElseIf Math.Remainder(t, 30) = 5 Then
    open = "True"
    Blink()
  EndIf
  If opBl <> "" Then
    nSp = Array.GetItemCount(opBl)
    xSp = Array.GetAllIndices(opBl)
    For _j = 1 To nSp
      iSp = xSp[_j]
      _opBl = opBl[iSp]
      nRp = Array.GetItemCount(_opBl)
      xRp = Array.GetAllIndices(_opBl)
      For _i = 1 To nRp
        iRp = xRp[_i]
        If (_opBl[iRp] = 100) Then
          Balloon()
          _opBl[iRp] = 99
          opBl[iSp] = _opBl
          bt[iRp][iRp] = t + 10
        ElseIf (0 < _opBl[iRp]) And (bt[iRp][iRp] < t) Then
          _opBl[iRp] = ""
          opBl[iSp] = _opBl
          Balloon()
        EndIf
      EndFor
    EndFor
  EndIf
  If snowing Then
    Timer.Pause()
    If Math.Remainder(t, 10) = 0 Then
      iSnow = iSnow + 1
      GraphicsWindow.PenWidth = 0
      GraphicsWindow.BrushColor = "White"
      snow[iSnow] = Shapes.AddEllipse(6, 6)
      Shapes.Move(snow[iSnow], Math.GetRandomNumber(gw), 0)
    EndIf
    nSnow = Array.GetItemCount(snow)
    xSnow = Array.GetAllIndices(snow)
    For _i = 1 To nSnow
      sign = (Math.GetRandomNumber(2) - 1.5) * 2
      _x = Shapes.GetLeft(snow[xSnow[_i]]) + sign * 2
      _y = Shapes.GetTop(snow[xSnow[_i]]) + 2
      Shapes.Move(snow[xSnow[_i]], _x, _y)
      If gh < _y Then
        Shapes.Remove(snow[xSnow[_i]])
        snow[xSnow[_i]] = ""
      ElseIf GraphicsWindow.GetPixel(_x, _y) = colorHill Then
        GraphicsWindow.BrushColor = "White"
        GraphicsWindow.FillEllipse(_x, _y, 6, 6)
        snow[xSnow[_i]] = ""
      EndIf
    EndFor
    Timer.Resume()
  EndIf
EndSub

Sub Blink
  ' work iSp - splite
  ' work iRp - repeat
  ' work iEy - eye
  For iSp = 1 To Array.GetItemCount(s)
    _eyes = eyes[iSp]
    For iRp = 1 To Array.GetItemCount(s[iSp])
      _shp = shp[iSp + ":" + iRp]
      For iEy = 1 To Array.GetItemCount(_eyes)
        _eye = _eyes[iEy]
        If open Then
          Shapes.ShowShape(_shp[_eye])
        Else
          Shapes.HideShape(_shp[_eye])
        EndIf
      EndFor
    EndFor
  EndFor
EndSub

Sub StartKeyInput
  GraphicsWindow.KeyDown = OnKeyDown
EndSub

Sub OnKeyDown
  ' work _iSp - splite
  ' work _iRp - repeat
  key = GraphicsWindow.LastKey
  For _iSp = 1 To Array.GetItemCount(s)
    For _iRp = 1 To Array.GetItemCount(s[_iSp])
      If Array.ContainsIndex(keys[_iSp][_iRp], key) Then
        dir = keys[_iSp][_iRp][key]
        MoveShapes()
        x1 = helloSpots[_iSp][_iRp]["x1"]
        y1 = helloSpots[_iSp][_iRp]["y1"]
        x2 = helloSpots[_iSp][_iRp]["x2"]
        y2 = helloSpots[_iSp][_iRp]["y2"]
        If (x1 <= x) And (x <= x2) And (y1 <= y) And (y <= y2) Then
          opBl[_iSp][_iRp] = 100
        EndIf
      EndIf
    EndFor
  EndFor
EndSub

Sub MoveShapes
  ' param dir - direction
  ' param _iSp - splite
  ' param _iRp - repeat
  ' work _iSh - shape
  __shp = shp[_iSp + ":" + _iRp]
  For _iSh = 1 To Array.GetItemCount(__shp)
    x = Shapes.GetLeft(__shp[_iSh]) + dx[dir]
    y = Shapes.GetTop(__shp[_iSh]) + dy[dir]
    Shapes.Move(__shp[_iSh], x, y)
  EndFor
EndSub

Sub Balloon
  ' param iSp - splite
  ' param iRp - repeat
  ' param opBl[iSp][iRp] - opacity
  nSh = Array.GetItemCount(balloons[iSp])
  xSh = Array.GetAllIndices(balloons[iSp])
  _shp = shp[iSp + ":" + iRp]
  For iSh = 1 To nSh
    Shapes.SetOpacity(_shp[balloons[iSp][xSh[iSh]]], opBl[iSp][iRp])
  EndFor
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.