Skip to content

Instantly share code, notes, and snippets.

@rm-hull
rm-hull / psychedelic-animation.cljs
Last active May 14, 2019 06:23
ClojureScript re-implementation of a js1k.com runner up, originally by Piotr Stosur: "Animated fractal shapes (mainly rotating spirals) similar to CEVs after taking psychedelic/dissociative drugs. :P Based on copying previous frame into 4 smaller fragments (once per frame, no other kind of iterations) so it's much faster than per-pixel fractal g…
; rewritten in Clojurescript from javascript (originally by Piotr Stosur: http://js1k.com/2013-spring/demo/1431)
(ns psychedelic-animation.demo
(:use [enchilada :only [canvas svg ctx]]
[jayq.core :only [show hide]]
[monet.core :only [animation-frame]]
[monet.canvas :only [fill-style fill-rect draw-image rotate translate]]))
(show canvas)
(hide svg)
@rm-hull
rm-hull / soundflower-vic20.cljs
Last active December 17, 2015 00:38
Experimental music from very short /ClojureScript/ programs. See http://www.youtube.com/watch?v=GtQdIYUtAHg
(ns soundflower-vic20.demo
(:use-macros [dommy.macros :only [sel1 node]])
(:use [jayq.core :only [show hide]]
[enchilada :only [canvas svg]]
[dommy.core :only [insert-after!]]
[dommy.template :only [->node-like]]))
(hide canvas)
(hide svg)
s = 640, t = 480, u = Math, v = [
[0, 0, 0],
[255, 0, 0],
[255, 255, 255]
], q = document, k = 'center', x = q.createElement('input');
c.width = s;
c.height = t;
b.style.textAlign = x.style.textAlign = k;
var k, l, w = function (b) {
a.fillStyle = '#000';
@rm-hull
rm-hull / world-choropleth.cljs
Last active December 17, 2015 02:38
Example world choropleth demonstrating C2 integration, using Albers equal-area conic projection (http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html). C2 is a Clojure and ClojureScript data visualization library that lets you declaratively create HTML and SVG markup based on data.
(ns world-choropleth.demo
(:use-macros [c2.util :only [bind!]])
(:use [jayq.core :only [show hide]]
[c2.core :only [unify]]
[c2.geo.core :only [geo->svg]]
[c2.geo.projection :only [albers]]
[dataset.geo.world :only [countries]]
[enchilada :only [canvas svg]])
(:require [c2.scale :as scale]))
@rm-hull
rm-hull / quadratic-residues.cljs
Last active June 30, 2016 22:24
Exploring quadratic residues and fixed points with clock arithmetic and digraphs, in Clojurescript with force-directed graph layout provided by _arbor.js_. Inspired, in part, by http://pi3.sites.sheffield.ac.uk/tutorials/week-8. Defaults to 51 data points, which produces a pleasing digraph, but add a _num=X_ param to the URL to show different ri…
(ns quadratic-residue.demo.core)
(defn follow [lookup-table]
(fn [n]
(loop [k n
edges {}]
(let [next-k (lookup-table k)]
(if (edges next-k)
edges
(recur next-k (assoc edges k next-k)))))))
(ns mod-test.example)
; Something very odd is happening with mod when used with some string values whose content happen to be numbers.
;
; Clearly it shouldn't be called with a string, but this doesn't appear to affect modulo "1", "3", "9", "11"
;
; when the rem function is used with string numbers is not affected in the same way, and appears to operate consistently.
;
; Is this some funky gotcha with javascript, or is it a side-effect of the way clojurescript implements mod?
;
@rm-hull
rm-hull / penrose-tiling.cljs
Last active July 5, 2016 19:48
A Penrose tiling is a non-periodic tiling generated by an aperiodic set of prototiles. Penrose tilings are named after mathematician and physicist Roger Penrose who investigated these sets in the 1970s. This gist describes the tiling in terms of a rewriting grammar (an 'L-system') and renders using a turtle (https://github.com/rm-hull/turtle) on…
(ns lindenmayer-systems.demo
(:use [turtle.core :only [draw!]]
[turtle.renderer.vector :only [->svg]]
[turtle.renderer.canvas :only [->canvas]]
[enchilada :only [ctx canvas svg]]
[dommy.core :only [set-html! insert-after! replace! hide! show!]]
[jayq.core :only [show]])
(:use-macros [dommy.macros :only [sel1]]))
(def L '(:left 36))
@rm-hull
rm-hull / autostereogram.cljs
Last active December 18, 2015 05:59
A SIRD (Single Image Random Dot) diagram, a.k.a. 'Magic Eye' or autostereogram is a single-image stereogram (SIS), designed to create the visual illusion of a three-dimensional (3D) scene within the human brain from an external two-dimensional image. In order to perceive 3D shapes in these autostereograms, one must overcome the normally automati…
(ns autostereogram.demo
(:use [monet.canvas :only [draw-image]]
[enchilada :only [canvas ctx proxy-request]]
[jayq.core :only [show]]
[jayq.util :only [log]]))
(def greens
(map #(vector 0x30 % 0x30 0xFF) (range 0xCF)))
(defn random-data [w h colors]
(ns n01se.externs-for-cljs
(:require [clojure.java.io :as io]
[cljs.compiler :as comp]
[cljs.analyzer :as ana]))
(defn read-file [file]
(let [eof (Object.)]
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))]
(vec (take-while #(not= % eof)
(repeatedly #(read stream false eof)))))))
@rm-hull
rm-hull / DHT.c
Last active December 18, 2022 15:40
// How to access GPIO registers from C-code on the Raspberry-Pi
// Example program
// 15-January-2012
// Dom and Gert
//
/*
$ wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.8.tar.gz
$ tar -zxvf bcm2835-1.8.tar.gz
$ cd bcm2835-1.8