Skip to content

Instantly share code, notes, and snippets.

@DideC
Forked from qtxie/sparks.red
Last active June 15, 2016 09:02
Show Gist options
  • Save DideC/4de8c35620c1edd31303ffe493a880e7 to your computer and use it in GitHub Desktop.
Save DideC/4de8c35620c1edd31303ffe493a880e7 to your computer and use it in GitHub Desktop.
With just a little bit of colored sparks
Red [
Title: "Sparks demo"
Author: "Qingtian Xie"
File: %sparks.red
Tabs: 4
Needs: View
]
system/view/auto-sync?: no
sparks: make block! 200
one-sixty: 1.0 / 60.0
view [
canvas: base 640x480 "Move the mouse ;-)" all-over rate 0:0:0.01666
on-time [
draw: clear []
foreach spark sparks [
spark/1: spark/1 + (spark/2 / 2)
spark/2/y: spark/2/y + 3
spark/3: spark/3 - one-sixty
; just a little bit of color ;-)
reduce/into ['pen spark/4 'line spark/1 spark/1 + spark/2] tail draw
]
canvas/draw: draw
show canvas
forall sparks [ ;-- remove old spark
if sparks/1/3 < 0.0 [sparks: back remove sparks]
]
][sparks one-sixty]
on-over [
append/only sparks reduce [ ;@@ optimize the memory usage
event/offset
as-pair (20 * random 1.0) - 10 (-40 * random 1.0)
1.0
; just a little bit of color ;-)
random white
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment