Code archives/Graphics/Simple Lightning for Max
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Press your space-bar to change where the lightning is generated. | |||||
'Written by David Schwartz - http://www.devdave.net Graphics 640,480,0 SetColor 255,255,255 Global newpixelx = 0 Global pixelx = 240 Global pixely = 0 Global pixelmove = 0 Repeat If KeyHit(key_space) Then newpixelx = Rand(0,640) CreateBolt() Flip;Cls Until KeyHit(key_escape) Function CreateBolt() pixelx = newpixelx pixely = 0 For i=1 To 480 pixelmove = Rand(-1,1) pixelx = pixelx - pixelmove pixelmove = Rand(-1,1) pixelx = pixelx + pixelmove pixely = pixely + 1 Plot pixelx,pixely Next End Function |
Comments
| ||
Would have added a "glow" to it if I knew how. Tried messing around with ALPHABLEND and SetAlpha, but failed. |
| ||
If you use DrawLine you can set the width to make it look thicker. |
| ||
Actually, I like its width as it is. The only thing I would add now is a glow that most lightning bolts have ;) |
| ||
I added a blue glow and changed some other things. After pressing SPACE the bolt stays on screen to get a better impression of it. Press SPACE again for another or ESCAPE to leave. 'Written by David Schwartz - http://www.devdave.net 'Modified by Calibrator, 2010-06-06 ' Global ResX = 800 Global ResY = 600 Function CreateBolt() Local pixelmove Local pixelx Local pixely pixelx = Rand(0,ResX) pixely = 0 For i=1 To ResY pixelmove = Rand(-1,1) pixelx = pixelx - pixelmove pixelmove = Rand(-1,1) pixelx = pixelx + pixelmove pixely = pixely + 1 SetColor 0,0,128 Plot pixelx-2,pixely SetColor 0,0,192 Plot pixelx-1,pixely SetColor 225,225,255 Plot pixelx,pixely SetColor 0,0,192 Plot pixelx+1,pixely SetColor 0,0,128 Plot pixelx+2,pixely Next End Function Graphics ResX,ResY,0 While Not (KeyHit(KEY_ESCAPE) Or AppTerminate()) If KeyHit(KEY_SPACE) Cls CreateBolt() Flip EndIf Wend |
Code Archives Forum