Skip to content

Instantly share code, notes, and snippets.

class TokenBucket(msgPerSecond:Long, bucketSize:Long) {
var prev = 0L
var tokens = bucketSize
def limit(func: => Any): Any = {
val current = System.currentTimeMillis
val delta = current-prev
prev = current
tokens += delta/1000.0 * msgPerSecond
void main(void) {
gl_FragColor = vec4(0,1.0,0,1.0);
}
@grazer
grazer / red circle shader
Last active March 8, 2023 23:41
red circle GLSL fragment shader
void main(void) {
// the center of the texture
vec2 center = vec2(iResolution.x/2.0,iResolution.y/2.0);
// current pixel location
vec2 loc = gl_FragCoord.xy;
// how far we are from the center
float radius=length(loc-center);
@grazer
grazer / GLSL Mandelbrot
Last active December 24, 2015 09:09
Mandelbrot Fractal GLSL
vec2 center = vec2(0.8,0);
float blue = 0.3;
void main() {
vec2 z, c;
float scale = 20.0/iGlobalTime; // zoom in
vec2 uv = gl_FragCoord.xy / iResolution.xy;
c.x = 1.3333 * (uv.x - 0.5) * scale - center.x;
c.y = (uv.y - 0.5) * scale - center.y;