Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns diagrams.core
(:require [hiccup.core :as h]))
(let [prelude "<?xml version=\"1.0\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN \" \" \">\n"]
(defn svg-str
(str prelude (h/html [:svg {:height 400 :width 400 :xmlns ""} contents]) "\n")))
(defn circle
[x y r & {:as attrs}]
[:circle (merge {:cx x :cy y :r r} attrs)])
(defn rect
[x y w h]
[:rect {:x x :y y :width w :height h}])
(defn line
[x1 y1 x2 y2 & {:as attrs}]
(let [[x1 y1 x2 y2] (map double [x1 y1 x2 y2])]
[:path (merge {:d (format "M%f,%fL%f,%f" x1 y1 x2 y2)} attrs)]))
(defn turbulate
(let [id (str (gensym))]
[:filter {:id id}
[:feTurbulence {:type "fractalNoise" :baseFrequency "0.1" :result "noise"}]
[:feDisplacementMap {:scale "10" :xChannelSelector "R" :yChannelSelector "G" :in "SourceGraphic" :in2 "noise"}]]
[:g {:filter (format "url(#%s)" id)}
(defn run
(spit "sample.svg"
[:g {:style "stroke:black;"}
[:g {:transform "scale(198,198) translate(1.01,1.01)"}
(circle 0 0 1 :fill "red" :stroke-width 0.03)
(for [i (range 30)]
[:g {:transform (format "rotate(%f)" (double (rand 360)#_(/ (* 360 i) 30)))}
[:path {:stroke-width 0 :fill "black" :d "M0,0L1,0.03L1,-0.03L0,0"}]])]]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.