-
-
Save samaaron/2895243 to your computer and use it in GitHub Desktop.
square-exploration
This file contains 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 square-exploration | |
(:use quil.core)) | |
; This is another blatant ripoff, this time of the images produced | |
; by Don Relyea here: http://algorithm.posterous.com/tag/algorithmicexplorationofsquares | |
; This code needs some serious refactoring, particularly the screen metrics. | |
; Stay tuned... | |
(def screen-w 1000) | |
(def screen-h 1000) | |
(def square-border-width 6) | |
(def palette-size 6) | |
(def palette (atom [])) | |
(defn- init-palette [] | |
(doseq [i (range palette-size)] | |
(swap! palette conj [(random 255) (random 255) (random 255)]))) | |
(defn setup [] | |
(init-palette) | |
(smooth) | |
(no-loop)) | |
(defn- generate-square [x y width border-color] | |
(apply stroke border-color) | |
(stroke-weight square-border-width) | |
(rect x y width width)) | |
(defn- generate-concentric-squares [x y width] | |
(doseq [i (range (/ width square-border-width 2))] | |
(generate-square (+ x (* (+ i 0.5) square-border-width)) | |
(+ y (* (+ i 0.5) square-border-width)) | |
(- width (* (+ (* 2 i) 1) square-border-width)) | |
(@palette (int (random palette-size)))))) | |
(defn- generate-background [] | |
(generate-concentric-squares 0 0 screen-w)) | |
(defn- generate-random-concentric-squares [] | |
(doseq [i (range 30)] | |
(let [square-count (+ 5 (random 35)) | |
square-x (+ 10 (random (- (/ screen-w square-border-width) 10 square-count))) | |
square-y (+ 10 (random (- (/ screen-w square-border-width) 10 square-count)))] | |
(generate-concentric-squares (* square-border-width square-x) | |
(* square-border-width square-y) | |
(* square-border-width square-count))))) | |
(defn- generate-random-square-path [square-size start-x start-y square-count path-orientation] | |
(doseq [i (range square-count)] | |
(if (< path-orientation 1) | |
(generate-concentric-squares (+ start-x (* i 20)) | |
start-y | |
square-size) | |
(generate-concentric-squares start-x | |
(+ start-y (* i 20)) | |
square-size)))) | |
(defn- generate-random-square-paths [] | |
(doseq [i (range 10)] | |
(let [square-size (* square-border-width (+ 2 (random 3))) | |
start-x (random (* screen-w 0.75)) | |
start-y (random (* screen-w 0.75)) | |
square-count (+ 5 (random 10)) | |
path-orientation (random 2)] | |
(generate-random-square-path square-size | |
start-x | |
start-y | |
square-count | |
path-orientation)))) | |
(defn draw [] | |
(generate-background) | |
(generate-random-concentric-squares) | |
(generate-random-square-paths) | |
(save "square-exploration.png")) | |
(defsketch main | |
:title "square-exploration" | |
:setup setup | |
:draw draw | |
:size [screen-w screen-h]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment