Small Basic: Challenge of the Month – May 2013 (code)


numeros

 

Excellent program!.  Animation and sound
High level programming Nonki. congratulations

Program Listing VXK727 –  http://smallbasic.com/program/?VXK727

……………………………………………………………………………….

‘ 30-second Animation  Edited  ‘Nonki Takahashi
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
dx = gw / 6
dy = gh / 3
fs = 60
x0 = dx – fs / 2
y0 = dy – fs
GraphicsWindow.FontSize = fs
GraphicsWindow.BrushColor = «Orange»
t0 = Clock.ElapsedMilliseconds
For i = 1 To 10
obj[i] = Shapes.AddText(i)
x[i] = x0 + dx * Math.Remainder(i – 1, 5)
y[i] = y0 + dy * Math.Floor((i – 1) / 5)
Shapes.Move(obj[i], gw + fs, y[i])
EndFor
song1 = «O4C4C8C8C4C8C8E4G8G8E4C4D4D8D8D4D8D8O3B4O4D8D8O3B4G4»
song2 = «O4C4C8C8C4C8C8E4G8G8E4C4G4F4E4D4C1»
int = 770
Timer.Interval = int
f = 0
Timer.Tick = OnTick
Sound.PlayMusic(song1)
Sound.PlayMusic(song2)
Sound.PlayMusic(song1)
Sound.PlayMusic(song2)
Sub OnTick
t1 = Clock.ElapsedMilliseconds
f = f + 1
sec = Math.Floor((t1 – t0) / 1000)
GraphicsWindow.Title = sec + «[sec]»
MoveObj()
EndSub
Sub MoveObj
If f <= 3 Then ‘ 1, 2, 3
Shapes.Animate(obj[f], x[f], y[f], int)
ElseIf f = 4 Then
ElseIf f <= 7 Then ‘ 4, 5, 6
Shapes.Animate(obj[f – 1], x[f – 1], y[f – 1], int)
ElseIf f = 8 Then
ElseIf f <= 11 Then ‘ 7, 8, 9
Shapes.Animate(obj[f – 2], x[f – 2], y[f – 2], int)
ElseIf f = 12 Then
ElseIf f = 13 Then ‘ 10
Shapes.Animate(obj[f – 3], x[f – 3], y[f – 3], int)
ElseIf f <= 17 Then
ElseIf f <= 19 Then ‘ 10, 9
Shapes.Animate(obj[28 – f], -fs * 2, y[27 – f], int)
ElseIf f = 20 Then
ElseIf f <= 23 Then ‘ 8, 7, 6
Shapes.Animate(obj[29 – f], -fs * 2, y[29 – f], int)
ElseIf f = 24 Then
ElseIf f <= 27 Then ‘ 5, 4, 3
Shapes.Animate(obj[30 – f], -fs * 2, y[30 – f], int)
ElseIf f = 28 Then
ElseIf f = 29 Then ‘ 2
Shapes.Animate(obj[2], -fs * 2, y[2], int)
ElseIf f <= 37 Then
ElseIf f = 38 Then ‘ 1
Shapes.Animate(obj[1], -fs * 2, y[1], int)
Else
Timer.Pause()
GraphicsWindow.BrushColor = «DimGray»
GraphicsWindow.DrawText(gw / 2 – fs ,gh / 2 – fs, «End»)
EndIf
EndSub

‘ Copyright (c) Microsoft Corporation. All rights reserved.

 

MS Small Basic: files and directories (code)


file3

To learn programming, you must program, program and program.
I took several short exercises of the Curriculum and wrote these into a single program.
This exercise includes objects: ImageList; Network and File
Chapters 2.6 and 3.1 of the Curriculum Tutorial

  1. GraphicsWindow.Title = «Imagen»
  2. rutaImagen = «C:\Users\carlos\Pictures\conchilas.jpg»
  3. Imagen = ImageList.LoadImage(rutaImagen)
  4. GraphicsWindow.Width=ImageList.GetWidthOfImage(rutaImagen)
  5. GraphicsWindow.Height=ImageList.GetHeightOfImage(rutaImagen)
  6. GraphicsWindow.DrawImage(Imagen, 0, 0)
  7. ‘ Fin
  8.  
  9. rutaarchivo1= «http://download.microsoft.com/download/9/0/6/90616372-C4BF-4628-BC82-BD709635220D/Introducing%20Small%20Basic.pdf»
  10. ArchivoDescargado= Network.DownloadFile(rutaarchivo1)
  11. TextWindow.WriteLine(» Archivo descargado:   » + ArchivoDescargado)
  12. ‘ Fin
  13.  
  14. rutaarchivo2= «http://download.microsoft.com/»
  15. ContenidoPaginaWeb = Network.GetWebPageContents(rutaarchivo2)
  16. TextWindow.WriteLine(«Contenido de la pagina:  «)
  17. TextWindow.WriteLine(ContenidoPaginaWeb)
  18. ‘ Fin
  19.  
  20. TextWindow.WriteLine(» El objeto File  «)
  21. rutaarchivo3= «c:\Users\carlos\temp\SubdirectorioTemp\mio.txt»
  22. TextWindow.WriteLine(«Escribir Contenido» + File.WriteLine(rutaarchivo3, 1, «Boca es un gran equipo de futbol»))
  23. TextWindow.WriteLine(«Agregar contenido» + File.AppendContents(rutaarchivo3, » y ademas gano muchos trofeos»))
  24. TextWindow.WriteLine(«Leer contenido=  » + File.ReadContents(rutaarchivo3))
  25. ‘ Fin
  26.  
  27. As Nonki says, to learn programming, program and program.
    I took several short exercises of the Curriculum and wrote these into a single program.
    This exercise includes objects: ImageList; Network
    and File
    Chapters 2.6 and 3.1 of the Curriculum
    Keep in mind that the paths of the files and directories must be such as we have in our physician C:
    Perhaps someone more novice than me, this will serve.
    regards
  28.  
  29.  
  30. rutaArchivoOrigen = «c:\Users\carlos\temp\SubdirectorioTemp\mio.txt»
  31. rutaArchivoDestino = «C:\Users\carlos\temp\SubdirectorioTemp\mover.txt»
  32. rutaDirectorio= «C:\Users\carlos\temp\SubdirectorioTemp»
  33. TextWindow.WriteLine(«Copiar archivo de operacion: » +File.CopyFile(rutaArchivoOrigen,rutaArchivoDestino))
  34. TextWindow.WriteLine(» Archivos en el directorio:  » + File.GetFiles(rutaDirectorio))
  35. ‘ Fin
  36.  
  37. rutaDirectorio1 = «C:\Users\carlos\temp\Small Basic»
  38. TextWindow.WriteLine(«Crear directorio:  » + File.CreateDirectory(rutaDirectorio1))
  39. rutaDirectorio2 = «C:\Users\carlos\temp»
  40. TextWindow.WriteLine(«Directorios:  «+ File.GetDirectories(rutaDirectorio2))
  41. ‘ Fin
  42. TextWindow.WriteLine(» Ultimo error «)
  43. rutaarchivo4 = «c:\Users\carlos\temp\SubdirectorioTemp\mio.txt»
  44. TextWindow.WriteLine(» Operacion WriteLine: » + File.WriteLine(rutaarchivo4, 1, » como esta ? «))
  45. If File.LastError = » » Then
  46.   TextWindow.WriteLine(«La operacion se completo con exito»)
  47. Else
  48.   TextWindow.WriteLine(File.LastError)
  49. EndIf
  50. ‘Fin