Skip to content

Instantly share code, notes, and snippets.

@mhuebert
Forked from daveliepmann/pyrgiometry.clj
Created July 10, 2017 21:57
Show Gist options
  • Save mhuebert/f3ba2e0458d2a89c9bfb7ac854636181 to your computer and use it in GitHub Desktop.
Save mhuebert/f3ba2e0458d2a89c9bfb7ac854636181 to your computer and use it in GitHub Desktop.
"Πυργεωμετρία ('Pyrgi-ometry')", a Processing sketch using Clojure and Quil. Inspired by artwork in the village of Pyrgi on the Greek island Chios: https://daveliepmann.exposure.so/pyrgi
;; "Πυργεωμετρία ('Pyrgi-ometry')", a Processing sketch using Clojure and Quil
(ns livecode.pyrgi
(:use quil.core))
(def stripe-height 50)
(def canvas-height (* 9 stripe-height))
(def canvas-width (* canvas-height (/ 3 2)))
;; Color conversion, courtesy of Jack Rusher
(defn hex-to-color [hex]
(apply color (map (comp #(Integer/parseInt % 16) (partial apply str))
(partition 2 (.replace hex "#" "")))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Geometries
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn isosceles-fun
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(doseq [x (range base-x end-x shape-width)]
(fill fill-color)
(triangle x base-y
x (+ base-y line-height)
(+ x shape-width) (+ base-y line-height))
(triangle (+ x (/ shape-width 2)) (+ base-y (/ line-height 2))
(+ x shape-width (- (/ shape-width 7))) (+ base-y (/ line-height 2))
(+ x (/ shape-width 2)) (+ base-y (/ shape-width 7)))
(fill bg-color)
(triangle (+ x (/ shape-width 2)) (+ base-y (/ line-height 2))
(+ x (/ shape-width 7)) (+ base-y (/ line-height 2))
(+ x (/ shape-width 2)) (+ base-y line-height (- (/ shape-width 7)))))
(stroke-weight 1)
(stroke fill-color)
(line base-x base-y end-x base-y)
(pop-style))
(defn circles-and-half-circles
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(smooth)
(let [radius 22]
(doseq [x1 (range base-x end-x (* 2 shape-width))]
(fill fill-color)
(rect x1 base-y shape-width line-height)
(fill bg-color)
(ellipse (+ x1 (/ shape-width 2)) (+ base-y (/ line-height 2))
radius radius)
(arc x1 (+ base-y (/ line-height 2)) radius radius
(+ PI HALF-PI) (+ TWO-PI HALF-PI))
(arc (+ x1 shape-width) (+ base-y (/ line-height 2)) radius radius
HALF-PI (+ PI HALF-PI)))
(doseq [x2 (range (+ base-x shape-width) canvas-width (* 2 shape-width))]
(fill bg-color)
(rect x2 base-y shape-width line-height)
(fill fill-color)
(ellipse (+ x2 (/ shape-width 2)) (+ base-y (/ line-height 2))
radius radius)
(arc x2 (+ base-y (/ line-height 2)) radius radius
(+ PI HALF-PI) (+ TWO-PI HALF-PI))
(arc (+ x2 shape-width) (+ base-y (/ line-height 2)) radius radius
HALF-PI (+ PI HALF-PI))))
(stroke-weight 1)
(stroke fill-color)
(no-smooth)
(line base-x base-y end-x base-y)
(line base-x (+ base-y line-height) end-x (+ base-y line-height))
(pop-style))
(defn negative-ellipses
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(rect base-x base-y end-x line-height)
(ellipse-mode :corner)
(smooth)
(doseq [x (range base-x end-x (/ shape-width 4))]
(fill bg-color)
(ellipse x base-y (/ shape-width 4) line-height)
(fill fill-color)
(ellipse (+ x (/ shape-width 16))
(+ base-y (/ line-height 4))
(/ shape-width 8)
(/ line-height 2)))
(pop-style))
(defn double-stripes
[base-x base-y end-x thickness line-height fill-color bg-color]
(push-style)
(fill fill-color)
(smooth)
(no-stroke)
(doseq [x (range base-x end-x thickness)]
(quad x (+ base-y (/ line-height 2))
(+ x (/ thickness 2)) (+ base-y (/ line-height 2))
(+ x thickness) base-y
(+ x (/ thickness 2)) base-y))
(doseq [x (range base-x end-x thickness)]
(quad x (+ base-y line-height)
(+ x (/ thickness 2)) (+ base-y line-height)
(+ x thickness) (+ base-y (/ line-height 2))
(+ x (/ thickness 2)) (+ base-y (/ line-height 2))))
(stroke-weight 1)
(stroke fill-color)
(line base-x base-y end-x base-y)
(line base-x (+ base-y line-height (- 1)) end-x (+ base-y line-height (- 1)))
(pop-style))
(defn stacked-diamonds
[base-x base-y end-x thickness line-height fill-color bg-color]
(push-style)
(fill fill-color)
(smooth)
(doseq [x (range base-x end-x thickness)]
(quad x (+ base-y (/ line-height 8))
(+ x (/ thickness 2)) base-y
(+ x thickness) (+ base-y (/ line-height 8))
(+ x (/ thickness 2)) (+ base-y (/ line-height 4)))
(quad x (+ (+ base-y (/ line-height 8)) (/ line-height 4))
(+ x (/ thickness 2)) (+ base-y (/ line-height 4))
(+ x thickness) (+ base-y (/ line-height 8) (/ line-height 4))
(+ x (/ thickness 2)) (+ base-y (/ line-height 4) (/ line-height 4)))
(quad x (+ (+ base-y (/ line-height 8)) (/ line-height 2))
(+ x (/ thickness 2)) (+ base-y (/ line-height 2))
(+ x thickness) (+ base-y (/ line-height 8) (/ line-height 2))
(+ x (/ thickness 2)) (+ base-y (/ line-height 4) (/ line-height 2)))
(quad x (+ (+ base-y (/ line-height 8)) (* line-height 0.75))
(+ x (/ thickness 2)) (+ base-y (* line-height 0.75))
(+ x thickness) (+ base-y (/ line-height 8) (* line-height 0.75))
(+ x (/ thickness 2)) (+ base-y (/ line-height 4) (* line-height 0.75))))
(stroke-weight 1)
(stroke fill-color)
(line base-x base-y end-x base-y)
(line base-x (+ base-y line-height (- 1)) end-x (+ base-y line-height (- 1)))
(pop-style))
(defn plus-sign-of-circles
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(smooth)
(doseq [x (range base-x end-x (* 2 shape-width))]
(fill fill-color)
(ellipse (+ x (/ shape-width 2))
(+ base-y (/ line-height 2))
27 27)
(arc x base-y (/ line-height 1.5) (/ line-height 1.5)
0 HALF-PI)
(arc (+ x shape-width) base-y (/ line-height 1.5) (/ line-height 1.5)
HALF-PI PI)
(arc (+ x shape-width) (+ base-y line-height)
(/ line-height 1.5) (/ line-height 1.5)
PI (+ PI HALF-PI))
(arc x (+ base-y line-height) (/ line-height 1.5) (/ line-height 1.5)
(+ PI HALF-PI) TWO-PI)
(fill bg-color)
(ellipse (+ x (/ shape-width 2))
(+ base-y (/ line-height 2)) 6 6)
(fill fill-color)
(rect (+ x shape-width) base-y shape-width line-height)
(fill bg-color)
(ellipse (+ x shape-width (/ shape-width 2))
(+ base-y (/ line-height 2)) 27 27)
(arc (+ x shape-width) base-y
(/ line-height 1.5) (/ line-height 1.5)
0 HALF-PI)
(arc (+ x (* 2 shape-width)) base-y
(/ line-height 1.5) (/ line-height 1.5)
HALF-PI PI)
(arc (+ x (* 2 shape-width)) (+ base-y line-height)
(/ line-height 1.5) (/ line-height 1.5)
PI (+ PI HALF-PI))
(arc (+ x shape-width) (+ base-y line-height)
(/ line-height 1.5) (/ line-height 1.5)
(+ PI HALF-PI) TWO-PI)
(fill fill-color)
(ellipse (+ x shape-width (/ shape-width 2))
(+ base-y (/ line-height 2)) 6 6))
(stroke-weight 1)
(stroke fill-color)
(line base-x base-y end-x base-y)
(line base-x (+ base-y line-height) end-x (+ base-y line-height))
(pop-style))
(defn pinwheels
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(no-smooth)
(doseq [x (range base-x end-x shape-width)]
(fill fill-color)
(triangle x base-y
(+ x (/ shape-width 2)) base-y
(+ x (/ shape-width 2)) (+ base-y (/ line-height 2)))
(triangle x (+ base-y (/ line-height 2))
(+ x (/ shape-width 2)) (+ base-y (/ line-height 2))
x (+ base-y line-height))
(triangle (+ x (/ shape-width 2)) (+ base-y (/ line-height 2))
(+ x shape-width) (+ base-y line-height)
(+ x (/ shape-width 2)) (+ base-y line-height))
(triangle (+ x (/ shape-width 2)) (+ base-y (/ line-height 2))
(+ x shape-width) base-y
(+ x shape-width) (+ base-y (/ line-height 2))))
(stroke-weight 1)
(stroke fill-color)
(line base-x base-y end-x base-y)
(line base-x (+ base-y line-height) end-x (+ base-y line-height))
(pop-style))
(defn facing-triangles
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(stroke-weight 1)
(stroke fill-color)
(line base-x base-y end-x base-y)
(line base-x (+ base-y line-height) end-x (+ base-y line-height))
(smooth)
(doseq [x (range base-x end-x (* 2 shape-width))]
(fill fill-color)
(triangle x base-y
(+ x (/ shape-width 2)) (+ base-y (/ line-height 2))
x (+ base-y line-height))
(triangle (+ x shape-width) base-y
(+ x (/ shape-width 2)) (+ base-y (/ line-height 2))
(+ x shape-width) (+ base-y line-height))
(triangle (+ x shape-width) base-y
(+ x (* shape-width 1.5)) (+ base-y (/ line-height 2))
(+ x (* 2 shape-width)) base-y)
(triangle (+ x shape-width) (+ base-y line-height)
(+ x (* shape-width 1.5)) (+ base-y (/ line-height 2))
(+ x (* 2 shape-width)) (+ base-y line-height)))
(pop-style))
(defn ghost-rectangles
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-matrix)
(push-style)
(stroke-weight 1)
(let [small-rect-size 25]
(doseq [x (range (+ (* shape-width 0.75) base-x) end-x (* 2 line-height))]
(fill fill-color)
(stroke fill-color)
(rect-mode :corner)
(rect x base-y line-height line-height)
(rect-mode :center)
(fill bg-color)
(rect x (+ base-y (/ line-height 2))
small-rect-size small-rect-size)
(rect (+ x line-height) (+ base-y (/ line-height 2))
small-rect-size small-rect-size)))
(no-smooth)
(stroke fill-color)
(line base-x base-y end-x base-y)
(line base-x (+ base-y line-height) end-x (+ base-y line-height))
(pop-matrix)
(pop-style))
(defn squinting-rectangles
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(let [small-rec-width 18
large-rec-width 36]
(doseq [x (range base-x end-x (* 4 shape-width))]
(no-stroke)
(rect-mode :corner)
(rect x base-y line-height line-height)
(fill fill-color)
(rect (+ x (* 2 line-height)) base-y line-height line-height)
(rect-mode :center)
(fill fill-color)
(rect (+ x (* shape-width 1.5)) (+ base-y (/ line-height 2))
shape-width shape-width)
(fill bg-color)
(rect (+ x (/ shape-width 2)) (+ base-y (/ line-height 2))
shape-width shape-width)
(rect (+ x (* shape-width 2.5)) (+ base-y (/ line-height 2))
small-rec-width small-rec-width)
(fill fill-color)
(rect (+ x (* shape-width 3.5)) (+ base-y (/ line-height 2))
small-rec-width small-rec-width)
(fill bg-color)
(rect (+ x (* shape-width 1.5)) (+ base-y (/ line-height 2))
large-rec-width large-rec-width)
(fill fill-color)
(rect (+ x (* shape-width 0.5)) (+ base-y (/ line-height 2))
large-rec-width large-rec-width)
(stroke-weight 1)
(stroke bg-color)
(line (+ x (* 2 shape-width)) base-y
(+ x (* 2 shape-width)) (+ base-y line-height))
(stroke fill-color)
(line x base-y x (+ base-y line-height))))
(stroke-weight 1)
(stroke fill-color)
(line base-x base-y end-x base-y)
(line base-x (+ base-y line-height) end-x (+ base-y line-height))
(pop-style))
(defn alternating-ceiling-and-floor-circles-and-triangles
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(fill fill-color)
(no-stroke)
(smooth)
(let [shape-height 22]
(doseq [x (range base-x end-x (* 2 shape-width))]
(arc (+ x (/ shape-width 2)) base-y shape-width (* 2 shape-height) 0 PI)
(triangle (+ (+ x (/ shape-width 2)) (/ shape-width 2)) base-y
(+ (+ x (/ shape-width 2)) (* 1.5 shape-width)) base-y
(+ (+ x (/ shape-width 2)) shape-width) (+ base-y shape-height))
(arc (+ x (/ shape-width 2)) (+ base-y line-height)
shape-width (* 2 shape-height)
PI TWO-PI)
(triangle (+ (+ x (/ shape-width 2)) (/ shape-width 2))
(+ base-y line-height)
(+ (+ x (/ shape-width 2)) (* 1.5 shape-width))
(+ base-y line-height)
(+ (+ x (/ shape-width 2)) shape-width)
(- (+ base-y line-height) shape-height))))
(pop-style))
(defn alternating-ceiling-and-floor-circles-and-triangles-offset
[base-x base-y end-x shape-width line-height fill-color bg-color]
(push-style)
(fill fill-color)
(rect-mode :corners)
(rect base-x base-y end-x (+ base-y line-height))
(stroke-weight 1)
(stroke fill-color)
(line base-x (- base-y 1) end-x (- base-y 1))
(line base-x (+ base-y line-height) end-x (+ base-y line-height))
(fill bg-color)
(no-stroke)
(smooth)
(let [shape-height 26]
(doseq [x (range base-x end-x (* 2 shape-width))]
(arc (+ x (/ shape-width 2)) base-y shape-width (* 2 shape-height) 0 PI)
(triangle (+ (+ x (/ shape-width 2)) (/ shape-width 2)) base-y
(+ (+ x (/ shape-width 2)) (* 1.5 shape-width)) base-y
(+ (+ x (/ shape-width 2)) shape-width) (+ base-y shape-height))
(triangle (+ x (/ shape-width 2)) (- (+ base-y line-height) shape-height)
x (+ base-y line-height)
(+ x shape-width) (+ base-y line-height))
(arc (+ x (* 1.5 shape-width)) (+ base-y line-height)
shape-width (* 2 shape-height)
PI TWO-PI)))
(pop-style))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; With our geometries known, we now define the sketch
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn setup []
(frame-rate 1))
(def geometries
[isosceles-fun
negative-ellipses
ghost-rectangles
squinting-rectangles
circles-and-half-circles
double-stripes
alternating-ceiling-and-floor-circles-and-triangles
alternating-ceiling-and-floor-circles-and-triangles-offset
stacked-diamonds
plus-sign-of-circles
pinwheels
facing-triangles])
(defn draw-flag-with-random-geometry []
(background 255)
(no-stroke)
(smooth)
(let [canton-square (* 2 stripe-height)
canton-edge (+ stripe-height (* 2 canton-square))]
;; Canton and cross in upper left for Eastern Orthodox Christianity
(rect-mode :corner)
(fill 255)
(rect 0 0 canton-edge canton-edge)
(fill (hex-to-color "#0099FF"))
(rect 0 0 canton-square canton-square)
(rect 0 (+ stripe-height canton-square)
canton-square canton-square)
(rect (+ stripe-height canton-square) 0
canton-square (+ 1 canton-square))
(rect (+ stripe-height canton-square) (+ stripe-height canton-square)
canton-square canton-square)
;; Nine stripes for Έλευθερία ή Θάνατος" ("Freedom or Death")
(doseq [[y random-geometry] (map vector (range 0 canvas-height
(* 2 stripe-height))
(shuffle geometries))]
;; ...five stripes beside the canton, and four stripes below the canton
(if (< y (+ 1 (- canton-edge stripe-height)))
(random-geometry (+ 1 canton-edge) y canvas-width
stripe-height stripe-height
(hex-to-color "#0099FF") 255)
(random-geometry 0 y canvas-width
stripe-height stripe-height
(hex-to-color "#0099FF") 255)))
(delay-frame 1500)))
(defsketch pyrgi
:title "Πυργεωμετρία ('Pyrgi-ometry')"
:setup setup
:draw draw-flag-with-random-geometry
:size [canvas-width canvas-height])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment