Skip to content

Instantly share code, notes, and snippets.

@rm-hull
rm-hull / lorenz-attractor.cljs
Last active August 29, 2015 14:06
First studied by Edward Lorenz in 1963, the Lorenz attractor is a system of ordinary differential equations, which for certain parameter values and initial conditions, exhibits chaotic behaviour.
(ns big-bang.examples.lorenz-attractor
(:require
[cljs.core.async :as async]
[dommy.core :refer [insert-after!]]
[enchilada :refer [ctx canvas canvas-size value-of]]
[jayq.core :refer [show]]
[monet.canvas :refer [fill-style fill-rect circle translate
stroke-width stroke-cap stroke-style stroke
move-to line-to begin-path]]
[big-bang.core :refer [big-bang]]
(ns big-bang.examples.glass-box
(:require-macros
[cljs.core.async.macros :refer [go]]
[dommy.macros :refer [sel1 node]])
(:require
[cljs.core.async :refer [chan <! >!]]
[big-bang.core :refer [big-bang]]
[big-bang.events.browser :refer [prevent-default]]
[dataview.loader :refer [fetch-image]]
[enchilada :refer [webgl proxy-request]]
@rm-hull
rm-hull / plasma.cljs
Last active August 29, 2015 14:06
Old-skool plasma effect, flogged to death in the early 90's demo scene - the plasma is basically a function on 2D space created by adding together a few sinusoids. By combining different types of sines and adding a time component the illusion of motion is achieved.
(ns big-bang.examples.plasma
(:require
[big-bang.core :refer [big-bang]]
[enchilada :refer [ctx canvas canvas-size]]
[jayq.core :refer [show]]))
(def initial-state
(let [block-size 15
[width height] (map #(quot % block-size) (canvas-size))]
{:t 1 :block-size block-size :w width :h height}))
@rm-hull
rm-hull / illusory-cones.cljs
Last active August 29, 2015 14:06
An optical illusion in ClojureScript & big-bang, ported from http://djfav.com/2014/01/24/illusory-cones/ - originally written in javascript by Jon Faviell.
(ns big-bang.examples.illusory-cones
(:require
[big-bang.core :refer [big-bang]]
[jayq.core :refer [show]]
[enchilada :refer [ctx canvas canvas-size]]
[monet.canvas :refer [clear-rect circle fill-style fill
save restore translate rotate]]))
(def initial-state
(let [[width height] (canvas-size)]
@rm-hull
rm-hull / newtons-method.cljs
Last active August 29, 2015 14:06
Newtons method (also know as the Newton-Raphson method) is a textbook example of an iterated method for finding successively better approximations to the roots (or zeroes) of a real-valued function. This program calculates the square root using anonymous recursion by way of the _fixpoint combinator_ (a.k.a. Haskell Curry's paradoxical _Y-combina…
(ns fixpoint.newtons-method)
(defn square [x]
(* x x))
(defn average [x y]
(/ (+ x y) 2))
(defn improve [guess x]
(average guess (/ x guess)))
(ns biomorph.designer
(:require
[cljs.core.async :as async]
[clojure.string :as str]
[dommy.core :refer [insert-after! set-text! add-class! remove-class!]]
[monet.canvas :refer [get-context begin-path close-path
clear-rect quadratic-curve-to
stroke-style stroke-width stroke-cap
line-join move-to line-to stroke]]
[enchilada :refer [canvas-size value-of]]
@rm-hull
rm-hull / cumulative-selection.cljs
Last active August 29, 2015 14:05
In his 1986 book _The Blind Watchmaker_, Richard Dawkins ponders the infinite monkey problem: The scenario is staged to produce a string of gibberish letters, assuming that the selection of each letter in a sequence of 28 characters will be random. The number of possible combinations in this random sequence is 27^28, or about 10^40, so the proba…
(ns weasel.cumulative-selection
(:require
[cljs.core.async :as async]
[clojure.string :as str]
[dommy.core :refer [insert-after! set-text! add-class! remove-class!]]
[big-bang.core :refer [big-bang]]
[big-bang.components :refer [slider]]
[weasel.evolution :as evo])
(:require-macros
[dommy.macros :refer [sel1 node]]))
@rm-hull
rm-hull / LISSAJOUS.md
Last active August 29, 2015 14:05
In mathematics, a Lissajous curve /ˈlɪsəʒuː/, also known as Lissajous figure or Bowditch curve /ˈbaʊdɪtʃ/, is the graph of a system of parametric equations $x=A\sin(at+\delta)$, $y=B\sin(bt)$, which describe complex harmonic motion. This family of curves was investigated by Nathaniel Bowditch in 1815, and later in more detail by Jules Antoine Li…
@rm-hull
rm-hull / recursive-trees.cljs
Last active August 29, 2015 14:05
A recursively generated tree is simply _a branch with a tree on the end of it_.
(ns big-bang.demo.recursive-trees
(:require-macros
[cljs.core.async.macros :refer [go]]
[dommy.macros :refer [sel1 node]])
(:require
[cljs.core.async :refer [chan <! >!]]
[dommy.core :refer [insert-after!]]
[jayq.core :refer [$ hide show]]
[big-bang.core :refer [big-bang]]
[big-bang.components :refer [dropdown slider]]