SHARE
TWEET

Untitled

a guest Sep 27th, 2014 177 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns tetsujin.renderers.sword
  2.   (:require [play-clj.core :refer :all]
  3.             [play-clj.g2d :refer [pixmap pixmap-format]]
  4.             [overcode.sces.entity :as entity]
  5.             [tetsujin.renderers.util :as util])
  6.   (:import [java.ext.SimplexNoise]
  7.            [com.badlogic.gdx.graphics Pixmap]
  8.            [com.badlogic.gdx.graphics.g2d Gdx2DPixmap] ;; breaks everything. comment this out for try 1 to work.
  9.            ))
  10.  
  11. (def scale (atom 35))
  12.  
  13.  
  14. ;;; ATTEMPT 1 -- draw-pixel. This works.
  15. (defn render [entity screen]
  16.   (swap! scale #(+ % (- (rand) 0.5)))
  17.   (let [pm (Pixmap. 50 150 (pixmap-format :r-g-b-a8888))]
  18.  
  19.     (doseq [x (range 50)
  20.           y (range 150)]
  21.       (let [v (SimplexNoise/noise (/ x @scale) (/ y @scale))
  22.             v (/ (inc v) 2)]
  23.         (pixmap! pm :set-color (color v v v 1))
  24.         (pixmap! pm :draw-pixel x y)))
  25.     (draw! screen [(texture pm)])
  26.     (pixmap! pm :dispose)))
  27.  
  28.  
  29. ;;; ATTEMPT 2 -- create a Gdx2DPixmap. This is broken.
  30. (defn render [entity screen]
  31.   (swap! scale #(+ % (- (rand) 0.5)))
  32.   (let [colors (for [x (range 50)
  33.                      y (range 150)]
  34.                  (let [v (SimplexNoise/noise (/ x @scale) (/ y @scale))
  35.                        v (/ (inc v) 2)
  36.                        v (* 255 v)
  37.                        v (Math/floor v)]
  38.                    [v v v 1]
  39.                    ))
  40.         pixbytes (byte-array (concat [50 150 4] (flatten colors)))
  41.         gp (Gdx2DPixmap. pixbytes 0 (count pixbytes))
  42.         pm (Pixmap. gp)]
  43.     (draw! screen [(texture pm)])
  44.     (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