Skip to content

Instantly share code, notes, and snippets.

@rm-hull
rm-hull / PARAMETRIC-EQUATIONS.md
Last active August 29, 2015 13:55
An animated render of a parametric equation in ClojureScript with big-bang. A curve is swept out where the trajectory of a point is usually represented by a parametric equation with the time as parameter.

Parametric Equations

Using:

x

y

Where t increases monotonically, and k can be varied with the slider below, the (x,y) co-ordinates sweep out the curve of a distressed Cardioid. When k = 0.5 the curve sweeps out a perfect Cardioid.

@rm-hull
rm-hull / BIG-BANG-RPS.md
Last active October 19, 2024 21:48
A Rock-Paper-Scissors game in ClojureScript, using core.async and big-bang.

Rock Paper Scissors

A familiar game implemented using Big-Bang, a ClojureScript library inspired by Racket's big-bang. It abstracts the GUI event-loop into a component based system, allowing self-contained big-bang 'worlds' to communicate over core.async channels, in a reactive CSP style.

In this example, the main file builds some DOM elements and fetches various SVG assets for inclusion on the page. Then, three big-bang components are initialized:

@rm-hull
rm-hull / big-bang-simple-animation.cljs
Last active January 4, 2016 12:49
Simple animation demo for big-bang
(ns big-bang.example.cat-animation
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [enchilada :refer [canvas ctx canvas-size proxy-request]]
[cljs.core.async :as async :refer [<!]]
[dataview.loader :refer [fetch-image]]
[big-bang.core :refer [big-bang!]]
[jayq.core :refer [show attr]]))
(defn increment-and-wrap [x]
(if (< x 800)
@rm-hull
rm-hull / BIGBANG_MOUSE_DEMO.md
Last active January 4, 2016 11:49
Demonstration of using Big-Bang: reactively capturing a stream of mouse move events

Move the mouse around to see a demonstration of Big-Bang mouse-move event handling. Big-bang uses core.async to handle events in a reactive manner, dispatching to relevant state-handlers so that manipulating state occurs in a purely functional manner.

In the code below, the update function is only fired when a new mouse-move event is delivered to big-bang's event loop. It is passed the event and the current 'world-state', of which it returns a modified version. The render function is invoked on a javascript requestAnimationFrame() callback only if the world state has been changed.

Big-bang is a new library, and is subject to ongoing change, but supports a flexible architecture which allows:

  • Reactive handling of browser events
  • Interval timer for periodic firings
  • Interaction with any DOM elements (originally targetted against <canvas>, but as demonstrated below there is no restriction)
  • Interaction with the outs
@rm-hull
rm-hull / OM_MOUSE_DEMO.md
Last active January 4, 2016 11:49
Demonstration of using Swannodette's OM: reactively capturing a stream of mouse move events.
#include <nall/platform.hpp>
#include <nall/stdint.hpp>
using namespace nall;
extern "C" {
void filter_size(unsigned&, unsigned&);
void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned);
};
enum {
@rm-hull
rm-hull / blocks.cljs
Last active April 2, 2025 14:46
Core.async example from Timothy Baldridge's Clojure/Conj 2013 talk: http://youtu.be/enwIIGzhahw, demonstrating 4800 'green' threads. Code modified from: https://github.com/halgari/clojure-conj-2013-core.async-examples/blob/master/src/clojure_conj_talk/core.clj#L585
(ns clojure-conj-talk.core
(:use [enchilada :only [canvas ctx canvas-size]]
[monet.canvas :only [fill-style fill-rect]]
[jayq.core :only [show]])
(:require [cljs.core.async :refer [<! >! chan timeout]])
(:require-macros [cljs.core.async.macros :as m :refer [go]]))
(def colors
(rand-nth [
[
@rm-hull
rm-hull / EARTH.md
Last active March 11, 2016 02:22
ClojureScript & WebGL integration by way of PhiloGL.js - an interactive spheroid. Modified from https://github.com/tsaastam/cljs-webgl-example
@rm-hull
rm-hull / sin.cljs
Last active December 30, 2015 01:49 — forked from martintrojer/sin.cljs
Sample core.async - see it running in the browser: http://programming-enchiladas.destructuring-bind.org/rm-hull/7758795
(ns async-test.sinewave.core
(:require [cljs.core.async :refer [<! >! chan timeout]])
(:require-macros
[cljs.core.async.macros :as m :refer [go]]))
(defn sin-vals [offset]
(map #(Math/sin %) (iterate (partial + 0.1) offset)))
(let [events (chan)]
@rm-hull
rm-hull / boids.cljs
Last active December 26, 2015 11:39
Boids, originally written by Craig Reynolds in 1986, is an artificial live program which simulates flocking birds (but in this case just in 2D). It is an example of emergent behaviour; that is, the complexity of Boids arises from the interaction of individual agents adhering to a set of simple rules, (i) separation: steering to avoid crowding lo…
(ns boids
(:use [enchilada :only [canvas ctx value-of canvas-size]]
[jayq.core :only [show]]
[monet.core :only [animation-frame]]
[monet.canvas :only [save restore
begin-path move-to line-to close-path
stroke stroke-style fill fill-rect fill-style
rotate translate]]
[boids.rules :only [step make-boid]])
(:require [boids.vector :refer [heading]]))