random examples
This commit is contained in:
parent
d83ca372bb
commit
f90af2b3ef
|
|
@ -0,0 +1,80 @@
|
|||
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define PI 3.14159265359
|
||||
#define TWO_PI 6.28318530718
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
float shape(vec2 st, float N){
|
||||
st = st*2.-1.;
|
||||
float a = atan(st.x,st.y)+PI;
|
||||
float r = TWO_PI/N;
|
||||
return abs(cos(floor(.5+a/r)*r-a)*length(st));
|
||||
}
|
||||
|
||||
float box(vec2 st, vec2 size){
|
||||
return shape(st*size,4.);
|
||||
}
|
||||
|
||||
float rect(vec2 _st, vec2 _size){
|
||||
_size = vec2(0.5)-_size*0.5;
|
||||
vec2 uv = smoothstep(_size,_size+vec2(1e-4),_st);
|
||||
uv *= smoothstep(_size,_size+vec2(1e-4),vec2(1.0)-_st);
|
||||
return uv.x*uv.y;
|
||||
}
|
||||
|
||||
float hex(vec2 st, float a, float b, float c, float d, float e, float f){
|
||||
st = st*vec2(2.,6.);
|
||||
|
||||
vec2 fpos = fract(st);
|
||||
vec2 ipos = floor(st);
|
||||
|
||||
if (ipos.x == 1.0) fpos.x = 1.-fpos.x;
|
||||
if (ipos.y < 1.0){
|
||||
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),a);
|
||||
} else if (ipos.y < 2.0){
|
||||
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),b);
|
||||
} else if (ipos.y < 3.0){
|
||||
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),c);
|
||||
} else if (ipos.y < 4.0){
|
||||
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),d);
|
||||
} else if (ipos.y < 5.0){
|
||||
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),e);
|
||||
} else if (ipos.y < 6.0){
|
||||
return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),f);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float hex(vec2 st, float N){
|
||||
float b[6];
|
||||
float remain = floor(mod(N,64.));
|
||||
for(int i = 0; i < 6; i++){
|
||||
b[i] = 0.0;
|
||||
b[i] = step(1.0,mod(remain,2.));
|
||||
remain = ceil(remain/2.);
|
||||
}
|
||||
return hex(st,b[0],b[1],b[2],b[3],b[4],b[5]);
|
||||
}
|
||||
|
||||
float random (in vec2 _st) { return fract(sin(dot(_st.xy, vec2(12.9898,78.233)))* 43758.5453123);}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.y *= u_resolution.y/u_resolution.x;
|
||||
|
||||
st *= 10.0;
|
||||
vec2 fpos = fract(st);
|
||||
vec2 ipos = floor(st);
|
||||
|
||||
float t = u_time*5.0;
|
||||
float df = 1.0;
|
||||
df = hex(fpos,ipos.x+ipos.y+t*random(ipos))+(1.0-rect(fpos,vec2(0.7)));
|
||||
|
||||
gl_FragColor = vec4(mix(vec3(0.),vec3(1.),step(0.7,df)),1.0);
|
||||
}
|
||||
|
|
@ -5,12 +5,16 @@ The following is a list of examples present in this book.
|
|||
### Chapters examples
|
||||
|
||||
* Getting started
|
||||
|
||||
* [Hello World](../02/)
|
||||
- ["Hello World!"](../edit.html#02/hello_world.frag)
|
||||
|
||||
* [Uniforms](../03/)
|
||||
- [u_time](../edit.html#03/time.frag)
|
||||
- [gl_FragCoord](../edit.html#03/space.frag)
|
||||
|
||||
* Algorithmic drawing
|
||||
|
||||
* [Shaping functions](../05/)
|
||||
- [Linear Interpolation](../edit.html#05/linear.frag)
|
||||
- [Exponential Interpolation](../edit.html#05/expo.frag)
|
||||
|
|
@ -32,12 +36,12 @@ The following is a list of examples present in this book.
|
|||
* [Shapes](../07/)
|
||||
- Rectangle: [making](../edit.html#07/rect-making.frag), [function](../edit.html#07/rect.frag) and [distance-field](../edit.html#07/rect-df.frag)
|
||||
- Circle: [making](../edit.html#07/circle-making.frag) and [function](../edit.html#07/circle.frag)
|
||||
- [Batman (distance field)](../edit.html#07/batman.frag)
|
||||
- [Line (distance field)](../edit.html#07/line.frag)
|
||||
- [Batman](../edit.html#07/batman.frag)
|
||||
- [Line](../edit.html#07/line.frag)
|
||||
- [Cross](../edit.html#07/cross.frag)
|
||||
- [Polar](../edit.html#07/polar.frag)
|
||||
- [Polar (distance field)](../edit.html#07/shapes.frag)
|
||||
- [Arrow (distance field)](../edit.html#07/arrow.frag)
|
||||
- [Polar](../edit.html#07/shapes.frag)
|
||||
- [Arrow](../edit.html#07/arrow.frag)
|
||||
|
||||
* [Matrix](../08/)
|
||||
- [cross](../edit.html#08/cross.frag)
|
||||
|
|
@ -61,16 +65,25 @@ The following is a list of examples present in this book.
|
|||
- [Deco](../edit.html#09/deco.frag)
|
||||
- [I Ching](../edit.html#09/iching-01.frag)
|
||||
|
||||
|
||||
* Generative designs
|
||||
|
||||
* [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).
|
||||
- Ikeda's style: [test pattern](../edit.html#10/ikeda-00.frag), [wave](../edit.html#10/ikeda-01.frag),[test pattern](../edit.html#10/ikeda-02.frag), [data path](../edit.html#10/ikeda-03.frag) and [data defrag](../edit.html#10/ikeda-04.frag).
|
||||
- [Matrix](../edit.html#10/matrix.frag)
|
||||
- [Digits](../edit.html#10/ikeda-digits.frag)
|
||||
- [Random Grid](../edit.html#10/ikeda-simple-grid.frag)
|
||||
- [Random Numbered Grid](../edit.html#10/ikeda-numered-grid.frag)
|
||||
- [Random I Ching](../edit.html#10/iching-02.frag)
|
||||
|
||||
### Advance
|
||||
|
||||
* [Moon](../edit.html#examples/moon.frag&examples/images/moon-texture.jpg)
|
||||
* [Matrix](../edit.html#08/matrix.frag)
|
||||
* [I Ching](../edit.html#09/iching.frag)
|
||||
* Ikeda's series: [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), [digits](../edit.html#10/ikeda-digits.frag), [radar](../edit.html#10/ikeda-simple-grid.frag), [numered grid](../edit.html#10/ikeda-numered-grid.frag)
|
||||
|
|
|
|||
Loading…
Reference in New Issue