Skip to content

Instantly share code, notes, and snippets.

@r4vi
Created July 22, 2012 01:02
Show Gist options
  • Save r4vi/3157822 to your computer and use it in GitHub Desktop.
Save r4vi/3157822 to your computer and use it in GitHub Desktop.
Quill Examples
(ns quil-ravi.core
(:use quil.core))
(defn setup []
(smooth) ;;Turn on anti-aliasing
(frame-rate 65) ;;Set framerate to 1 FPS
(background 200)) ;;Set the background colour to
;; a nice shade of grey.
(defn savef []
(save (str "C:\\temp\\quil\\" (ns-name *ns*) "-" (frame-count) "-out.png")))
(defn draw []
(stroke (random 255) (random 255) (random 255)) ;;Set the stroke colour to a random grey
(stroke-weight (random 5)) ;;Set the stroke thickness randomly
(fill (random 255) (random 255) (random 255)) ;;Set the fill colour to a random grey
(let [diam (random 55) ;;Set the diameter to a value between 0 and 100
x (random (width)) ;;Set the x coord randomly within the sketch
y (random (height))] ;;Set the y coord randomly within the sketch
(ellipse x y diam diam))) ;;Draw a circle at x y with the correct diameter
(defsketch example3 ;;Define a new sketch named example
:title "Oh so many grey circles" ;;Set the title of the sketch
:setup setup ;;Specify the setup fn
:draw draw ;;Specify the draw fn
:mouse-clicked savef
:size [851 315]) ;;You struggle to beat the golden ratio
(ns quil-ravi.genart1
(:use quil.core
[quil.helpers.seqs :only [seq->stream range-incl]]))
(defn setup []
(smooth) ;;Turn on anti-aliasing
(frame-rate 5) ;;Set framerate to 1 FPS
(background 200) ;;Set the background colour to
(width)(height)
(let [diams (range-incl (width) 0 -5)]
(set-state! :diam (seq->stream diams)
:cent-x (/ (width) 2)
:cent-y (/ (height) 2)))) ;; a nice shade of grey.
(defn savef []
(save (str "C:\\temp\\quil\\" (ns-name *ns*) "-" (frame-count) "-out.png")))
(defn draw []
(stroke (random 255) (random 255) (random 255)) ;;Set the stroke colour to a random grey
(stroke-weight (random 5)) ;;Set the stroke thickness randomly
(fill (random 255) (random 255) (random 255)) ;;Set the fill colour to a random color
(let [diam ((state :diam)) ;;Set the diameter to a value between 0 and 100
x (state :cent-x) ;;Set the x coord randomly within the sketch
y (state :cent-y)] ;;Set the y coord randomly within the sketch
(if (= diam 0)
(exit))
(ellipse x y diam diam)))
(defsketch warped-circles ;;Define a new sketch named example
:size [400 400]
:title "warped circles" ;;Set the title of the sketch
:setup setup ;;Specify the setup fn
:draw draw ;;Specify the draw fn
:mouse-clicked savef)
(ns quil-ravi.genart2
(:use quil.core
[quil.helpers.seqs :only [seq->stream range-incl steps]]))
;; colour pallet from http://www.colourlovers.com/palette/1812767/Snow?widths=1
(defn setup []
(smooth)
(frame-rate 5)
(background 200)
(width)(height)
(let [step '(quil.core/random 5)
x2 (range-incl (width) 0 (- (eval step)))
y2 (range-incl (height) 0 (- (eval step)))
pallet (cycle [
'(218 229 247)
'(195 208, 227)
'(163 177 203)
'(146 157 189)
])]
(set-state!
:x2 (seq->stream x2)
:y2 (seq->stream y2)
:pallet (seq->stream pallet))))
(defn savef []
(save (str "C:\\temp\\quil\\" (ns-name *ns*) "-" (frame-count) "-out.png")))
(defn draw []
(apply stroke ((state :pallet))) ;;Set the stroke colour to a random grey
(stroke-weight 5)
(fill (random 255) (random 255) (random 255)) ;;Set the fill colour to a random color
(let [x2 ((state :x2)) ;;Set the diameter to a value between 0 and 100
y2 ((state :y2))] ;;Set the y coord randomly within the sketch
(if (< x2 0)
((savef)
(exit)))
(line 0 y2 400 x2)
(line 0 x2 400 y2)
(line 0 x2 400 x2)
(line 0 y2 400 y2)
(stroke-weight 1)
#_(line (random 400) (random 400) (random 400) (random 400))
(savef)
))
(defsketch lines ;;Define a new sketch named example
:size [400 400]
:title "lines" ;;Set the title of the sketch
:setup setup ;;Specify the setup fn
:draw draw ;;Specify the draw fn
:mouse-clicked savef)
(ns quil-ravi.genart3
(:use quil.core
[quil.helpers.seqs :only [seq->stream range-incl steps]]
[quil.helpers.drawing :only [line-join-points]]
[quil.helpers.calc :only [mul-add]]))
;; colour pallet from http://www.colourlovers.com/palette/580974/Adrift_in_Dreams
(defn setup []
(smooth)
(frame-rate 60)
(background 150)
(width)(height)
(let [xs (range-incl 20 480 1)
rads (map radians (range))
ys (map sin rads)
scaled-ys (mul-add ys 40 50)
line-args (line-join-points xs scaled-ys)
pallet (cycle [
'(207 240 158)
'(168 219 168)
'(121 189 154)
'(59 134 134)
'(11 72 107)
])]
(set-state! :line-args (seq->stream line-args)
:pallet (seq->stream pallet)))
(stroke 0 30)
(line 20 50 480 50)
(stroke 20 50 70))
(defn savef []
(save (str "C:\\temp\\quil\\" (ns-name *ns*) "-" (format "%08d" (frame-count)) "-out.png")))
(defn draw []
(stroke-weight 5)
(let [args ((state :line-args))
[x y] args]
(apply line args)
(if (== (round y) 50)
(apply stroke ((state :pallet))))
;;(savef)
))
(defsketch sinewave ;;Define a new sketch named sinewave
:size [500 100]
:title "sine" ;;Set the title of the sketch
:setup setup ;;Specify the setup fn
:draw draw ;;Specify the draw fn
:mouse-clicked savef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment