adding barcode

This commit is contained in:
Patricio Gonzalez Vivo 2015-10-07 14:20:15 -04:00
parent 6c36bcf606
commit 137e27ed20
11 changed files with 270 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

40
09/tmp/dots-texture.frag Normal file
View File

@ -0,0 +1,40 @@
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_tex0;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float rows = 10.0;
vec2 brickTile(vec2 _st, float _zoom){
_st *= _zoom;
if (fract(_st.y * 0.5) > 0.5){
_st.x += 0.5;
}
return fract(_st);
}
float circle(vec2 _st, float _radius){
vec2 pos = vec2(0.5)-_st;
_radius *= 0.75;
return 1.-smoothstep(_radius-(_radius*0.01),_radius+(_radius*0.01),dot(pos,pos)*3.14);
}
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec2 pos = st;
st = brickTile(st,50.);
float pattern = texture2D(u_tex0,pos).r;
pattern = circle(st, pattern);
gl_FragColor = vec4(1.-vec3(pattern),1.0);
}

BIN
09/tmp/moon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

156
10/tmp/barcode.frag Normal file
View File

@ -0,0 +1,156 @@
// 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 binChar (vec2 ipos, float n) {
float remain = mod(n,33554432.);
for (float i = 0.0; i < 15.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 = binChar(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 binBar (vec2 ipos, float n) {
float remain = mod(n,128.);
for(float i = 0.0; i < 8.0; i++){
if ( mod(i,10.) == ipos.x ) {
return step(1.0,mod(remain,2.));
}
remain = ceil(remain/2.);
}
return 0.0;
}
// Standard UPC-E Barcode reference from
// https://en.wikipedia.org/wiki/Universal_Product_Code
float bar (vec2 st, float n, bool L) {
vec2 grid = vec2(7.,1.);
if (L) { st = 1.0-st; }
vec2 ipos = floor(st*grid);
vec2 fpos = fract(st*grid);
n = floor(mod(n,10.));
float digit = 0.0;
if (n < 1. ) { digit = 114.; }
else if (n < 2. ) { digit = 102.0; }
else if (n < 3. ) { digit = 108.0; }
else if (n < 4. ) { digit = 66.0; }
else if (n < 5. ) { digit = 92.0; }
else if (n < 6. ) { digit = 78.0; }
else if (n < 7. ) { digit = 80.0; }
else if (n < 8. ) { digit = 68.0; }
else if (n < 9. ) { digit = 72.0; }
else if (n < 10. ) { digit = 116.0; }
float pct = binBar(ipos, digit+1.);
if (L) { pct = 1.-pct; }
return step(.5,pct);
}
float bar (vec2 st, float n) {
return bar(st,n,true);
}
float barStart (vec2 st) {
vec2 grid = vec2(7.,1.);
vec2 ipos = floor((1.0-st)*grid);
float digit = 122.0;
float pct = binBar(ipos, digit+1.);
return step(.5,1.0-pct);
}
float barEnd(vec2 st) {
vec2 grid = vec2(7.,1.);
vec2 ipos = floor((1.0-st)*grid);
float digit = 85.0;
float pct = binBar(ipos, digit+1.);
return step(.5,1.0-pct);
}
float barCode(vec2 st, float rows, float value) {
rows = ceil(rows);
vec2 ipos = floor(st*rows);
vec2 fpos = fract(st*rows);
value = value*pow(10.,ipos.x)*0.0000000001+0.1;
if (ipos.x == 0.0 ) {
return barStart(fpos);
} else if (ipos.x == rows-1.) {
return barEnd(fpos);
} else {
if (ipos.y == 0.0) {
return 1.0-char(fpos,value);
} else {
return bar(fpos,value);
}
}
}
void main(){
vec2 st = gl_FragCoord.st/u_resolution.xy;
st *= 3.;
vec2 ipos = floor(st);
vec2 fpos = fract(st);
fpos.y *= u_resolution.y/u_resolution.x;
vec3 color = vec3(0.0);
if (ipos.x == 1. && ipos.y == 1.) {
float value = 0.0;
// value = 123456789.0;
value += floor(u_time);
value = random(floor(u_time*10.))*1000000000.;
color += barCode(fpos,12.,value);
} else {
color += 1.;
}
gl_FragColor = vec4( color , 1.0);
}

69
10/tmp/digits.frag Normal file
View File

@ -0,0 +1,69 @@
// 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;
}
void main(){
vec2 st = gl_FragCoord.st/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
float rows = 34.0;
vec2 ipos = floor(st*rows);
vec2 fpos = fract(st*rows);
ipos += vec2(0.,floor(u_time*20.*random(ipos.x+1.)));
float pct = random(ipos);
vec3 color = vec3(char(fpos,100.*pct));
color = mix(color,vec3(color.r,0.,0.),step(.99,pct));
gl_FragColor = vec4( color , 1.0);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

BIN
12/tmp/moon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -4,25 +4,15 @@
precision mediump float;
#endif
uniform sampler2D u_tex0;
uniform vec2 u_resolution;
uniform float u_time;
// Cellular noise ("Worley noise") in 2D in GLSL.
// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.
// This code is released under the conditions of the MIT license.
// See LICENSE file for details.
// Permutation polynomial: (34x^2 + x) mod 289
vec4 permute(vec4 x) {
return mod((34.0 * x + 1.0) * x, 289.0);
}
// Cellular noise, returning F1 and F2 in a vec2.
// Speeded up by using 2x2 search window instead of 3x3,
// at the expense of some strong pattern artifacts.
// F2 is often wrong and has sharp discontinuities.
// If you need a smooth F2, use the slower 3x3 version.
// F1 is sometimes wrong, too, but OK for most purposes.
vec2 cellular2x2(vec2 P) {
#define K 0.142857142857 // 1/7
#define K2 0.0714285714285 // K/2
@ -58,10 +48,10 @@ vec2 cellular2x2(vec2 P) {
void main(void) {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec2 F = cellular2x2(st*50.);
vec2 F = cellular2x2(st*100.);
float pct = st.x;
float pct = texture2D(u_tex0,st).r;
pct = step(1.-pct,F.x);
float n = step(pct,F.x*1.3);
gl_FragColor = vec4(n, n, n, 1.0);
gl_FragColor = vec4(vec3(pct), 1.0);
}