0  ,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3<W                                  ÎÌÌÌÌˆˆˆ¬ªªª¬ˆˆˆ¬ÌÌÌ¬ÌÀÌ¬ÌÀÌ¬ÌÀÌÌÌìîˆˆÌîªªÀîˆ¨ÀîÌ¬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌÌˆˆˆ¬ªªª¬ˆˆˆ¬ÌÌÌ¬ÌÌÌ¬ÌÀÌ¬ÌÀÌÌÌìîˆˆÌîªªÀîˆ¨ÀîÌ¬ÀÌÌ¬ÀÀÀ¬ÀÀÀ¬ÀÀ                                                                                                                                                                                                                                                                                                                                                                                                ¬ÌÌÌ¬ªªª¬ª¬ª¬ªÊÌ¬ªªªŒˆˆˆÌ ÀÌÎÌÌÎÌ¬ ÌªªÀì¬ªÀîªªÀîªªÀîˆˆÌî ÀìîÌÌîî¬ÌÌÌ¬ªªª¬ª¬ª¬ªÊÌ¬ªªªŒˆˆˆÌ ÀÌÎÌÌÎÌ¬ ÌªªÀì¬ªÀîªªÀîªªÀîˆˆÌî ÀìîÌÌîî  F?                                                                                                            À                                                                                                                      Ð                                                                                                                 @                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          `                         Ð                                                                                                           0        °                                                                                                                                                                                                                                                 
                                                                                    Ð                    `                                                                                                                   à                                                                                                                        À            0                                                                                            `                  P        `                                                                                                                  `    P                                                                                                            @       @                                                                                                                    0                                                                                                                    Ð P                                 	                                                                               0   0                       
       p                           
                                                    p                                                                                                                            €   Ð                                                                                                                                                                                                                                                                                                                                                    p œ                                                                                                                                                                                                                                                     °p                                        °                                                                    Ð       Ð `                                                                                                     Ð                                                                                                                             P                                                                                     
                     À     P                                       
                           `                          P Ð                                               Ð                0            À                                                                                €                                                                                                                                                      P                                                          À      @                                                                                                                                         à                                                                                          °                                                                                                                                                                             @                                                                          `                     À                                 °                                                                                                                                                                                                   P                                              À                                     à          à                                                     à              0                                                                  `                                                                                                         0                           0                                                                         À                               `À@ 	           €                                                                                                                                                                                                                                                                                                       	               À                            Ð                                      °                                          @                                    à                      	   Ð         
                                                                                  
                                                                                                              p                             à               À                                                                       0     ã                                                                                       	                                                                                                            °                                                   @                                                                                                                                  0                                                                                                                         °        °                                                                 
                                P                                                                                                                                  `@                                                        °                                                                             	                                                                                              0                                                                                                                                             	                                                                                               p                     €                                             Ð                                                   a                                 à                                                                              °                     @                                                                                                                             	                      
                                                                                                                                                                 @                                           
  `                                                      @                                                                à                                                                                                    à                  0                                                                                                                 
P                                                                                        @                      0       Ð                                                                                                                                                                                                                                     	                                                                                                                                                                                                                                         `     P                                                                                                                                                            Ð          À                                                                                                                                                                                                    0                                                                                                                                                                                                            p                                                                                                                                                   p                                à                                                                                                                                                                                                                                      @              0                                                                                                                          à                                                                                  
                              »                                                                                                                                                p                                                                                                                                  @                                                                  °                         @                  
                
                                                                                                                                                                                                                          à                                            0            €                                                                                              p `                                                                                                                                                                                      à                                
                                                                                                                                                                                                  	         p                              à                                        Ð                                                                                                                                      €                                                                                            	                                                                                                                                      p        	                                    à                                                                                  @                  
                                                                                  p                                              P                                                                 p                                                                                               €                     0           À                                                                                                                                                                                                                                       P                                                                                                                                                                                                                                        Ð                                        
p                      `                                                                                       p                                                                                                                                                                                       @                                      à                                                                                                       
                                    0          À                                                                                                          °`             €                                                       €                                                °                                                                   À                                        
                    €                         P                                                                               @                                                                 P                                     p                	                                                                                                                           @          	                                                                                    °                                                           P                                                                 °                                       à                      p                                                                                                                                                                                                                                                      P                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                             à                                                                                                                                                   P                                                             
à                                                                                        0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
               Ç ;; title:   Fireworks
;; author:  crisjr.eng.br
;; desc:    Fireworks simulation
;; site:    http://www.crisjr.eng.br
;; license: Beerware v42
;; version: 0.1.0
;; script:  fennel
;; strict:  true

(var HEIGHT (* 8 17))
(var WIDTH (* 8 30))
(var GRAVITY (/ 1 100))
(var PARTICLES [])

(fn concat [x y]
  (let [z x]
    (each [_ a (ipairs y)]
      (table.insert z a))
    z))

(fn random [from to]
  (+ from (* (- to from) (math.random))))

(fn new-particle [x0 y0]
  (let [vx0 (- (math.random) 0.5)
        vy0 (- (math.random))]
    {:x0  x0
     :y0  y0
     :vx0 vx0
     :vy0 vy0
     :t   (- 1)
     :x   x0
     :y   y0
     :c   (random 2 16)}))

(fn new-firework [x0 y0 ps]
  (let [firework []]
    (for [_ 1 ps 1]
      (table.insert firework (new-particle x0 y0)))
    firework))
  
(fn read-input [particles]
  (if (btnp 4)
    (let [x0 (random 10 (- WIDTH 10)) 
          y0 (random 10 (- HEIGHT 10))
          no-parts (random 20 50)
          firework (new-firework x0 y0 no-parts)]
      (concat particles firework))
    particles))

(fn move-particle [p]
  (let [x0 (. p :x0)
        y0 (. p :y0)
        vx0 (. p :vx0)
        vy0 (. p :vy0)
        t (+ 1 (. p :t))]
    {:x0 x0
     :y0 y0
     :vx0 vx0
     :vy0 vy0
     :t t
     :x (+ x0 (* t vx0))
     :y (+ y0 (* t vy0) (* GRAVITY t t))
     :c (. p :c)}))
  
(fn is-particle-valid [p]
  (let [x (. p :x)
        y (. p :y)]
    (and (> x 0)
         (< x WIDTH)
         (< y HEIGHT))))

(fn update-particles [particles]
  (let [new-particles []]
    (each [_ p (ipairs particles)]
      (let [p1 (move-particle p)]
        (when (is-particle-valid p1)
          (table.insert new-particles p1))))
    new-particles))
  
(fn draw-particles [particles]
  (cls 0)
  (each [_ p (ipairs particles)]
    (let [x (. p :x)
          y (. p :y)
          c (. p :c)]
      (pix x y c)))
  particles)

(fn _G.TIC []
  (->> PARTICLES
       read-input
       update-particles
       draw-particles
       (set PARTICLES)))
