Skip to content

Instantly share code, notes, and snippets.

View ztellman's full-sized avatar
💭
boiling the ocean

Zach Tellman ztellman

💭
boiling the ocean
View GitHub Profile
=> (pprint fragment-shader)
(let [marble
(-> pos .x (* 2.0) (+ noise) sin abs)
marble-color
(float4 0.8 0.7 0.7 1.0)
vein-color
(float4 0.2 0.15 0.1 1.0)
mixed-color
(mix vein-color marble-color (pow marble 0.5))]
(set! :frag-color (* intensity mixed-color))))
(use 'penumbra.compute 'penumbra.app)
(with-gl
(defmap generate
(let [s (sin :index)]
(normalize
(float3 s (* 3.0 (cos :index)) (/ (* s s) 2.0)))))
(defreduce find-max
(max %1 %2))
(dotimes [_ 100]
(use 'penumbra.opengl)
(require '(penumbra [app :as app]))
(def max-iterations 100)
(def num-paths 50)
(defn ikeda [x y u]
(iterate
(fn [[x_n y_n]]
(let [t_n (- 0.4 (/ 6 (+ 1 (* x_n x_n) (* y_n y_n))))]

Kinetic Energy

(defmap kinetic-energy
    (let [m %1, v %2]
      (float3 (* 0.5 m (dot v v)))))
#extension GL_ARB_texture_rectangle : enable
varying vec2 __coord;
uniform vec2 __dim;
void main()
(defmap initialize-fractal
(float3 (mix upper-left lower-right (/ :coord :dim)) 0))
(defmap iterate-fractal
(let [val %
z (.xy val)
c (mix upper-left lower-right (/ :coord :dim))
iterations (.z val)]
(? (< 4.0 (dot z z))
val
(float3
(+ c
(float2
(defmap color-fractal
(let [val %
z (.xy val)
n (.z val)
escape (/ n (float max-iterations))]
(? (< 4.0 (dot z z))
(color3 escape escape (mix 0.2 1.0 escape))
(color3 0.0 0.0 0.0))))
(ns draw-order (:use [penumbra.opengl] [penumbra.window]))
(defn- init [state]
(enable :depth-test)
(ortho-view 0 0 640 480 -1 1)
(scale 1 1 -1)
state)
(defn draw-square [x y w h]
(draw-quads
;; Draw 1000 moving rects on the screen.
;; With penumbra, I get about 50 fps on a dual-core machine with an nVidia 8800.
;; On a single-core machine with an ATI Radeon X300, I get about 2 fps.
(ns examples.squares
(:use [clojure.contrib.def :only (defvar-)]
[clojure.contrib.seq-utils :only (flatten)]
[penumbra opengl window]))
(defstruct rect :offset :size :depth :veloc :color)
(ns example.wiki.triangle1
(:use [penumbra.opengl])
(:require [penumbra.app :as app]))
(defn reshape [[x y width height] state]
(frustum-view 60.0 (/ (double width) height) 1.0 100.0)
(load-identity)
state)
(defn display [[delta time] state]