SHARE
TWEET

Untitled

a guest Sep 27th, 2014 182 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;; ATTEMPT 1 -- draw-pixel. This works.
  2. (defn render [entity screen]
  3.   (swap! scale #(+ % (- (rand) 0.5)))
  4.   (let [pm (Pixmap. 50 150 (pixmap-format :r-g-b-a8888))]
  5.  
  6.     (doseq [x (range 50)
  7.           y (range 150)]
  8.       (let [v (SimplexNoise/noise (/ x @scale) (/ y @scale))
  9.             v (/ (inc v) 2)]
  10.         (pixmap! pm :set-color (color v v v 1))
  11.         (pixmap! pm :draw-pixel x y)))
  12.     (draw! screen [(texture pm)])
  13.     (pixmap! pm :dispose)))
  14.  
  15.  
  16. ;;; ATTEMPT 2 -- create a Gdx2DPixmap. This is broken.
  17. (defn render [entity screen]
  18.   (swap! scale #(+ % (- (rand) 0.5)))
  19.   (let [colors (for [x (range 50)
  20.                      y (range 150)]
  21.                  (let [v (SimplexNoise/noise (/ x @scale) (/ y @scale))
  22.                        v (/ (inc v) 2)
  23.                        v (* 255 v)
  24.                        v (Math/floor v)]
  25.                    [v v v 1]
  26.                    ))
  27.         pixbytes (byte-array (concat [50 150 4] (flatten colors)))
  28.         gp (Gdx2DPixmap. pixbytes 0 (count pixbytes))
  29.         pm (Pixmap. gp)]
  30.     (draw! screen [(texture pm)])
  31.     (pixmap! pm :dispose)))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top