Showing posts with label small-basic. Show all posts
Showing posts with label small-basic. Show all posts

Sunday 11 May 2014

Pelukis1

GraphicsWindow.MouseDown = catat
GraphicsWindow.MouseMove = gambar
Sub catat
  x1 = GraphicsWindow.MouseX
  x2 = GraphicsWindow.MouseY
EndSub

Sub gambar
  If Mouse.IsLeftButtonDown Then
    GraphicsWindow.DrawLine(x1,x2,GraphicsWindow.mousex,GraphicsWindow.mousey)
  EndIf
EndSub

Saturday 10 May 2014

Bola Asik (aplikasi game menggunakan Smallbasic)

Copas code berikut ini ke editor bahasa program Smallbasic kamu dan jalankan (run/F5):

bola1 = Shapes.AddEllipse(25,25)
GraphicsWindow.BrushColor = "Red"
bola2 = Shapes.AddEllipse(25,25)
GraphicsWindow.BrushColor = "Green"
bola3 = Shapes.AddEllipse(25,25)
awal:
shapes.animate(bola1, Math.GetRandomNumber(500), Math.GetRandomNumber(500),1000)
shapes.animate(bola2, Math.GetRandomNumber(500), Math.GetRandomNumber(500),1000)
shapes.animate(bola3, Math.GetRandomNumber(500), Math.GetRandomNumber(500),1000)
Program.Delay(1000)
Goto awal

Wednesday 19 February 2014

Basic of reading text file



How about .csv file? Is it OK?
OK
textwindow.writeline(File.ReadContents("c:/circle.csv"))

Tuesday 11 February 2014

Dasar pengacakan kata

textwindow.WriteLine(Text.GetCharacterCode("a"))

Output: 97

Formula
1. Misal: A -> B

Mobil untuk Natanael


Halo Bere! Ini mobil untuk bere. Jangan dipakai buat ngebut ya (hehehe). Padahal memang tidak diprogram untuk ngebut (Speed-nya dilambatin).

Untuk sederhananya begini dulu yah. Peluk cium dari Tulang, Tulang Jonathan, Opung Boru dan Opung Doli..

NB: Untuk bisa melihat animasinya, perlu instal software Microsoft Silverlight dulu (itu kayak Adobe Flash gitu, supaya bisa berinteraksi). Coba dicari di google pasti ketemu, unduhan Microsoft silverlight ya... Yoss gitu dulu...
 

Monday 10 February 2014

Hujan Bola 2


GraphicsWindow.MouseDown = mousedown GraphicsWindow.MouseUp = mouseup GraphicsWindow.Show() i = 0 Sub mousedown s[i] = Shapes.AddEllipse(25,25) Shapes.Move(s[i], GraphicsWindow.mousex - 10, GraphicsWindow.mousey - 10) i = i + 1 EndSub Sub mouseup shapes.animate(s[i-1], Shapes.Getleft(s[i - 1]), GraphicsWindow.height - 25, 1000) EndSub




Sunday 9 February 2014

Tracing the problems of asyncrhonization

aloha = Shapes.AddEllipse(10,10)
For i = 0 To 100
Shapes.Animate(aloha, i * Math.GetRandomNumber(10), i, 1000)
Program.Delay(1000)
'Shapes.Animate(aloha, 100, 200, 1000)
EndFor



aloha = Shapes.AddEllipse(10,10)

For j = 0 To 100
  x[j] = j
EndFor


For i = 0 To 100
Shapes.Animate(aloha, x[i], x[i], 1000)
Program.Delay(1000)
'Shapes.Animate(aloha, 100, 200, 1000)
EndFor

Saturday 8 February 2014

Case-x Value of i never end

GraphicsWindow.MouseDown = md
i = 0
loopz:
TextWindow.WriteLine(i)
Program.Delay(100)
i = i + 1
Goto loopz


Sub md
  For j = 0 To10
    TextWindow.WriteLine("yoyo hakusho")
    Program.Delay(1000)
  EndFor
EndSub

Just paste above code and run, klik your mouse on the graphic screen

Above versus below

GraphicsWindow.MouseDown = md
i = 0
loopz:
TextWindow.WriteLine("i " + i + " j :" + j)
Program.Delay(100)
i = i + 1
Goto loopz


Sub md
  For j = 0 To i
    TextWindow.WriteLine("yoyo hakusho")
    Program.Delay(1000)
  EndFor
EndSub

Finally, added: a = i,  value of i should rest in peace now, in variable a (Loop don't use variable i anymore)

GraphicsWindow.MouseDown = md
i = 0
aloha = Shapes.AddEllipse(10,10)
loopz:
TextWindow.WriteLine("i " + i + " j :" + j + Clock.time)
Program.Delay(1000)
i = i + 1
Goto loopz


Sub md
  a = i
  For j = 0 To i
    TextWindow.WriteLine("yoyo hakusho" + Clock.time)
    Program.Delay(1000)
  EndFor
EndSub

So again, the conclusion: the sub is obey what he told to do.

Friday 7 February 2014

Hujan Bola









GraphicsWindow.MouseDown = mousedown GraphicsWindow.MouseUp = mouseup i = 0 Sub mousedown x[i] = GraphicsWindow.mousex y[i] = GraphicsWindow.mousey i = i + 1 EndSub Sub mouseup anak = Shapes.AddEllipse(10,10) Shapes.animate(anak, x[i - 1], y[i - 1],1000) EndSub

Monday 3 February 2014

Detecting mouse movement with endless loop (goto)

start:
GraphicsWindow.Show()
x1 = GraphicsWindow.MouseX
y1 = GraphicsWindow.MouseY
Program.Delay(10)
x2 = GraphicsWindow.MouseX
y2 = GraphicsWindow.MouseY

if x1 <> x2 and y1 <> y2 Then
  TextWindow.WriteLine("mouse is moving")
Else
  TextWindow.WriteLine("mouse is still")
 
EndIf

Goto start

Friday 31 January 2014

ketika dua event berjibaku

gw pengen discover: apakah suatu eksekusi suatu event bisa di interupsi oleh eksekusi event lain?

GraphicsWindow.Show()
GraphicsWindow.MouseDown = mousedown
GraphicsWindow.KeyDown = keydown

Sub keydown
  TextWindow.WriteLine("aloha")
EndSub

Sub mousedown
  TextWindow.BackgroundColor = "red"
  For i = 0 To 100000
    TextWindow.WriteLine(i)
  EndFor
EndSub

diatas kmu bisa lihat bahwa ketika gw klik mouse diatas jendela grafik, program akan mulai menampilkan angka di jendela text (textwindow), angka ini gw perbanyak dari 0 sampai seratus ribu, untuk memperlama waktu eksekusi sub procedure mousedown. Ditengah eksekusi sub procedure mousedown ini, misalkan ketika angka baru sampai angka 10000, 10001, gw tekan sembarang tombol pada keyboard, dengan tujuan mengintrupsi proses perlakuan sub procedure mousedown diatas, tapi gw tidak melihat adanya tampilan kata aloha, yang gw lihat hanya penerusan angka-angka tersebut.

Setelah angka 100000 lah gw baru melihat kata aloha diatas. Dari pengujian ini gw bisa melihat bahwa yang pengintrupsian subprocedure tidak bisa dilakuka.

Gambar biar gw jangan dibilang hoax:





Controlling the opacity of a shape using mousemove event

a = Shapes.AddEllipse(100,100)
GraphicsWindow.MouseMove = mousemove

Sub mousemove
  If GraphicsWindow.MouseX <= 100 Then
    Shapes.SetOpacity(a, 100)
  Else
    Shapes.SetOpacity(a,50)
    endif
EndSub

It used to be:
a = Shapes.AddEllipse(100,100)
Shapes.SetOpacity(a,50)
GraphicsWindow.MouseMove = mousemove

Sub mousemove
  If GraphicsWindow.MouseX <= 100 Then
    Shapes.SetOpacity(a, 100)
  Else
    Shapes.SetOpacity(a,50)
    endif
EndSub

Final:

Thursday 30 January 2014

Menggambar bentuk dengan small basic

1. Menggambar elips dan bulat

a.  Menggambar elips
- dengan menggunakan parent shape
Shapes.AddEllipse(100,50)

Output:

- dengan menggunakan parent graphicswindow
GraphicsWindow.DrawEllipse(0,0,100,50)

Output:

b. Menggambar bulat
- dengan menggunakan parent shape
Shapes.AddEllipse(100,100)

Output:

- dengan menggunakan parent graphicswindow
GraphicsWindow.DrawEllipse(0,0,100,100)

Output:

2. Menggambar petak (rectangle)

- dengan menggunakan parent shape
Shapes.AddRectangle(100,100)

Output:

- dengan menggunakan parent graphicswindow
GraphicsWindow.DrawRectangle(0,0,100,100)

Output:

3. Menggambar segitiga

 - dengan menggunakan parent shape
Shapes.AddTriangle(0,100,50,0,100,100)

Output:


- dengan menggunakan parent graphicswindow
GraphicsWindow.DrawTriangle(0,100,50,0,100,100)

Output:




Kesimpulan

- Kamu lihat bahwa menggambar bulat dan menggambar elips sama-sama menggunakan perintah elips?
- Kamu lihat bahwa menggambar dengan graphic window tidak mengarsir dan menggambar dengan shape selalu mengarsir?


Tambahan sedikit:

GraphicsWindow.BrushColor = "Black"
GraphicsWindow.PenColor = "red"
Shapes.AddEllipse(100,100)

Output:

 




Wednesday 29 January 2014

My-first add/subs click program

val = Controls.AddTextBox(0,0)
Controls.SetSize(val, 100, 50)
add = Controls.AddButton("+",300,0)
subs = Controls.AddButton("-",400,0)

Controls.ButtonClicked = process

Sub process
  If Controls.LastClickedButton = add then
    val1 = Controls.GetTextBoxText(val)
    val1 = val1 + 1
    Controls.SetTextBoxText(val, val1)
  Else
    val1 = Controls.GetTextBoxText(val)
    val1 = val1 - 1
    Controls.SetTextBoxText(val, val1)
  endif
 
EndSub

Tuesday 28 January 2014

File Input and output LAB

Properties:
file.lasterror(

Operations:
file.readcontents
file.writecontents
file.readline
file.writeline
file.insertline
file.appendcontents
file.copyfile
file.deletefile
file.createdirectory
file.deletedirectory
file.getfiles
file.getdirectories
file.gettemporaryfilepath
file.getsettingsfilepath()

Bahan-bahan:
1. Sediakan sebuah file text kosong
2. Sediakan kata-kata yang akan dimasukkan

Remark:
1. jika file tidak ditemukan akan membuat file baru:
2. linefile dimulai dari angka 1
3

Write a program that performs the following steps:
  • Requests a suitable name for a directory from the user, and creates a directory of that name.
  • Downloads a file from the network, and copies it to the new directory.
  • Displays the contents of the downloaded file in the text window.
  • Accepts additional content from the user, and adds it to the file.
  • Displays the final content from the file in the text window.

File lab

1. Read a file on a disk
How?


Monday 27 January 2014

Plain

a = Shapes.AddEllipse(100,100)
GraphicsWindow.BrushColor = "red"
b = Shapes.AddEllipse(100,100)
GraphicsWindow.BrushColor = "Green"
c = Shapes.AddEllipse(100,100)
start:
Shapes.Move(a, 500, 0)
Shapes.Move(b,0,100)
Shapes.Move (c, 250,0)
progdel()
Shapes.Move(a, 400, 0)
Shapes.Move(b,100,100)
Shapes.Move (c, 250,100)
progdel()
Shapes.Move(a, 300, 0)
Shapes.Move(b,200,100)
Shapes.Move (c, 250,200)
progdel()
Shapes.Move(a, 200, 0)
Shapes.Move(b, 300,100)
Shapes.Move (c, 250,300)
progdel()
Shapes.Move(a, 100, 0)
Shapes.Move(b, 400,100)
Shapes.Move (c, 250,400)
progdel()
Shapes.Move(a,0,0)
Shapes.Move(b, 500,100)
Shapes.Move (c, 250,500)
progdel()
Shapes.Move(a,100,0)
Shapes.Move(b, 400,100)
Shapes.Move (c, 250,400)
progdel()
Shapes.Move(a,200,0)
Shapes.Move(b, 300,100)
Shapes.Move (c, 250,300)
progdel()
Shapes.Move(a,300,0)
Shapes.Move(b, 200,100)
Shapes.Move (c, 250,200)
progdel()
Shapes.Move(a,400,0)
Shapes.Move(b, 100,100)
Shapes.Move (c, 250,100)
progdel()
Shapes.Move(a,500,0)
Shapes.Move(b, 0,100)
Shapes.Move (c, 250,0)
progdel()
Goto start
Sub progdel
  Program.Delay(1000)
EndSub


Sunday 26 January 2014

Programan bergerak (animasi) dan small basic

1. Garis bergerak lurus
for i = 1 to 10000
x1 = i
y1 = 0
x2 = x1 + 1
y2 = 0
graphicswindow.drawline(x1, y1, x2, y2)
Program.Delay(100)
endfor

atau

For i = 0 To 1000
if i = 0 Then
  x1 = i
Else
  x1 = i * 10
EndIf
y1 = 10
x2 = x1 + 10
y2 = 10
Shapes.AddLine(x1, y1, x2, y2)
Program.Delay(10)
EndFor

2. Shape bergerak
- shape rectangle bergerak


- shape triangle bergerak



3.