Finishing random

pull/14/head
Patricio Gonzalez Vivo 9 years ago
parent 7c9f1fbc45
commit d83ca372bb

@ -20,9 +20,9 @@
<ul class="navigationBar" >
<li class="navigationBar" onclick="previusPage()">&lt; &lt; Previous</li>
<li class="navigationBar" onclick="homePage()"> Home </li>
<li class="navigationBar" onclick="nextPage()">Next &gt; &gt;</li>
</ul>';
include($path."/footer.php");
?>
<!-- <li class="navigationBar" onclick="nextPage()">Next &gt; &gt;</li> -->

@ -31,18 +31,19 @@ float char(vec2 st, float n){
vec2 ipos = floor(st*grid);
vec2 fpos = fract(st*grid);
float digit[10];
digit[0] = 31600.;
digit[1] = 9363.0;
digit[2] = 31184.0;
digit[3] = 31208.0;
digit[4] = 23525.0;
digit[5] = 29672.0;
digit[6] = 29680.0;
digit[7] = 31013.0;
digit[8] = 31728.0;
digit[9] = 31717.0;
float pct = bin(ipos, digit[int(floor(mod(n,10.)))]);
n = floor(mod(n,10.));
float digit = 0.0;
if (n < 1. ) { digit = 31600.; }
else if (n < 2. ) { digit = 9363.0; }
else if (n < 3. ) { digit = 31184.0; }
else if (n < 4. ) { digit = 31208.0; }
else if (n < 5. ) { digit = 23525.0; }
else if (n < 6. ) { digit = 29672.0; }
else if (n < 7. ) { digit = 29680.0; }
else if (n < 8. ) { digit = 31013.0; }
else if (n < 9. ) { digit = 31728.0; }
else if (n < 10. ) { digit = 31717.0; }
float pct = bin(ipos, digit);
vec2 borders = vec2(1.);
// borders *= step(0.01,fpos.x) * step(0.01,fpos.y); // inner

@ -0,0 +1,110 @@
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform float u_time;
float random(in float x){ return fract(sin(x)*43758.5453); }
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
float bin(vec2 ipos, float n){
float remain = mod(n,33554432.);
for(float i = 0.0; i < 25.0; i++){
if ( floor(i/3.) == ipos.y && mod(i,3.) == ipos.x ) {
return step(1.0,mod(remain,2.));
}
remain = ceil(remain/2.);
}
return 0.0;
}
float char(vec2 st, float n){
st.x = st.x*2.-0.5;
st.y = st.y*1.2-0.1;
vec2 grid = vec2(3.,5.);
vec2 ipos = floor(st*grid);
vec2 fpos = fract(st*grid);
n = floor(mod(n,10.));
float digit = 0.0;
if (n < 1. ) { digit = 31600.; }
else if (n < 2. ) { digit = 9363.0; }
else if (n < 3. ) { digit = 31184.0; }
else if (n < 4. ) { digit = 31208.0; }
else if (n < 5. ) { digit = 23525.0; }
else if (n < 6. ) { digit = 29672.0; }
else if (n < 7. ) { digit = 29680.0; }
else if (n < 8. ) { digit = 31013.0; }
else if (n < 9. ) { digit = 31728.0; }
else if (n < 10. ) { digit = 31717.0; }
float pct = bin(ipos, digit);
vec2 borders = vec2(1.);
// borders *= step(0.01,fpos.x) * step(0.01,fpos.y); // inner
borders *= step(0.0,st)*step(0.0,1.-st); // outer
return step(.5,1.0-pct) * borders.x * borders.y;
}
float grid(vec2 st, float res){
vec2 grid = fract(st*res);
return 1.-(step(res,grid.x) * step(res,grid.y));
}
float box(in vec2 st, in vec2 size){
size = vec2(0.5) - size*0.5;
vec2 uv = smoothstep(size,
size+vec2(0.001),
st);
uv *= smoothstep(size,
size+vec2(0.001),
vec2(1.0)-st);
return uv.x*uv.y;
}
float cross(in vec2 st, vec2 size){
return clamp(box(st, vec2(size.x*0.5,size.y*0.125)) +
box(st, vec2(size.y*0.125,size.x*0.5)),0.,1.);
}
void main(){
vec2 st = gl_FragCoord.st/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec3 color = vec3(0.0);
// Grid
vec2 grid_st = st*300.;
color += vec3(0.5,0.,0.)*grid(grid_st,0.01);
color += vec3(0.2,0.,0.)*grid(grid_st,0.02);
color += vec3(0.2)*grid(grid_st,0.1);
// Crosses
vec2 crosses_st = st + .5;
crosses_st *= 3.;
vec2 crosses_st_f = fract(crosses_st);
color *= 1.-cross(crosses_st_f,vec2(.3,.3));
color += vec3(.9)*cross(crosses_st_f,vec2(.2,.2));
// Digits
vec2 digits_st = mod(st*60.,20.);
vec2 digits_st_i = floor(digits_st);
if (digits_st_i.y == 1. &&
digits_st_i.x > 0. && digits_st_i.x < 6. ) {
vec2 digits_st_f = fract(digits_st);
float pct = random(digits_st_i+floor(crosses_st)+floor(u_time*20.));
color += vec3(char(digits_st_f,100.*pct));
} else if (digits_st_i.y == 2. &&
digits_st_i.x > 0. && digits_st_i.x < 8. ) {
vec2 digits_st_f = fract(digits_st);
float pct = random(digits_st_i+floor(crosses_st)+floor(u_time*20.));
color += vec3(char(digits_st_f,100.*pct));
}
gl_FragColor = vec4( color , 1.0);
}

@ -0,0 +1,62 @@
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform float u_time;
float random(in float x){ return fract(sin(x)*43758.5453); }
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
float grid(vec2 st, float res){
vec2 grid = fract(st*res);
return 1.-(step(res,grid.x) * step(res,grid.y));
}
float box(in vec2 st, in vec2 size){
size = vec2(0.5) - size*0.5;
vec2 uv = smoothstep(size,
size+vec2(0.001),
st);
uv *= smoothstep(size,
size+vec2(0.001),
vec2(1.0)-st);
return uv.x*uv.y;
}
float cross(in vec2 st, vec2 size){
return clamp(box(st, vec2(size.x*0.5,size.y*0.125)) +
box(st, vec2(size.y*0.125,size.x*0.5)),0.,1.);
}
void main(){
vec2 st = gl_FragCoord.st/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec3 color = vec3(0.0);
// Grid
vec2 grid_st = st*300.;
color += vec3(0.5,0.,0.)*grid(grid_st,0.01);
color += vec3(0.2,0.,0.)*grid(grid_st,0.02);
color += vec3(0.2)*grid(grid_st,0.1);
// Crosses
vec2 crosses_st = st + .5;
crosses_st *= 3.;
vec2 crosses_st_f = fract(crosses_st);
color *= 1.-cross(crosses_st_f,vec2(.3,.3));
color += vec3(.9)*cross(crosses_st_f,vec2(.2,.2));
// Digits
vec2 blocks_st = floor(st*6.);
float t = u_time*.8+random(blocks_st);
float time_i = floor(t);
float time_f = fract(t);
color.rgb += step(0.9,random(blocks_st+time_i))*(1.0-time_f);
gl_FragColor = vec4( color , 1.0);
}

@ -20,8 +20,9 @@
<ul class="navigationBar" >
<li class="navigationBar" onclick="previusPage()">&lt; &lt; Previous</li>
<li class="navigationBar" onclick="homePage()"> Home </li>
<li class="navigationBar" onclick="nextPage()">Next &gt; &gt;</li>
</ul>';
include($path."/footer.php");
?>
<!-- <li class="navigationBar" onclick="nextPage()">Next &gt; &gt;</li> -->

@ -27,7 +27,7 @@ This is a gentle step-by-step guide through the abstract and complex universe of
* [Patterns](09/)
* Generative designs
* Random
* [Random](10/)
* Noise
* Fractional brownian motion
* Fractals

@ -60,6 +60,14 @@ The following is a list of examples present in this book.
- [Truchet](../edit.html#09/truchet.frag)
- [Deco](../edit.html#09/deco.frag)
- [I Ching](../edit.html#09/iching-01.frag)
* [Random](../10/)
- [1D Random](../edit.html#10/1d-random.frag)
- [2D Random](../edit.html#10/2d-random.frag)
- [Random Mosaic](../edit.html#10/2d-random-mosaic.frag)
- [Random Dots](../edit.html#10/2d-random-dots.frag)
- [Random Truchet](../edit.html#10/2d-random-truchet.frag)
- Ikeda's style: [test pattern](../edit.html#10/ikeda-00.frag), [data path](../edit.html#10/ikeda-03.frag) and [data defrag](../edit.html#10/ikeda-04.frag).
### Advance

Loading…
Cancel
Save