This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
/* | |
* This work is free. You can redistribute it and/or modify it under the | |
* terms of the Do What The Fuck You Want To Public License, Version 2, | |
* as published by Sam Hocevar. See the COPYING file for more details. | |
*/ | |
/* | |
* Easing Functions - inspired from http://gizma.com/easing/ | |
* only considering the t value for the range [0, 1] => [0, 1] | |
*/ | |
EasingFunctions = { |
/* | |
These are the helper functions to store and to restore a 2D vector with a custom 16 floating point precision in a texture. | |
The 16 bit are used as follows: 1 bit is for the sign, 4 bits are used for the exponent, the remaining 11 bit are for the mantissa. | |
The exponent bias is asymmetric so that the maximum representable number is 2047 (and bigger numbers will be cut) | |
the accuracy from 1024 - 2047 is one integer | |
512-1023 it's 1/2 int | |
256-511 it's 1/4 int and so forth... | |
between 0 and 1/16 the accuracy is the highest with 1/2048 (which makes 1/32768 the minimum representable number) |
# sleepy flower girl | |
(◡ ‿ ◡ ✿) | |
# y u no | |
ლ(ಠ益ಠლ) | |
# smiling breasts | |
(^人^) | |
# flipping tables |
Please consider using http://lygia.xyz instead of copy/pasting this functions. It expand suport for voronoi, voronoise, fbm, noise, worley, noise, derivatives and much more, through simple file dependencies. Take a look to https://github.com/patriciogonzalezvivo/lygia/tree/main/generative
float rand(float n){return fract(sin(n) * 43758.5453123);}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
/** | |
* GOZORK Text Adventure Game | |
* by apoc <http://apoc.cc> | |
* | |
* Inspired by the infamous beginning of Zork I. | |
* Reading the source will obviously spoil the game. | |
* The goal is to somehow kill the troll. | |
* Oh yeah and: This is my first GO program! Which would be | |
* my perfect excuse for the bad code quality1! | |
* Here is a solution/transcript: |
let isFunction = function(obj) { | |
return typeof obj == 'function' || false; | |
}; | |
class EventEmitter { | |
constructor() { | |
this.listeners = new Map(); | |
} | |
addListener(label, callback) { | |
this.listeners.has(label) || this.listeners.set(label, []); |
(defn grow [pos rot points len] | |
(let [[x y z] (last rot) ;; :( no M33 and no (g/rotate-xyz _ (vec3 x y z)) | |
corners (map #(-> % (g/rotate-x x) (g/rotate-y y) (g/rotate-z z) (g/+ (last pos))) | |
[(vec3 0 0 0) (vec3 -1 0 0) (vec3 0 -1 0) (vec3 0 1 0) | |
(vec3 -1 0 len) (vec3 0 -1 len) (vec3 0 1 len) (vec3 0 0 len)])] | |
[(conj (pop pos) (last corners)) | |
rot | |
(conj points (map gu/tessellate-3 (g/faces (apply cub/cuboid corners))))])) | |
(defn build-lsystem [l-system angle len] |
(defn branch | |
"A recursive branching tree structure with half-cylinder flowers." | |
[level] | |
(if (= 0 level) | |
[(length 1.5) cylinder] | |
[(angle (fn [_] (m/random 3 5))) ry- | |
(length (fn [t] (* (m/random 0.75 1.5) (or (:last-length t) 1.5)))) | |
(map (fn [[a b]] (concat (take 8 (cycle [a b])) (branch (dec level)))) | |
[[ry line] [ry- line] [rx line] [rx- line]])])) |