Small Basic中文站-快乐编程

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 14936|回复: 14

SmallBasic第3方扩展库应用实例

[复制链接]
发表于 2010-6-16 19:40:52 | 显示全部楼层 |阅读模式
2017年1月更新:
最新的扩展库  可以查阅:https://blogs.msdn.microsoft.com ... extensions-gallery/
Small Basic第三方扩展的使用方法:http://www.smallbasic.cn/thread-1203-1-1.html


SmallBasic第3方扩展库应用实例
首先你需要导入第3方扩展库SmallBasicFun.dll,导入的方法很简单,压缩包中有快乐编程-鱼二六提供的使用说明书,赶紧体验一下导入扩展库是怎么回事吧
     本地下载地址: SmallBasicFun.rar (222.8 KB, 下载次数: 4978)
回复

使用道具 举报

 楼主| 发表于 2010-6-16 21:50:55 | 显示全部楼层

代码:

  1. Tortoise.Show()
  2. Tortoise.SetSpeed(10)
  3. Tortoise.SetPenColor(Colors.Blue)
  4. For i = 1 To 4
  5. Tortoise.Move(50)
  6. Tortoise.Turn(90)
  7. EndFor
复制代码

回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-6-16 21:55:02 | 显示全部楼层
回复 鱼二六 的帖子


    代码:
  1. ' Turn the background to black
  2. 'Start the branch length to 60
  3. 'DrawBranch (recipe below)
  4. GraphicsWindow.BackgroundColor = "black"
  5. 'GraphicsWindow.DrawImage(Flickr.GetRandomPicture("grass"),0,0)
  6. Turtle.Speed = 9
  7. length =60
  8. DrawBranch()

  9. Sub DrawBranch
  10. PickColor()
  11. Turtle.Move(length)
  12. DrawLowerBranch()
  13. PickColor()
  14. Turtle.Move(-length)
  15. EndSub
  16. 'Recipe for DrawBranch
  17. 'PickColorForBranchLength (recipe below)
  18. 'Move the turtle the branch length
  19. 'DrawLowerBranch (recipe below)
  20. 'PickColorForBranchLength (recipe below)
  21. 'Move the Turtle backwards the length of the branch
  22. Sub PickColor
  23. Color[10] = "Lime"
  24. Color[20] = "ForestGreen"
  25. Color[30] = "DarkGreen"
  26. Color[40] = "Olive"
  27. Color[50] = "Sienna"
  28. Color[60] = "SaddleBrown"
  29. 'set the pen color to the Color for the branch length
  30. GraphicsWindow.PenColor = Color[length]
  31. EndSub
  32. Sub DrawLowerBranch

  33. If (length > 0) then
  34. length = length - 10
  35. Turtle.Turn(30)
  36. DrawBranch()
  37. Turtle.Turn(-60)
  38. DrawBranch()
  39. Turtle.Turn(30)
  40. length = length + 10
  41. EndIf


  42. EndSub
  43. 'Recipe for DrawLowerBranch
  44. 'Decrease the branch length by 10
  45. 'if the branch length is more than 0 then
  46. ' turn the turtle 30 degrees
  47. 'DrawBranch (recipe above)
  48. ' turn the turtle back 60 degrees
  49. 'DrawBranch (recipe above)
  50. 'turn the turtle 30 degrees
  51. 'Increase the branch length by 10



  52. 'Recipe for PickColorForBranchLength
  53. 'Color #10 is Lime
  54. 'Color #20 is ForestGreen
  55. 'Color #30 is DarkGreen
  56. 'Color #40 is Olive
  57. 'Color #50 is Sienna
  58. 'Color #60 is SaddleBrown
  59. 'set the pen color to the Color for the branch length

复制代码

回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-6-16 21:57:49 | 显示全部楼层
回复 鱼二六 的帖子


   
注 : 这个代码和效果图是相反的,海龟是从外往内绘制图像的。
代码:
  1. c = Colors.Violet
  2. Tortoise.SetSpeed(10)
  3. For i = 50 To 1 Step -2
  4. c = Colors.Darken(c)
  5. Tortoise.SetPenColor(c)
  6. Tortoise.Move(i)
  7. Tortoise.TurnRight()
  8. EndFor
复制代码

回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-6-16 22:07:28 | 显示全部楼层
回复 鱼二六 的帖子


  效果图:  这个代码实现了9种效果,效果图显示了最后一种,也是其中最复杂的效果
1.png
代码:
  1. originalX = Turtle.X
  2. originalY = Turtle.Y
  3. While( 2 = 2)
  4. times = 0
  5. simpleSquare()
  6. variation1Sides()
  7. variation2Sides()
  8. variation3Colors()
  9. variation4Width()
  10. variation5Large()
  11. variation6Small()
  12. variation7VariableWidths()
  13. variation8VariableLength()
  14. variation9TimesAround()
  15. Program.Delay(7000)
  16. EndWhile

  17. Sub variation9TimesAround
  18. text[t] = "Variation - Number Of Rotations"
  19. length = 3
  20. width = 1.5
  21. sides = 30
  22. circles = 3
  23. square()
  24. EndSub
  25. Sub variation8VariableLength
  26. text[t] = "Variation - VariableLengths"
  27. length = 5
  28. lengthVariable = "true"
  29. sides = 15
  30. square()
  31. EndSub

  32. Sub variation7VariableWidths
  33. text[7] = "Variation - VariableWidths"
  34. width = 2
  35. widthVariable = "true"
  36. square()
  37. EndSub

  38. Sub variation6Small
  39. text[6] = "Variation - Size (Small)"
  40. length = 25
  41. square()
  42. EndSub
  43. Sub variation5Large
  44. text[5] = "Variation - Size (Big)"
  45. length = 100
  46. square()
  47. EndSub

  48. Sub variation4Width
  49. text[4] = "Variation - Width (thick)"
  50. width = 5
  51. square()
  52. EndSub
  53. Sub variation3Colors
  54. text[3] = "Variation - Colors"
  55. random = "true"

  56. square()

  57. EndSub
  58. Sub variation1Sides
  59. text[1] = "Variation - # of Sides (3)"
  60. sides = 3
  61. square()

  62. EndSub
  63. Sub variation2Sides
  64. text[2] = "Variation - # of Sides (8)"
  65. sides = 8
  66. square()

  67. EndSub
  68. Sub simpleSquare
  69. text[0] = "Simple Square"
  70. sides = 4
  71. length = 50
  72. lengthBase = 1
  73. widthBase = 1
  74. width = 2
  75. random = "false"
  76. widthVariable = "false"
  77. lengthVariable = "false"
  78. circles = 1
  79. square()
  80. endsub
  81. Sub square
  82. GraphicsWindow.Clear()
  83. Turtle.Show()
  84. Turtle.X = originalX
  85. Turtle.Y = originalY
  86. drawText()
  87. For i = 1 To sides
  88. setColor()
  89. If (widthVariable = "true") Then
  90. widthBase = i
  91. EndIf
  92. GraphicsWindow.PenWidth = width * widthBase
  93. If (lengthVariable = "true") Then
  94. lengthBase = i
  95. EndIf
  96. Turtle.Move(length* lengthBase)
  97. Turtle.Turn(360*circles/sides)
  98. EndFor
  99. Program.Delay(2000)
  100. EndSub
  101. Sub drawText
  102. For t = 0 To times
  103. GraphicsWindow.DrawText( 30, 30 + 20 * t,text[t])
  104. endfor

  105. times = times + 1
  106. endsub
  107. sub setColor
  108. If (random = "true") Then
  109. GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()
  110. Else
  111. GraphicsWindow.PenColor = "blue"
  112. EndIf
  113. EndSub
复制代码

回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-6-16 22:13:16 | 显示全部楼层
回复 鱼二六 的帖子


    从1-100之间随机取一个数字出来,然后让你猜他是多少,根据你猜测的回答是高了 还是低了,在规定的次数-8次内猜测出来正确的数字即获胜。
代码:
  1. 'choose a random number between 1 and 100
  2. number = Math.GetRandomNumber(100)
  3. 'do the following 8 times
  4. For i = 1 To 8
  5. 'ask for a guess.
  6. guess = MessageBox.AskForInput("Please enter a guess between 1 and 100")
  7. 'if the guess is correct
  8. If (guess = number) Then
  9. 'play a bell
  10. Sound.PlayBellRing()
  11. 'tell the user that they won the game and exit
  12. MessageBox.ShowMessage("You won!")
  13. Program.End()
  14. 'if the guess is too high
  15. ElseIf (guess > number) Then
  16. 'say too high
  17. MessageBox.ShowMessage("Too high!")
  18. 'if the guess is too low
  19. ElseIf (guess < number) Then
  20. 'say too low
  21. MessageBox.ShowMessage("Too low!")
  22. EndIf
  23. EndFor
  24. 'if after 8 times they haven't guessed correctly, tell them they've lost the game
  25. MessageBox.ShowMessage("You are a loser, and the number was " + number)
复制代码

回复 支持 反对

使用道具 举报

发表于 2011-2-25 10:47:40 | 显示全部楼层
本帖最后由 wbwchina 于 2011-2-25 10:48 编辑

  1. Tortoise.Show()
  2. Tortoise.SetSpeed(10)
  3. Tortoise.SetPenColor(Colors.Blue)
  4. For i = 1 To 4
  5. Tortoise.Move(50)
  6. Tortoise.Turn(90)
  7. EndFor
复制代码
应改为以下代码,在smallbsic才能正常
  1. Turtle.Show()
  2. Turtle.Move(0)
  3. GraphicsWindow.PenColor="Blue"
  4. Turtle.PenDown()
  5. For i = 1 To 4
  6. Turtle.Move(50)
  7. Turtle.Turn(90)
  8. EndFor
复制代码

回复 支持 反对

使用道具 举报

发表于 2011-7-18 11:59:14 | 显示全部楼层
为何上面代码复制进去无法运行呢
回复 支持 反对

使用道具 举报

发表于 2012-5-12 00:33:27 | 显示全部楼层
鱼二六 发表于 2010-6-16 22:13
回复 鱼二六 的帖子


MessageBox对象在Small Basic 版本1.0中已经没有啦
回复 支持 反对

使用道具 举报

发表于 2012-12-24 08:40:42 | 显示全部楼层
为何不能下载
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|Small Basic中文站-快乐编程 ( 闽ICP备09051788号 |

GMT+8, 2017-8-22 13:29 , Processed in 0.287401 second(s), 9 queries , File On.

Powered by Discuz! X3.3

快速回复 返回顶部 返回列表