Skip to content

Instantly share code, notes, and snippets.

@co3moz
Created March 13, 2016 11:08
Show Gist options
  • Save co3moz/08a1923f7ef586e13cd0 to your computer and use it in GitHub Desktop.
Save co3moz/08a1923f7ef586e13cd0 to your computer and use it in GitHub Desktop.
/*
co3moz
github.com/co3moz
draw => for y-finite solutions
drawYInfinite => for y-infinite solutions
press left button of mouse and move for move.
press right button of mouse and move for scale.
press shift and left button of mouse, move a little bit will reset to default position.
*/
precision highp float;
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
varying vec2 surfacePosition;
#define draw(function, r, g, b) if(distance(function(p.x - c.x), p.y - c.y) < 0.01) color = vec3(r, g, b)
#define drawYInfinite(function, r, g, b) if(distance(function(p.x - c.x), p.y - c.y) < abs(function(p.x - c.x) - function(p.x - c.x - 0.01))) color = vec3(r, g, b)
#define mouseTrack(function) if(distance(mouse.x * aspect.x, p.x) < 0.003 && function(p.x - c.x) - p.y + c.y > 0.0 && sin((c.y - p.y) * 200.0) < 0.1) color = vec3(0.5, 0.5, 0.5)
float y1(float x) {
return x;
}
float y2(float x) {
return sin(x);
}
float y3(float x) {
return sin(x + time);
}
void main(void) {
vec2 aspect = resolution.xy / min(resolution.x, resolution.y);
vec2 c = vec2(0.5) * aspect - surfacePosition * 1.5;
vec2 p = gl_FragCoord.xy / min(resolution.x, resolution.y);
vec3 color = vec3(0.0);
draw(y1, 1.0, 1.0, 1.0); // y1
draw(y2, 0.0, 0.0, 1.0); // y2
draw(y3, 0.0, 1.0, 1.0); // y3
mouseTrack(y3); // mouse tracking
if(distance(p.y, c.y) < 0.005 && sin((c.x - p.x) * 200.0) < 0.1) color = vec3(0.0, 1.0, 0.0); // horizontal
if(distance(p.x, c.x) < 0.005 && sin((c.y - p.y) * 200.0) < 0.1) color = vec3(1.0, 0.0, 1.0); // vertical
gl_FragColor = vec4(color, 1.0);
}
@co3moz
Copy link
Author

co3moz commented Mar 13, 2016

image

@co3moz
Copy link
Author

co3moz commented Mar 19, 2016

float y1(float x) {
    return fract(x + time) * sin(x - fract(x + time));
}

@co3moz
Copy link
Author

co3moz commented Mar 23, 2016

float wave1(float x) {
    return fract(pow(fract(x + time), fract(x + time))) + sin(time) / 10.0;
}

float wave2(float x) {
    return fract(pow(fract(x), fract(x)));
}

float wave3(float x) {
    return fract(pow(fract(x + time + 0.5), fract(x + time + 0.5))) + cos(time) / 10.0;
}

image

@co3moz
Copy link
Author

co3moz commented Mar 23, 2016

float fn(float x) {
    return length(vec3(x) * mat3(x, cos(time * 10.0), tan(time), 1.0, 0.0, -1.0, -0.0, -1.0, 0.0));
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment