Last active
August 29, 2015 14:08
-
-
Save enshiromashiro/2d0eeffaf52372f05095 to your computer and use it in GitHub Desktop.
Drawing stripes with Clojure (Seesaw/WritableRaster).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns stagbeetle.core | |
(:gen-class) | |
(:use [seesaw.core] | |
[seesaw.graphics])) | |
(import (java.awt.image BufferedImage | |
WritableRaster) | |
(java.awt Color)) | |
(def frm (frame :title "stagbeetle")) | |
(def cnv (canvas)) | |
(def img (buffered-image 640 480 BufferedImage/TYPE_INT_ARGB)) | |
(defn draw-stripe [ras | |
i o c1 c2] | |
(dotimes [y (.getHeight ras)] | |
(dotimes [x (.getWidth ras)] | |
(if (even? (quot (+ o x) i)) | |
(.setPixel ras x y (int-array c1)) | |
(.setPixel ras x y (int-array c2))))) | |
nil) | |
(defn paint [c g] | |
(try (draw g (rect 0 0 (width c) (height c)) | |
(style :background :black)) | |
(.drawImage g img 0 0 nil))) | |
(defn init [] | |
(native!) | |
(config! cnv :size [640 :by 480]) | |
(config! cnv :paint paint) | |
(config! frm :content cnv)) | |
(defn -main | |
[& args] | |
(init) | |
(config! frm :on-close :dispose) | |
(let [start (System/currentTimeMillis)] | |
(draw-stripe (.getRaster img) 50 0 [0 0 255 255] [255 255 255 255]) | |
(println "eplaced:" (format "%.3f" (float (/ (- (System/currentTimeMillis) start) 1000))))) | |
(-> frm pack! show!)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment