Skip to content

Instantly share code, notes, and snippets.

@rm-hull
rm-hull / simple-demo.cljs
Last active December 15, 2015 04:19
Demo clojurescript gist for programming enchiladas
(ns example)
;; Print output goes to the output buffer
(doseq [a (range 10)
b (range a)]
(println a "x" b "=" (* a b)))
(js/alert "ClojureScript says 'Boo!'")
@rm-hull
rm-hull / turtle-demo.cljs
Last active December 15, 2015 08:18
Demo clojurescript gist to test out http://programming-enchiladas.destructuring-bind.org/ -- draws a simple pentagon and other geometric stars using turtle graphics
;; Draws a simple pentagon and other geometric stars using turtle graphics
;;
;; Scale it to fit in a bounding-box of 750x550 px
(ns turtle.demo
(:use [turtle.core :only [draw!]]
[turtle.renderer.canvas :only [->canvas]]
[jayq.core :only [show]]
[enchilada :only [ctx canvas]]))
@rm-hull
rm-hull / champernowne.cljs
Last active December 15, 2015 08:49
Experiments in colourizing digits of transcendental numbers like √2, π and Champernowne's constant - numbers which are not the root of any polynomial with integer coeffients. Whilst an Cambridge undergraduate in 1933, David Champernowne concatenated the positive integers, 1, 2, 3, 4, ..., and lead with a decimal point to yield 0.1234567891011121…
(ns transcendental-numbers.champernownes-constant
(:use [transcendental-numbers.utils :only [digits integers]]))
(def digit-seq
(mapcat digits integers))
@rm-hull
rm-hull / flower-of-life.cljs
Last active December 10, 2017 04:19
Flower of Life, in ClojureScript ... originally in JavaScript by Tristan Brehaut [http://js1k.com/2013-spring/details/1362]: "Randomly generated spiraling energetic patterns depicting the flower of life in 5 dimensions, or something :) Refresh window for a new flower."
;; Adapted from javascript version by Tristan Brehaut at
;; http://js1k.com/2013-spring/details/1362
(ns flower-of-life.demo
(:use [monet.canvas :only [save restore begin-path end-path translate rotate
stroke stroke-style fill-style fill-rect move-to
bezier-curve-to composition-operation]]
[monet.core :only [animation-frame]]
[jayq.core :only [show]]
[enchilada :only [ctx canvas]]))
@rm-hull
rm-hull / turmites.cljs
Last active December 15, 2015 12:19
A turmite is a Turing machine which has an orientation as well as a current state and a "tape" that consists of an infinite two-dimensional grid of cells. Adapted from: https://github.com/rm-hull/turmites
;; Turmites
;; --------
;; A simple N-state two-color Turing machine which operates on a wrapped
;; grid of black and white cells, and follows custom rules on every tick of
;; a clock.
;;
;; Predef rules derived from http://code.google.com/p/ruletablerepository/downloads/detail?name=Turmites.zip
;;
;; Copyright (c) Richard Hull 2012
;;
@rm-hull
rm-hull / error.cljs
Created March 29, 2013 17:03
Faulty ClojureScript to test error reporting in http://programming-enchiladas.destructuring-bind.org
(ns error.demo)
(+ 3 6
@rm-hull
rm-hull / chroma-spirals.cljs
Last active December 15, 2015 14:58
Rewrote python code [from Peter Derlien], in ClojureScript - see "The Pi-Cubed Programming Challenge : Golden Angle, Sunflowers and Chromospirals http://pi3.sites.sheffield.ac.uk/tutorials/week-2"
; chroma-spirals.cljs
; loosely based on some python code written by Peter Derlien, University of Sheffield, March 2013
; Draws spiralling patterns of circles using the Golden Angle.
(ns chroma-spirals.demo
(:use [monet.canvas :only [fill-style fill-rect circle rotate translate composition-operation]]
[monet.core :only [animation-frame]]
[enchilada :only [ctx canvas]]
[chroma-spirals.color-chart :only [color-seq]]
[jayq.core :only [show]]
@rm-hull
rm-hull / heighways-dragon.cljs
Last active December 15, 2015 15:59
The Heighway dragon (also known as the Harter–Heighway dragon or the Jurassic Park dragon) was first investigated by NASA physicists John Heighway, Bruce Banks, and William Harter. It was described by Martin Gardner in his Scientific American column Mathematical Games in 1967. It is a self-similar fractal curve, which can be approximated by recu…
(ns lindenmayer-systems.demo
(:use [turtle.core :only [draw!]]
[turtle.renderer.canvas :only [->canvas]]
[enchilada :only [ctx canvas]]
[jayq.core :only [show]]))
(def dragon-seq
"Unfolding the dragon"
(letfn [(seq0 [x y]
(lazy-seq (cons (flatten x) (seq0 [x :right 90 y :fwd 20] [:fwd 20 x :left 90 y]))))]
@rm-hull
rm-hull / arnolds-cat-map.cljs
Last active December 16, 2015 20:19
Arnold's cat map is named after the mathematician Vladimir Arnold, who in the 1960s demonstrated the effect of repeatedly applying a linear transformation to an image of a cat (hence the name). Each animation frame transforms the pixels according to the pisano period of the largest dimension (width or height). Eventually the image will restore b…
(ns arnolds-cat-map.demo
(:use [monet.canvas :only [draw-image get-pixel composition-operation]]
[monet.core :only [animation-frame]]
[enchilada :only [ctx canvas proxy-request]]
[jayq.core :only [show]]
[jayq.util :only [wait]])
(:use-macros [dommy.macros :only [sel1 node]]))
(def cat-resources
[
@rm-hull
rm-hull / us-choropleth.cljs
Last active December 16, 2015 23:30
Example choropleth from http://keminglabs.com/c2/ex/choropleth/ demonstrating C2 integration. C2 is a Clojure and ClojureScript data visualization library that lets you declaratively create HTML and SVG markup based on data.
(ns us-choropleth.demo
(:use-macros [c2.util :only [bind!]])
(:use [jayq.core :only [show hide]]
[c2.core :only [unify]]
[c2.maths :only [extent floor]]
[c2.geo.core :only [geo->svg]]
[c2.geo.projection :only [albers-usa]]
[dataset.geo.us :only [states]]
[enchilada :only [canvas svg]])
(:require [c2.scale :as scale]