Small Basic中文站-快乐编程

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2953|回复: 2

借鉴·烟花源代码

[复制链接]
发表于 2013-2-7 17:21:08 | 显示全部楼层 |阅读模式

  1. 'Paddle game extended a bit with fireworks for winners
  2. ' set GraphicsWindow window size
  3. gh=600
  4. gw=800
  5. GraphicsWindow.Width = gw
  6. GraphicsWindow.Height = gh
  7. GraphicsWindow.BackgroundColor="Black"
  8. GraphicsWindow.FontSize=15

  9. 'Set a random set of stars, the randon RGB are designed to be dimish 'off white'
  10. For i = 1 To gh
  11.   x=math.GetRandomNumber(gw)
  12.   y=math.GetRandomNumber(gh)
  13.   size=math.GetRandomNumber(8)
  14.   R=100+math.GetRandomNumber(55)
  15.   G=100+math.GetRandomNumber(55)
  16.   B=100+math.GetRandomNumber(55)
  17.   GraphicsWindow.BrushColor=GraphicsWindow.GetColorFromRGB(R,G,B)
  18.   GraphicsWindow.FillEllipse(x,y,size,size)
  19. EndFor
  20. 'loop for each firework
  21. next:
  22. 'Update firework count
  23. count = count+1
  24. 'Set a random start and end for rocket
  25. startx=math.GetRandomNumber(gw)
  26. starty=gh
  27. endx=50+math.GetRandomNumber(gw-100)
  28. endy=20+math.GetRandomNumber(gh/2)
  29. 'Use a random number to set the colour - these are designed to be bright near primary
  30. 'Red, Green, Blue, Cyan, Yellow, Magenta
  31. rand = math.GetRandomNumber(6)
  32. If (rand=1) Then
  33.   R=254
  34.   G=math.GetRandomNumber(100)
  35.   B=0
  36. EndIf
  37. If (rand=2) Then
  38.   G=254
  39.   B=math.GetRandomNumber(100)
  40.   R=0
  41. EndIf
  42. If (rand=3) Then
  43.   B=254
  44.   R=math.GetRandomNumber(100)
  45.   G=0
  46. EndIf
  47. If (rand=4) Then
  48.   R=254
  49.   G=254
  50.   B=math.GetRandomNumber(100)
  51. EndIf
  52. If (rand=5) Then
  53.   G=254
  54.   B=254
  55.   R=math.GetRandomNumber(100)
  56. EndIf
  57. If (rand=6) Then
  58.   B=254
  59.   R=254
  60.   G=math.GetRandomNumber(100)
  61. EndIf
  62. 'Set our firework color and create a rocket (ball)
  63. GraphicsWindow.PenColor = GraphicsWindow.GetColorFromRGB(R,G,B)
  64. GraphicsWindow.BrushColor = GraphicsWindow.GetColorFromRGB(R,G,B)
  65. ball = Shapes.AddEllipse(15,15)
  66. 'Draw the rocket trail from start to end
  67. For i = 1 To 100
  68.   x=startx+i/100*(endx-startx)
  69.   y=starty+i/100*(endy-starty)
  70.   Program.Delay(5)
  71.   Shapes.Move(ball, x, y)
  72. endfor
  73. Shapes.Remove(ball)
  74. 'Draw the firework burst
  75. 'nlayer is the number of concentric layers
  76. 'nangle is the number of angular segments to the burst
  77. nlayer = 50
  78. nangle = 20
  79. 'Random gravity for burst
  80. grav = Math.GetRandomNumber(5)/nlayer
  81. 'Draw with the firework colour(k=1), then overdraw in black (k=2) - this leaves a trace outline which may be an artifact, but looks ok
  82. For k = 1 To 2
  83.   If (k = 2) then
  84.     'Overdraw in black - also do a bang
  85.     GraphicsWindow.PenColor = "Black"
  86.     GraphicsWindow.BrushColor = "Black"
  87.     'Add you own bang!
  88. ' Sound.PlayAndWait("C:\Users\Public\Documents\SmallBasic\bang_2.wav")
  89. ' Sound.Stop("C:\Users\Public\Documents\SmallBasic\bang_2.wav")
  90.   EndIf
  91.   'A little text to show score above firework
  92.   GraphicsWindow.DrawText(endx-50,endy-100,"Happy new year! ")
  93.   'Loop over concentric layers
  94.   For i = 1 To nlayer
  95.     'Add a delay and set the radius(dist) and size of the burst points
  96.     'These scalings are an attempt to make it OK with different nlayer - not guaranteed!
  97.     Program.Delay(500/nlayer)
  98.     dist = 200/nlayer*i
  99.     size = 1+0.2*nlayer/math.SquareRoot(i)
  100.     ' Loop over angle segments
  101.     For j = 1 To nangle
  102.       'Calculate coordinates of burst point, including the gravity term
  103.       x=endx+dist*math.Cos(j/nangle*2*3.14)
  104.       y=endy+dist*math.Sin(j/nangle*2*3.14)+grav*i*i
  105.       'Draw burst point
  106.       GraphicsWindow.FillEllipse(x,y,size,size)
  107.     EndFor
  108.     'Fireworks fade a little more slowly
  109.     If (k = 2) Then
  110.       Program.Delay(10)
  111.     EndIf
  112.   EndFor
  113.   'Short delay between draw and black overdraw (erase)
  114.   Program.Delay(300)
  115. EndFor

  116. 'Next firework
  117. Goto next
复制代码

回复

使用道具 举报

发表于 2015-12-26 09:44:28 | 显示全部楼层
怎么用呢?
回复 支持 反对

使用道具 举报

发表于 2016-6-7 11:14:24 | 显示全部楼层
感谢分享。学习了
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2017-8-22 13:27 , Processed in 0.229563 second(s), 7 queries , File On.

Powered by Discuz! X3.3

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