Skip to content

Instantly share code, notes, and snippets.

@rm-hull
rm-hull / _corewar.cljs
Last active August 29, 2015 14:07
An _in-progress_ implementation of A.K.Dewdney's "Corewar" in ClojureScript. There are many things that don't quite work properly yet, such as handling when a redcode assembly program is terminated. By default four (non-selectable) redcode programs are pitted against each other - at some point these will be loaded at random from a hill. The inst…
(ns corewar.gui
(:require
[clojure.string :as str]
[jayq.core :refer [show]]
[enchilada :refer [canvas ctx canvas-size]]
[corewar.memory :as mem]
[corewar.assembler :as asm]
[corewar.instruction-set :as instr]
[corewar.virtual-machine :as vm]
[corewar.redcode :as red]
@rm-hull
rm-hull / rotating-spiral.cljs
Last active August 29, 2015 14:07
A common optical illusion that is a static image, but appears to move as you look at different parts of the image - first popularised by Akiyoshi Kitaoka, Ritsumeikan University (http://www.ritsumei.ac.jp/~akitaoka/index-e.html). This gist based on a processing-js script at http://www.openprocessing.org/sketch/131928.
(ns enchilada.rotating-spiral
(:require
[jayq.core :refer [show]]
[enchilada :refer [ctx canvas]]
[big-bang.core :refer [big-bang]]
[monet.canvas :refer [fill-style fill ellipse rotate translate save restore fill-rect]]))
(def initial-state {
:angle 0
:radius 600
@rm-hull
rm-hull / introrx.md
Last active August 29, 2015 14:08 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@rm-hull
rm-hull / INSTRUCTIONS.md
Last active August 29, 2015 14:08
Experimenting with some basic image dithering, in the style of 10 PRINT (see also http://programming-enchiladas.destructuring-bind.org/rm-hull/4bf4ce47c4f615e9cfe6), the idea was inspired by _bitcraft's_ OpenProcessing version: http://openprocessing.org/sketch/82451.
  • Move the mouse horizontally to change threshold point
  • Click the mouse to alter the resolution
  • Press the 'C' key to cycle between [10-Print, Greyscale, Inverse, Solarize]
  • Refresh the page for a different image (chosen at random)
@rm-hull
rm-hull / BOYS-SURFACE.md
Last active August 29, 2015 14:09
In 1901, Werner Boy (under direction from David Hilbert) discovered a non-orienting surface which is a self-intersecting immersion of the real projective plane in 3-dimensional space. The surface is obtained by sewing a Möbius strip to the edge of a disk, given by the parametric equations below.

$\mathbb{R}^3$ Parametric equations

$x = {\sqrt 2 \cos^2 v \cos (2u) + \cos u \sin (2v) \over 2 - \alpha \sqrt 2 \sin (3u) \sin (2v)}$

$y = {\sqrt 2 \cos^2 v \sin (2u) - \sin u \sin (2v) \over 2 - \alpha \sqrt 2 \sin (3u) \sin (2v)}$

$z = {3 \cos^2 \over 2 - \alpha \sqrt 2 \sin (3u) \sin (2v)}$

for $u \in [-\pi /2, \pi/2]$ and $v \in [0, \pi]$

@rm-hull
rm-hull / REACTION-DIFFUSION-MORPHOGENESIS.md
Last active August 29, 2015 14:09
In 1952, Alan Turing wrote a paper proposing a reaction–diffusion model as the basis of the development of patterns such as the spots and stripes seen in animal skin. Mathematically, reaction–diffusion systems take the form of semi-linear parabolic partial differential equations. By iteration 300, it should be clear how the two elements have sep…
@rm-hull
rm-hull / slinky.cljs
Created December 5, 2014 00:41
A slinky - move the cursor over the grey area and the slinky will follow. Based on _Jean-no_'s http://openprocessing.org/sketch/173277
(ns enchilada.slinky
(:require
[jayq.core :refer [show css]]
[enchilada :refer [ctx canvas canvas-size]]
[big-bang.core :refer [big-bang]]
[big-bang.events.browser :refer [offset-coords]]
[monet.canvas :refer [stroke-style stroke fill-style fill fill-rect arc begin-path close-path]]))
(def screen-area
(let [[w h] (canvas-size)]
@rm-hull
rm-hull / color-vortex.cljs
Created December 6, 2014 00:44
Faux rotating torus testing alpha channels with HSV->RGB color conversion in https://github.com/rm-hull/inkspot. Click the canvas area to toggle between solid color and wireframe. Inspiration: Jerome Herr's http://openprocessing.org/sketch/160303
(ns enchilada.color-vortex
(:require
[jayq.core :refer [show css]]
[enchilada :refer [ctx canvas canvas-size]]
[inkspot.color :refer [coerce red green blue]]
[inkspot.converter :refer [hsv->rgb]]
[big-bang.core :refer [big-bang]]
[big-bang.events.browser :refer [offset-coords]]
[monet.canvas :refer [stroke-style stroke fill-style fill fill-rect
ellipse save restore translate]]))
@rm-hull
rm-hull / aspirational-vanity-product.cljs
Last active August 29, 2015 14:11
I found myself in a popular electronics emporium recently; I was transfixed by the on-screen advertisements of a certain manufacturer, which seemed to encourage consumer conformity and consistency - and felt driven to reproduce it's iconography crudely here. See http://bit.ly/1Aqmz3g
(ns enchilada.aspirational-vanity-product
(:require
[enchilada :refer [ctx canvas]]
[big-bang.core :refer [big-bang]]
[jayq.core :refer [show attr css]]
[monet.canvas :refer [begin-path move-to line-to clear-rect
stroke stroke-style stroke-width stroke-cap
save restore translate rotate]]))
(def two-pi (* 2 Math/PI))
@rm-hull
rm-hull / wireframe-extrusion.cljs
Last active August 29, 2015 14:15
The humble cone contains the answers to fundamental questions about the universe. But not _this_ one, its just pixels on the screen. What is mildly interesting about this cone is the way it is generated - a 2D polyline forms the bottom side and hypotenuse of a right-handed triangle in the X-Y plane. This flat shape is then "extruded" into three …
(ns enchilada.wireframe-extrusion
(:require
[enchilada :refer [canvas ctx value-of canvas-size]]
[wireframes.renderer.canvas :refer [draw-solid ->canvas]]
[wireframes.renderer.color :refer [wireframe solid]]
[wireframes.transform :refer [point combine rotate scale translate degrees->radians]]
[wireframes.shapes.primitives :refer [extrude make-line make-point transform-shape center-at-origin]]
[jayq.core :refer [show]]
[inkspot.color :refer [coerce]]
[monet.canvas :refer [get-context fill-rect fill-style]]