Skip to content

Instantly share code, notes, and snippets.

@merttoka
Last active October 12, 2016 18:03
Show Gist options
  • Save merttoka/f7feecf1f5d046cbd144936f3a304365 to your computer and use it in GitHub Desktop.
Save merttoka/f7feecf1f5d046cbd144936f3a304365 to your computer and use it in GitHub Desktop.
MAT200C HW1
<html>
<script type="text/javascript" src="https://rawgit.com/patriciogonzalezvivo/glslCanvas/master/build/GlslCanvas.js"></script>
<body>
<canvas class="glslCanvas" data-fragment="
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float rand(float x){
return fract(sin(x) * 999.);
}
float stepRandom(float x){
return rand( floor( x ) );
}
float smoothStep(float x){
return ((x) * (x) * ((x - 1.) / 0.5 * -1. + 1.));
}
float smoothSaw(float x){
return smoothStep( fract( x ) );
}
float smoothNoise(float x){
return (((stepRandom( x )) * (smoothSaw( x ))) + ((stepRandom( (x - 1.) )) * (smoothSaw( (x - 1.) ) * -1. + 1.)));
}
float fractalNoise(float x){
return (smoothNoise( x ) +
smoothNoise( x / 0.5 ) * 0.5 +
smoothNoise( x / 0.333 ) * 0.333 +
smoothNoise( x / 0.25 ) * 0.25 +
smoothNoise( x / 0.2 ) * 0.2 +
smoothNoise( x / 0.167 ) * 0.167 +
smoothNoise( x / 0.143 ) * 0.143) * 0.5;
}
float F1(float x, float y){
return sin(x*y*x*2.)*sin(x*x*3.)+sqrt(x*x+y*y)+x*x*x-y*y;
}
float F2(float x, float y){
return sin(x*y*x*2.)+sqrt(x*x+y*y)+x*x-y*y;
}
float F3(float x, float y){
return sin(x*y*x)*sin(x*x*3.)+sqrt(x*x+y*y)+x*x*x-y*y;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy*2.-1.;
st.x *= u_resolution.x/u_resolution.y;
vec2 n_mouse = u_mouse.xy/u_resolution.xy;
float r = fractalNoise(F1(st.x, st.y)*(50.+n_mouse.x*n_mouse.y)*smoothNoise(u_time));
float g = fractalNoise(F2(st.x, st.y)*(40.+n_mouse.x*n_mouse.y)*smoothNoise(u_time))*abs(sin(u_time))/.5;
float b = fractalNoise(F3(st.x, st.y)*(30.+n_mouse.x*n_mouse.y)*smoothNoise(u_time))*sin(u_time)/.5;
gl_FragColor = vec4(r,g,b,1.0);
}
"
width="1000" height="800"> </canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment