Skip to content

Instantly share code, notes, and snippets.

@harold
Created February 22, 2016 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harold/8866e07526e427d67b11 to your computer and use it in GitHub Desktop.
Save harold/8866e07526e427d67b11 to your computer and use it in GitHub Desktop.
(ns hackathon.core
(:require [mikera.image.core :as i]))
(defn get-img
[]
(i/load-image-resource "galaxy.jpg"))
(defn get-?-block
[]
(i/sub-image (get-img) (* 16 16) (* 16 9) 16 16))
(defn get-gap
[]
(int (Math/floor (+ 32 (* 32 (rand))))))
(defn sort-img-row
[img i]
(let [w (i/width img)]
(loop [x 0
gap (get-gap)]
(let [pixels (i/get-pixels (i/sub-image img x i gap 1))
sorted-pixels (sort pixels)]
(doseq [n (range gap)]
(i/set-pixel img (+ x n) i (nth sorted-pixels n))))
(if (< (+ x gap) w)
(recur (+ x gap) (min (- w (+ x gap)) (get-gap)))))))
(defn go
[]
(let [img (get-img)
h (range (i/height img))]
(doseq [i h]
(println (str i "/" (i/height img)))
(sort-img-row img i)
)
(i/show img)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment