Skip to content

Instantly share code, notes, and snippets.

View nasser's full-sized avatar
🛰️
save-lisp-and-die

Ramsey Nasser nasser

🛰️
save-lisp-and-die
View GitHub Profile
(ns user
(:use arcadia.core)
(:import [UnityEngine
Vector3
Time
Gizmos
Color
Debug
Plane
Mathf]))
<meta charset="utf-8">
<script src="js/jquery.js"></script>
<script src="js/jqconsole.js"></script>
<script src="js/sugar.js"></script>
<script src="js/peg.js"></script>
<script src="js/plt.js"></script>
<script type="text/javascript">
// uncomment next line to enable refresh
(ns shady
(:require [clojure.string :as s]))
;; analyze
;; break shader up into logical bits
;; right now just uniforms and main fn
(def analysis {'uniform (fn [out form]
(update-in out [:uniforms] conj form))
:default (fn [out form]
(update-in out [:fns :main] conj form))})
@nasser
nasser / bird.clj
Created November 11, 2014 05:36
Cleaned up code from the Nov 10 ClojureNYC Meetup
(ns flappy.bird
(:use arcadia.core)
(:import [UnityEngine Vector2 Input Time Vector3]))
(defcomponent Bird [^Vector2 force]
(Update [this]
;; flap on any keypress
(if Input/anyKeyDown
(.. this rigidbody2D
(AddForce force ForceMode2D/Impulse)))))
void main(void)
{
if(floor(gl_FragCoord.x) == floor(iMouse.x) ||
floor(gl_FragCoord.y) == floor(iMouse.y)) {
gl_FragColor = vec4(1.0);
} else {
gl_FragColor = vec4(0.0);
}
}
void main(void)
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
if(uv.y < 0.5 + 0.2*sin(20.0*uv.x + iGlobalTime)) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
} else {
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
}
}
void main(void)
{
float radius = 50.0;
float distanceToMouse = distance(gl_FragCoord.xy, iMouse.xy);
if(floor(distanceToMouse) == floor(radius)) {
gl_FragColor = vec4(1.);
} else {
gl_FragColor = vec4(0.);
}
}
void main(void)
{
vec2 px = gl_FragCoord.xy - mod(gl_FragCoord.xy, 10.);
vec2 uv = px / iResolution.xy * vec2(1., -1.);
gl_FragColor = texture2D(iChannel0, uv);
}
@nasser
nasser / tris.clj
Created November 15, 2014 00:21
triangle index functions
(defn tri-strip
([size] (tri-strip 0 size))
([start size]
(->> (range start (+ start size))
(partition 4 1)
(map (fn [[a b c d]] [a b c
c b d]))
flatten)))
(defn tri-fan
@nasser
nasser / meshes.clj
Created November 15, 2014 00:36
pure functional composable mesh generation
(import Selection MeshFilter Vector3 Mesh Mathf)
(use 'clojure.repl)
;; mesh updates
(defn update-mesh! [^MeshFilter mf vs tris]
(set! (.. mf mesh vertices)
(into-array Vector3 vs))
(set! (.. mf mesh triangles)
(into-array System.Int32 tris)))