const version = "v2c1" // ============================== VERT ======================================== const shader_vert = ` attribute vec3 aPosition; attribute vec2 aTexCoord; varying vec2 vTexCoord; void main() { vTexCoord = aTexCoord; vec4 positionVec4 = vec4(aPosition, 1.0); positionVec4.xy = positionVec4.xy * 2.0 - 1.0; gl_Position = positionVec4; }`; // =============================== PRE-SHADER ================================= const preShader_frag = ` precision mediump float; varying vec2 vTexCoord; uniform sampler2D img_input; uniform float aimX; uniform float aimY; uniform float width; uniform float height; uniform float pixelSize; uniform float pixelBlend; uniform float alt; uniform float piTime; uniform float rndX; uniform float rndY; vec2 uv; vec4 img_output; vec4 fragColor; vec2 fragCoord; const vec4 color0 = vec4(0.0, 0.0, 0.0, 1); const vec4 color1 = vec4(0.33, 0.33, 0.33, 1); const vec4 color2 = vec4(0.66, 0.66, 0.66, 1); const vec4 color3 = vec4(1.0, 1.0, 1.0, 1); #define cell_size 100.0 #define cell_step 33.0 vec4 img_mos = vec4(0); float luma(vec4 color) { return dot(color.rgb, vec3(0.299, 0.587, 0.114)); } // pixelation shader code by jfons_ https://www.shadertoy.com/view/4dVyRz // https://github.com/hughsk/glsl-dither/blob/master/8x8.glsl float dither8x8(vec2 position, float brightness) { int x = int(mod(position.x, 8.0)); int y = int(mod(position.y, 8.0)); int index = x + y * 8; float limit = 0.0; if (x < 8) { if (index == 0) limit = 0.015625; if (index == 1) limit = 0.515625; if (index == 2) limit = 0.140625; if (index == 3) limit = 0.640625; if (index == 4) limit = 0.046875; if (index == 5) limit = 0.546875; if (index == 6) limit = 0.171875; if (index == 7) limit = 0.671875; if (index == 8) limit = 0.765625; if (index == 9) limit = 0.265625; if (index == 10) limit = 0.890625; if (index == 11) limit = 0.390625; if (index == 12) limit = 0.796875; if (index == 13) limit = 0.296875; if (index == 14) limit = 0.921875; if (index == 15) limit = 0.421875; if (index == 16) limit = 0.203125; if (index == 17) limit = 0.703125; if (index == 18) limit = 0.078125; if (index == 19) limit = 0.578125; if (index == 20) limit = 0.234375; if (index == 21) limit = 0.734375; if (index == 22) limit = 0.109375; if (index == 23) limit = 0.609375; if (index == 24) limit = 0.953125; if (index == 25) limit = 0.453125; if (index == 26) limit = 0.828125; if (index == 27) limit = 0.328125; if (index == 28) limit = 0.984375; if (index == 29) limit = 0.484375; if (index == 30) limit = 0.859375; if (index == 31) limit = 0.359375; if (index == 32) limit = 0.0625; if (index == 33) limit = 0.5625; if (index == 34) limit = 0.1875; if (index == 35) limit = 0.6875; if (index == 36) limit = 0.03125; if (index == 37) limit = 0.53125; if (index == 38) limit = 0.15625; if (index == 39) limit = 0.65625; if (index == 40) limit = 0.8125; if (index == 41) limit = 0.3125; if (index == 42) limit = 0.9375; if (index == 43) limit = 0.4375; if (index == 44) limit = 0.78125; if (index == 45) limit = 0.28125; if (index == 46) limit = 0.90625; if (index == 47) limit = 0.40625; if (index == 48) limit = 0.25; if (index == 49) limit = 0.75; if (index == 50) limit = 0.125; if (index == 51) limit = 0.625; if (index == 52) limit = 0.21875; if (index == 53) limit = 0.71875; if (index == 54) limit = 0.09375; if (index == 55) limit = 0.59375; if (index == 56) limit = 1.0; if (index == 57) limit = 0.5; if (index == 58) limit = 0.875; if (index == 59) limit = 0.375; if (index == 60) limit = 0.96875; if (index == 61) limit = 0.46875; if (index == 62) limit = 0.84375; if (index == 63) limit = 0.34375; } return brightness < limit ? 0.0 : 1.0; } void main() { uv = vTexCoord; uv.y = 1.0 - uv.y; vec2 iResolution = vec2(width,height); fragCoord = vTexCoord*iResolution; //if (alt==0.0) { //float pixelSizeN = 2.0; fragCoord = floor(fragCoord/pixelSize) * pixelSize; fragCoord /= pixelSize; vec4 color = texture2D(img_input, uv); float l = luma(color); float ll = l * 4.0; float b; if (ll <= 1.5) b = ll/1.5; else if (ll <= 2.5) b = ll-1.5; else b = (ll-2.5)/1.5; float d = dither8x8(fragCoord, b); if (ll <= 1.5) fragColor = d == 0.0 ? color0 : color1; else if (ll <= 2.5) fragColor = d == 0.0 ? color1 : color2; else if (ll <= 3.975) fragColor = d == 0.0 ? color2 : color3; else fragColor = color3; img_output = fragColor; //} /* if (alt==1.0) { float psize_x = 1.0 / width; // float pixsize float psize_y = 1.0 / height; // float pixsize vec2 fstep = uv; fstep.x = (psize_x * cell_size) * floor(fstep.x / (psize_x * cell_size)); fstep.y = (psize_y * cell_size) * floor(fstep.y / (psize_y * cell_size)); for (float i = 0.0; i < cell_size; i+= cell_step) { for (float j = 0.0; j < cell_size; j+= cell_step) { vec2 shift = vec2(fstep.x + psize_x * (i), fstep.y + psize_y * (j)); img_mos += texture2D(img_input, shift); } } img_mos /= pow((cell_size/cell_step), 2.0); img_mos = vec4(img_mos-0.5); vec2 uv_shift = abs(1.0 - abs(1.0-uv + vec2(img_mos.r,img_mos.g))); vec4 src_sh = texture2D(img_input, uv_shift); img_output = max(texture2D( img_input , uv) ,src_sh); } */ /* if (piTime<0.1) { //vec2 rsz = vec2( uv*(cos(piTime)*10.0) - vec2(rndX, rndY)*10.0); vec2 rsz = vec2( uv*2.0 - vec2(rndX*3.0-1.0, rndY*3.0-1.0)); img_output = texture2D(img_input, rsz); img_output.a = rsz.x > 0.01 && rsz.y > 0.01 && rsz.x < 0.99 && rsz.y < 0.99 ? 1.0 : 0.0; gl_FragColor = img_output; } */ //img_output = texture2D(img_input, uv); gl_FragColor = img_output; }`; // =============================== MAIN-SHADER ================================= const mainShader_frag = ` precision mediump float; varying vec2 vTexCoord; uniform sampler2D img_input; uniform float cam_mode; uniform float rndX; uniform float rndY; uniform float piTime; uniform float freq; uniform float wave1; uniform float aimX; uniform float aimY; uniform float aimX3; uniform float aimY3; uniform int mode; uniform int alt; uniform int freeze; vec2 uv; vec4 img_work; vec4 img_output; float xShift; float yShift; float avg; float thr; float isin; void main() { uv = vTexCoord; uv.y = 1.0 - uv.y; if (cam_mode==1.0) uv.x = 1.0 - uv.x; // if (aimX3>=0.0) { uv.x = uv.x - aimX3 > 0.0 ? uv.x - aimX3 < 1.0 ? uv.x - aimX3 : uv.x - aimX3 - 1.0 : uv.x - aimX3 + 1.0 ; uv.y = uv.y - aimY3 > 0.0 ? uv.y - aimY3 < 1.0 ? uv.y - aimY3 : uv.y - aimY3 - 1.0 : uv.y - aimY3 + 1.0 ; /* uv.x = uv.x - aimX3; uv.y = uv.y - aimY3; } else { uv = uv + vec2( sin(uv.y * abs(aimX3)*5.0 + (( piTime )*5.0)) * 0.2, cos(uv.x * abs(aimY3)*5.0 + (( piTime )*5.0)) * 0.2); } // if (aimY3>0.0) { uv.x *= (1.0-aimY3); uv.y *= (1.0-aimY3); // } */ if (freeze == 0) { // Pure if (mode==0) { img_output = texture2D( img_input , uv); float xShift = (img_output.r*2.0-1.0) * aimX; float yShift = (img_output.g*2.0-1.0) * aimY; img_output = texture2D( img_input , abs(1.0-abs(1.0-uv +vec2(xShift,yShift)))); } // Copy if (mode==1) { if (alt == 0) { img_work = texture2D(img_input, uv); xShift = (img_work.r*2.0-1.0) * aimX * cos(piTime); yShift = (img_work.g*2.0-1.0) * aimY * sin(piTime); img_output = texture2D(img_input, abs(1.0-abs(1.0-uv +vec2(xShift,yShift)))); //img_output = texture2D(img_input, uv); avg = dot(img_work.rgb, vec3(0.33333)); thr = step((sin(piTime)*0.45+0.55), avg); img_output.a = thr*2.0; } if (alt == 1) { img_output = texture2D(img_input, uv); xShift = (img_work.r*2.0-1.0) * aimX * cos(piTime); yShift = (img_work.g*2.0-1.0) * aimY * sin(piTime); /* uv2.x = uv.x - xShift > 0.0 ? uv.x - xShift < 1.0 ? uv.x - xShift : uv.x - xShift - 1.0 : uv.x - xShift + 1.0 ; uv2.y = uv.y - yShift > 0.0 ? uv.y - yShift < 1.0 ? uv.y - yShift : uv.y - yShift - 1.0 : uv.y - yShift + 1.0 ; */ img_work = texture2D(img_input, abs(1.0-abs(1.0-uv +vec2(xShift,yShift)))); avg = dot(img_work.rgb, vec3(0.33333)); thr = step((sin(piTime)*0.45+0.55), avg); img_output.a = thr*2.0; } } // Stamp if (mode==2) { if (alt==0) { if (wave1==1.0) { img_work = texture2D(img_input, vec2(cos(piTime),sin(piTime)) + ( uv-vec2(cos(piTime),sin(piTime)) ) / sin(piTime)); xShift = (img_work.r*2.0-1.0) * aimX * cos(piTime); yShift = (img_work.g*2.0-1.0) * aimY * sin(piTime); img_output = texture2D(img_input, abs(1.0-abs(uv*sin(piTime) +vec2(xShift,yShift)))); } avg = dot(img_output.rgb, vec3(0.33333)); isin = (sin(piTime))*0.5+0.5; thr = smoothstep(isin,isin+0.05,avg)-smoothstep(isin+0.25,isin+0.30,avg); img_output = vec4 ( img_work.r, img_work.g, img_work.b, thr*0.65); } if (alt==1) { vec3 img_color; if (wave1==1.0) { vec2 rsz = vec2( uv - (vec2(rndX, rndY)-0.5)*2.0); img_work = texture2D(img_input, rsz); xShift = (img_work.r*2.0-1.0) * aimX * cos(piTime); yShift = (img_work.g*2.0-1.0) * aimY * sin(piTime); rsz += vec2(xShift,yShift)*0.5; img_work = texture2D(img_input, rsz); avg = dot(img_work.rgb, vec3(0.33333)); isin = (sin(piTime))*0.5+0.5; thr = smoothstep(isin,isin+0.05,avg)-smoothstep(isin+0.25,isin+0.30,avg); img_color = texture2D(img_input, vec2(rndX,rndY)).rgb; img_work.a = rsz.x > 0.01 && rsz.y > 0.01 && rsz.x < 0.99 && rsz.y < 0.99 ? thr : 0.0; } img_output = vec4 ( sin(piTime) > 0.5 ? img_color.r : img_work.r, sin(piTime) > 0.5 ? img_color.g : img_work.g, sin(piTime) > 0.5 ? img_color.b : img_work.b, img_work.a ); } } // Draw if (mode==3) { if (wave1==1.0){ img_work = texture2D(img_input, uv+vec2(cos(piTime)*0.005,sin(piTime)*0.005)); xShift = (img_work.r*2.0-1.0) * aimX * cos(piTime); yShift = (img_work.g*2.0-1.0) * aimY * sin(piTime); img_output = texture2D(img_input, abs(1.0-abs(uv*sin(piTime) +vec2(xShift,yShift)))); } vec4 col = img_output; float colorQuality = 12.0; // (1-255) vec3 q = vec3(colorQuality); vec4 picpost = vec4(floor(col.rgb*q)/q,col.a); avg = dot(picpost.rgb, vec3(0.33333)); isin = (sin(piTime))*0.5+0.5; //thr = step(isin,avg)-step(isin+0.25,avg); thr = smoothstep(isin,isin+0.05,avg)-smoothstep(isin+0.25,isin+0.30,avg); img_output = vec4 ( img_work.r, img_work.g, img_work.b, thr*0.65); } } gl_FragColor = img_output; }`; // =============================== FEEDBACK-SHADER ================================ const feedShader_frag = ` precision mediump float; #define PI 3.14159265359 #define TWO_PI 6.28318530718 varying vec2 vTexCoord; uniform sampler2D img_input; uniform sampler2D fb_input; uniform float fbk; uniform float zebra; uniform int freeze; vec2 uv; vec4 img_work; vec4 img_output; vec4 fb = vec4(0.0,0.0,0.0,1.0); float fbk_work; void main() { uv = vTexCoord; uv.y = 1.0 - uv.y; if (freeze == 0) { img_work = texture2D( img_input , uv ); float avg = dot(img_work.rgb, vec3(0.33333)); float angleX = (sin(avg * TWO_PI)) * 0.005 ; float angleY = (cos(avg * TWO_PI)) * 0.005 ; //fbk_work = fbk * (1.0-zebra*0.5); if (zebra == 1.0 && fbk > 0.75) fbk_work = 0.0 - (fbk-0.75)*30.0; else fbk_work = fbk; fb = texture2D(fb_input,uv + vec2(angleX,angleY) * fbk_work); img_output = (img_work*(1.0-fbk_work) + fb*fbk_work)*(1.0+zebra); avg = dot(img_output.rgb, vec3(0.33333)); if (zebra == 1.0 && fbk > 0.75) img_output = vec4( avg > 1.0 ? fb.r : img_output.r, avg > 1.0 ? fb.g : img_output.g, avg > 1.0 ? fb.b : img_output.b, avg > 1.0 ? 0.0 : img_output.a); else img_output = vec4( avg > 1.0 ? 0.0 : img_output.r, avg > 1.0 ? 0.0 : img_output.g, avg > 1.0 ? 0.0 : img_output.b, avg > 1.0 ? 0.0 : img_output.a); // if (img_output.a == 0.0) img_output = fb; } gl_FragColor = img_output; }`; // =============================== POST-SHADER ================================ const postShader_frag = ` precision mediump float; varying vec2 vTexCoord; uniform sampler2D img_input; uniform float aimX; uniform float aimY; uniform float aimX3; uniform float aimY3; vec2 uv; vec4 img_output; void main() { uv = vTexCoord; uv.y = 1.0 - uv.y; if (aimY3>0.0) { float rsize = aimY3; uv *= 1.0-rsize; uv += rsize/2.0; } img_output = texture2D( img_input , uv); float xShift = (img_output.r*2.0-1.0) * aimX * 0.1; float yShift = (img_output.g*2.0-1.0) * aimY * 0.1; img_output = texture2D( img_input , uv - vec2(xShift,yShift)); //if (uv.y>0.5 && uv.x >0.5) img_output.b = 1.0; gl_FragColor = img_output; }`; // =========================== VARIABLES ====================================== let set_resolution; let camera_input; let camera_mode; let image_input; let fbk = 0.01; let top_mode; let pr_mode; let def_fx; /* let sound_enabled; let mic; let vol; let volArray; let vol_av; let vol_len; */ let bp = 0; let btn_new; let scr_mode = 0; let ztimer = 0; let fps; let DT; // ============================= CLASSES ====================================== class button { constructor(text, x, y, width, height) { this.text = text; this.x = x; this.y = y; this.width = width; this.height = height; this.over = false; this.pressed = false; this.clicked = false; this.alpha = 0.0; this.tSize = 20.0; this.clickable = true; this.lightable = true; this.outpress = false; this.outclick = false; } create() { if (this.clicked == true) { this.clicked = false; //print("unclicked: "+ this.text); } if (mouseX>this.x && mouseXthis.y && mouseY 0) this.alpha -= 20.0; rect(this.x,this.y,this.width,this.height); fill(0); noStroke(); textSize(this.tSize); textAlign(CENTER, CENTER); fill(255); text(this.text, this.x + this.width/2+1, this.y + this.height/2+1); fill(0); text(this.text, this.x + this.width/2, this.y + this.height/2); } } class checkbox { constructor(text, x, y, width, height) { this.text = text; this.x = x; this.y = y; this.width = width; this.height = height; this.over = false; this.pressed = false; this.clicked = false; this.alpha = 0.0; this.mode = 0; } create() { if (this.clicked == true) { if (this.mode == 0) this.mode=1; else if (this.mode == 1) this.mode=0; this.clicked = false; //print("unclicked: "+ this.text); } if (mouseX>this.x && mouseXthis.y && mouseY 0) this.alpha -= 20.0; rect(this.x,this.y,this.width,this.height); this.mode == 1 ? textSize(40) : textSize(20) ; noStroke(); textAlign(CENTER, CENTER); fill(255-255*this.mode); text(this.text, this.x + this.width/2+1, this.y + this.height/2+1); fill(0+255*this.mode); text(this.text, this.x + this.width/2, this.y + this.height/2); textSize(20) ; } } class scrollbar { constructor(text, x, y, width, height, vmin, vmax, vset) { this.text = text; this.x = x; this.y = y; this.width = width; this.height = height; this.vmin = vmin; this.vmax = vmax; this.vset = vset; this.bypass = 0.0; this.over = false; this.pressed = false; this.alpha = 0.0; } create() { if (mouseX>this.x && mouseXthis.y && mouseY 0) this.alpha -= 20.0; stroke(255); noFill(); rect(this.x+1,this.y+1,this.width,this.height); stroke(0); fill(0, this.alpha); rect(this.x,this.y,this.width,this.height); stroke(255); noFill(); rect(this.x+1,this.y+1,this.width*((this.vset-this.vmin)/(this.vmax-this.vmin)),this.height); stroke(0); this.vset > this.bypass ? fill(255, this.alpha) : fill(100, this.alpha); rect(this.x,this.y,this.width*((this.vset-this.vmin)/(this.vmax-this.vmin)),this.height); noStroke(); textSize(20); textAlign(CENTER, CENTER); fill(255); text(this.text, this.x + this.width/2+1, this.y + this.height/2+1); fill(0); text(this.text, this.x + this.width/2, this.y + this.height/2); } } class aimbar { constructor(x, y, width, height, x1set, y1set, x2set, y2set, x3set, y3set, x4set, y4set) { this.x = x; this.y = y; this.width = width; this.height = height; this.x1set = x1set; this.y1set = y1set; this.x2set = x2set; this.y2set = y2set; this.x3set = x3set; this.y3set = y3set; this.over = false; this.pressed = false; this.clicked = false; this.alpha = 0.0; this.xmin = -1.0; this.ymin = -1.0; this.xmax = 1.0; this.ymax = 1.0; this.mode = 1; } create() { if (mouseX>this.x && mouseXthis.y && mouseY 0) this.alpha -= 20.0; stroke(255); noFill(); rect(this.x+1,this.y+1,this.width,this.height); line(this.x+this.width/2+1, this.y+1, this.x+this.width/2+1, this.y+this.height+1); line(this.x+1, this.y+this.height/2+1, this.x+this.width+1, this.y+this.height/2+1); stroke(0); fill(0, this.alpha); rect(this.x,this.y,this.width,this.height); line(this.x+this.width/2, this.y, this.x+this.width/2, this.y+this.height); line(this.x, this.y+this.height/2, this.x+this.width, this.y+this.height/2); noFill(); stroke(255); this.mode == 3 ? strokeWeight(4) : strokeWeight(1); circle( this.x + this.width* (this.x3set-this.xmin)/(this.xmax-this.xmin) +1 , this.y + this.height*(this.y3set-this.ymin)/(this.ymax-this.ymin) +1 , 20 ); this.mode == 3 ? stroke(223,67,16) : stroke(0); circle( this.x + this.width* (this.x3set-this.xmin)/(this.xmax-this.xmin) , this.y + this.height*(this.y3set-this.ymin)/(this.ymax-this.ymin) , 20 ); stroke(255); this.mode == 2 ? strokeWeight(4) : strokeWeight(1); circle( this.x + this.width* (this.x2set-this.xmin)/(this.xmax-this.xmin) +1 , this.y + this.height*(this.y2set-this.ymin)/(this.ymax-this.ymin) +1 , 20 ); this.mode == 2 ? stroke(230,217,17) : stroke(0); circle( this.x + this.width* (this.x2set-this.xmin)/(this.xmax-this.xmin) , this.y + this.height*(this.y2set-this.ymin)/(this.ymax-this.ymin) , 20 ); stroke(255); this.mode == 1 ? strokeWeight(4) : strokeWeight(1); circle( this.x + this.width* (this.x1set-this.xmin)/(this.xmax-this.xmin) +1 , this.y + this.height*(this.y1set-this.ymin)/(this.ymax-this.ymin) +1 , 20 ); this.mode == 1 ? stroke(76,153,197) : stroke(0); circle( this.x + this.width* (this.x1set-this.xmin)/(this.xmax-this.xmin) , this.y + this.height*(this.y1set-this.ymin)/(this.ymax-this.ymin) , 20 ); strokeWeight(1); //rect(this.x,this.y,this.width*((this.vset-this.vmin)/(this.vmax-this.vmin)),this.height); } } class radio { constructor(x, y) { this.x = x; this.y = y; this.mode = 1; this.width = height*0.1; this.height = height*0.1; this.over = false; this.pressed = false; this.clicked = false; this.alpha = 0.0; this.n1 = "1"; this.n2 = "2"; this.n3 = "3"; } create() { if (mouseX>this.x && mouseXthis.y && mouseYthis.y+this.height*0.0 && mouseYthis.y+this.height*1.0 && mouseYthis.y+this.height*2.0 && mouseY 0) this.alpha -= 20.0; stroke(255); noFill(); rect(this.x+1,this.y+1,this.width,this.height); stroke(0); this.mode == 1 ? textSize(40) : textSize(20) ; fill(76,153,197, this.mode == 1 ? this.alpha : 0.0); rect(this.x,this.y,this.width,this.height); this.mode == 1 ? fill(0) : fill(255) ; text(this.n1, this.x + this.width/2+1, this.y + this.height/2+this.height*0+1); this.mode == 1 ? fill(76,153,197) : fill(0) ; text(this.n1, this.x + this.width/2, this.y + this.height/2+this.height*0); stroke(255); noFill(); rect(this.x+1,this.y+this.height+1,this.width,this.height); stroke(0); this.mode == 2 ? textSize(40) : textSize(20) ; fill(230,217,17, this.mode == 2 ? this.alpha : 0.0); rect(this.x,this.y+this.height,this.width,this.height); this.mode == 2 ? fill(0) : fill(255) ; text(this.n2, this.x + this.width/2+1, this.y + this.height/2+this.height*1+1); this.mode == 2 ? fill(230,217,17) : fill(0) ; text(this.n2, this.x + this.width/2, this.y + this.height/2+this.height*1); stroke(255); noFill(); rect(this.x+1,this.y+this.height*2.0+1,this.width,this.height); stroke(0); this.mode == 3 ? textSize(40) : textSize(20) ; fill(223,67,16, this.mode == 3 ? this.alpha : 0.0); rect(this.x,this.y+this.height*2.0,this.width,this.height); this.mode == 3 ? fill(0) : fill(255) ; text(this.n3, this.x + this.width/2+1, this.y + this.height/2+this.height*2+1); this.mode == 3 ? fill(223,67,16) : fill(0) ; text(this.n3, this.x + this.width/2, this.y + this.height/2+this.height*2); textSize(20); } } class shake_meter { constructor() { this.calibration_steps = 100; this.calibration_timer = -1.0; this.av_shake = getItem('av_shake')/10; //if (this.av_shake==getItem('empty_item')) { // this.av_shake = -1.0; // this.calibration_timer = this.calibration_steps; //} //print('av_shake get as '+this.av_shake); this.sum_shake = 0.0; this.Ax = 0.0; this.message_delay = 0.0; } create() { this.Ax = abs(accelerationX)+abs(accelerationY)+abs(accelerationZ)+abs(pAccelerationX)+abs(pAccelerationY)+abs(pAccelerationZ); if (this.calibration_timer == this.calibration_steps) { } if (this.calibration_timer>0) { fill(0); rect(width/2-115,height/2-45,230,85,3); this.calibration_timer -= 1; this.sum_shake += this.Ax; } if (this.calibration_timer==0) { this.av_shake = this.sum_shake/this.calibration_steps; this.sum_shake = 0; this.message_delay = 50; storeItem('av_shake', this.av_shake*10); ////print('av_shake stored as '+this.av_shake); this.calibration_timer = -1; } if (this.calibration_timer == -1 && this.message_delay > 0) { this.message_delay -= 1; if (this.av_shake>0) { fill(200,this.message_delay*10); rect(width/2-115,height/2-45,230,85,3); fill(0,this.message_delay*10); textSize(27); textAlign(CENTER, BOTTOM); text( "[ COMPLETED ]", width/2, height/2); textSize(18); textAlign(CENTER, TOP); text( "now you can shake", width/2, height/2+5); } else { fill(0,this.message_delay*10); rect(width/2-115,height/2-45,230,85,3); fill(200,this.message_delay*10); textSize(27); textAlign(CENTER, BOTTOM); text( "[ FAILED ]", width/2, height/2); textSize(18); textAlign(CENTER, TOP); text( "function unavailable", width/2, height/2+5); } } fill(200, this.calibration_timer*10); textSize(27); textAlign(CENTER, BOTTOM); text( "[ CALIBRATION ]", width/2, height/2); textSize(18); textAlign(CENTER, TOP); text( "please don't shake device", width/2, height/2+5); stroke(200, this.calibration_timer*10); line(width/2-110*(this.calibration_steps-this.calibration_timer)/this.calibration_steps, height/2-40, width/2+110*(this.calibration_steps-this.calibration_timer)/this.calibration_steps, height/2-40); line(width/2-110*(this.calibration_steps-this.calibration_timer)/this.calibration_steps, height/2+35, width/2+110*(this.calibration_steps-this.calibration_timer)/this.calibration_steps, height/2+35); } } class main_shader { constructor() { this.timer = 0.0; this.pi_timer = 0.0; this.random_timer = 0.0; this.timer_speed = 0.00063*4; this.wave1 = 0.0; this.mode = 0; this.modes_num = 4; this.inImg; this.outImg; // 00 - Camera // 01 - Copy // 02 - Stamp // 03 - Draw } create(inImg) { this.inImg = inImg; if (this.mode==0 || this.mode==1) { // Copy this.timer += this.timer_speed*DT; this.pi_timer = this.timer*PI; if (this.timer>=2) this.timer=0; if(cos(this.pi_timer)<0) this.wave1 = (cos(this.pi_timer)*0.5+1.0); } if (this.mode==2 || this.mode==3) { // Stamp, Draw this.random_timer = random(0,2); this.pi_timer = this.random_timer*PI; this.wave1 = 0.0; if ( (shaker.Ax>shaker.av_shake*2 || btn_plus.pressed == true ) && btn_h.mode == 0) this.wave1 = 1.0; } mainShader.setUniform('cam_mode', camera_mode); mainShader.setUniform('img_input', this.inImg); mainShader.setUniform('img_source', camera_input); mainShader.setUniform('piTime', this.pi_timer); mainShader.setUniform('wave1', this.wave1); mainShader.setUniform('mode', this.mode); mainShader.setUniform('alt', btn_x.mode); mainShader.setUniform('rndX', random()); mainShader.setUniform('rndY', random()); mainShader.setUniform('freeze', btn_h.mode); //mainShader.setUniform('freq', frameCount * 0.01); mainShader.setUniform('aimX', btn_aim.x1set/2.0); mainShader.setUniform('aimY', btn_aim.y1set/2.0); mainShader.setUniform('aimX3', btn_aim.x3set); mainShader.setUniform('aimY3', btn_aim.y3set); mainImg.shader(mainShader); mainImg.rect(0,0,mainImg.width, mainImg.height); this.outImg = mainImg; } } class automizer { constructor() { this.ztimer = 0.0; this.temp = 50 /DT; this.rs_x1 = 0; this.rs_y1 = 0; this.rs_x2 = 0; this.rs_y2 = 0; this.rs_x3 = 0; this.rs_y3 = 0; this.x3s = 0; this.y3s = 0; this.rs_b = 0; this.let_aim1 = false; this.let_aim2 = false; this.let_aim3 = false; this.let_x = false; this.let_y = false; this.let_z = false; this.let_blur = false; this.let_mode = false; this.let_plus = false; } create() { if (btn_a.mode==1 && btn_h.mode==0) { this.temp = 50 /DT; if (this.let_aim1 && frameCount>100/DT) { if (random()< 0.01*DT ) { this.rs_x1 = random(-1,1); this.rs_y1 = random(-1,1); } btn_aim.x1set += (this.rs_x1-btn_aim.x1set)/this.temp; btn_aim.y1set += (this.rs_y1-btn_aim.y1set)/this.temp; } if (this.let_aim2 && frameCount>200/DT) { if (random()< 0.01*DT ) { this.rs_x2 = random(-1,1); this.rs_y2 = random(-1,1); } btn_aim.x2set += (this.rs_x2-btn_aim.x2set)/this.temp; btn_aim.y2set += (this.rs_y2-btn_aim.y2set)/this.temp; } if (this.let_aim3 && frameCount>300/DT) { if (random()< 0.01*DT ) { this.rs_x3 = random(-1,1); this.rs_y3 = random(-1,1); } if (random()< 0.005*DT ) { this.rs_x3 = 0; this.rs_y3 = 0; } this.x3s += (this.rs_x3-btn_aim.x3set)/this.temp/20; this.y3s += (this.rs_y3-btn_aim.y3set)/this.temp/20; let maxs = 0.005; if (this.x3s>maxs) this.x3s = maxs; if (this.x3s<-maxs) this.x3s = -maxs; if (this.y3s>maxs) this.y3s = maxs; if (this.y3s<-maxs) this.y3s = -maxs; if (btn_aim.x3set>1) { btn_aim.x3set = 0.98; this.x3s = -this.x3s; } if (btn_aim.x3set<-1) { btn_aim.x3set = -0.98; this.x3s = -this.x3s; } if (btn_aim.y3set>1) { btn_aim.y3set = 0.98; this.y3s = -this.y3s; } if (btn_aim.y3set<-1) { btn_aim.y3set = -0.98; this.y3s = -this.y3s; } btn_aim.x3set += this.x3s*DT; btn_aim.y3set += this.y3s*DT; } if (this.let_x) { if (random()< 0.01*DT ) btn_x.mode = (btn_x.mode+1)%2; } if (this.let_y) { if (random()< 0.01*DT && fbk<0.15) btn_y.mode = (btn_y.mode+1)%2; } if (this.let_z) { if (random()< 0.001*DT ) this.ztimer = random(5,50); if (this.ztimer > 0) { this.ztimer-=0.2*DT; btn_z.mode = 1; } else { btn_z.mode = 0; } } if (this.let_blur) { if (random()< 0.01*DT ) bp = random(0,1); btn_feedback.vset += (bp-btn_feedback.vset)/this.temp; if (bp>0.01) bp -= 0.005 * DT; fbk=btn_feedback.vset; } } if (btn_b.mode==1 && btn_h.mode==0) { if (random()<0.1*DT ) btn_plus.outpress = true; else btn_plus.outpress = false; } if (btn_c.mode==1 && btn_h.mode==0) { if (random()< 0.005*DT & frameCount>500/DT) { mShader.mode = int(random(3))+1; mShader.timer = 0.7; } } } } // ------------------------------- FUNCTIONS --------------------------------- function create_buttons() { shaker = new shake_meter(); autom = new automizer(); btn_fps = new button("FPS", 0, 0, width/3, height*0.1); btn_fps.clickable = false; btn_menu = new button("SET", width/3, 0, width/3, height*0.1); btn_hide = new button("HIDE", width, 0, width/3, height*0.1); btn_camtype = new button("", width/3, height*0.1, width/3, height*0.1); if (camera_mode == 0.0) btn_camtype.text = "CAMERA:\n[ MAIN ]"; if (camera_mode == 1.0) btn_camtype.text = "CAMERA:\n[ FRONTAL ]"; btn_resolution = new button("SCALE:\n[ "+ set_resolution + "X ]", width/3, height*0.2, width/3, height*0.1); btn_calibration = new button("SHAKING:\n[ "+nf(shaker.av_shake,1,1)+" ]", width/3, height*0.3, width/3, height*0.1); //btn_sound = new button("SOUND:\n[ "+ (sound_enabled == 0 ? "OFF" : "ON") +" ]", width/3, height*0.4, width/3, height*0.1); btn_apply = new button("> APPLY <", width/3, height*0.4, width/3, height*0.1); btn_modeinfo = new button('MODE', height*0.1, height*0.1, width-height*0.2, height*0.1); btn_modeinfo.clickable = false; let aimsize; if (width-height*0.2 > height*0.6) aimsize = height*0.6; else aimsize = width-height*0.2; btn_aim = new aimbar( width/2-aimsize/2, height/2-aimsize/2 , aimsize, aimsize, 0.0,0.0, 0.0,0.0, 0.0,0.0, 0.0,0.0 ); btn_aimsel = new radio(width-height*0.1,height*0.3); btn_reset = new button("R",width-height*0.1,height*0.2,height*0.1,height*0.1); btn_a = new checkbox("A",0,height*0.2,height*0.1,height*0.1); btn_b = new checkbox("B",0,height*0.3,height*0.1,height*0.1); btn_c = new checkbox("C",0,height*0.4,height*0.1,height*0.1); btn_x = new checkbox("X",0,height*0.5,height*0.1,height*0.1); // alt mode btn_y = new checkbox("Y",0,height*0.6,height*0.1,height*0.1); // main shader layer order btn_z = new checkbox("Z",0,height*0.7,height*0.1,height*0.1); // zebra btn_feedback = new scrollbar('BLUR',0, height*0.8, width, height*0.1, 0.01, 0.99, 0.01); btn_f = new checkbox("F",width-height*0.1,height*0.6,height*0.1,height*0.2); btn_h = new checkbox("H",width-height*0.1,height*0.6,height*0.1,height*0.2); btn_screenshot = new button('SCREENSHOT', height*0.1, height*0.9, width-height*0.2, height*0.1); btn_save = new button('SAVE', height*0.1, height*0.9, (width-height*0.2)/2, height*0.1); btn_cancel = new button('CANCEL', height*0.1+(width-height*0.2)/2, height*0.9, (width-height*0.2)/2, height*0.1); btn_left = new button('<', 0, height*0.1, height*0.1, height*0.1); btn_right = new button('>', width-height*0.1, height*0.1, height*0.1, height*0.1); btn_fx = new button('Fx', 0, height*0.9, height*0.1, height*0.1); btn_plus = new button('+', width-height*0.1, height*0.9, height*0.1, height*0.1); btn_new = []; for (let i = 0; i<=26; i++) { btn_new[i] = new button("-", width/3*(i%3), height/10*int(i/3), width/3, height*0.1); btn_new[i].tSize = 15; btn_new[i].lightable = false; } } function draw_buttons() { if (top_mode == 0 || top_mode == 2 ) { btn_menu.create(); } if (btn_menu.clicked==true) { if (top_mode != 2) top_mode = 2; else if (top_mode == 2) top_mode = 0; } if (top_mode == 2) { fill(255,128); noStroke(); rect(btn_menu.x,btn_menu.y,btn_menu.width,btn_menu.height); rect(btn_camtype.x,btn_camtype.y,btn_camtype.width,btn_camtype.height*4.0); btn_camtype.create(); btn_camtype.tSize = 15; if (btn_camtype.clicked==true) { let camera_mode_temp = getItem('camera_mode'); camera_mode_temp = (camera_mode_temp+1.0)%2.0; storeItem('camera_mode', camera_mode_temp); if (camera_mode_temp == 0.0) btn_camtype.text = "CAMERA:\n[ MAIN ]"; if (camera_mode_temp == 1.0) btn_camtype.text = "CAMERA:\n[ FRONTAL ]"; } btn_resolution.create(); btn_resolution.tSize = 15; if (btn_resolution.clicked==true) { let set_resolution_temp = getItem('set_resolution'); set_resolution_temp = (set_resolution_temp+1.0)%4.0; if (set_resolution_temp==0.0) set_resolution_temp = 1.0; storeItem('set_resolution', set_resolution_temp); btn_resolution.text = "SCALE:\n[ "+set_resolution_temp+"X ]"; } btn_calibration.create(); btn_calibration.tSize = 15; btn_calibration.text = "SHAKING:\n[ "+nf(shaker.av_shake,1,1)+" ]"; if (btn_calibration.clicked==true) { shaker.calibration_timer = shaker.calibration_steps; //top_mode = 0; //mouseIsPressed = false; } /* btn_sound.create(); btn_sound.tSize = 15; btn_sound.text = "SOUND:\n[ "+ (sound_enabled == 0 ? "OFF" : "ON") +" ]" if (btn_sound.clicked==true) { sound_enabled == 0 ? sound_enabled = 1 : sound_enabled = 0; storeItem('sound_enabled', sound_enabled); } */ btn_apply.create(); btn_apply.tSize = 15; if (btn_apply.clicked==true) { location.reload(true); } } if (top_mode == 0 || top_mode == 1) btn_hide.create(); if (btn_hide.clicked==true) { if (top_mode != 1) { top_mode = 1; storeItem('top_mode', 1); //btn_hide.text="…"; } else if (top_mode == 1) { top_mode = 0; storeItem('top_mode', 0); //btn_hide.text="HIDE"; } } if (top_mode == 0) { btn_hide.text="HIDE"; btn_hide.x = width*2/3; btn_hide.y = 0; btn_hide.width = width/3; btn_hide.height = height*0.1; } else if (top_mode == 1) { btn_hide.text="…"; btn_hide.x = width-height*0.1; btn_hide.y = 0; btn_hide.width =height*0.1; btn_hide.height = height*0.1; } if (top_mode == 0) { btn_fps.create(); if (frameCount%5==0) fps=int(frameRate()); btn_fps.text = ("FPS: "+fps); btn_modeinfo.create(); if (mShader.mode == 0 ) btn_modeinfo.text = "PURE MODE"; if (mShader.mode == 1 ) btn_modeinfo.text = "COPY MODE"; if (mShader.mode == 2 ) btn_modeinfo.text = "STAMP MODE"; if (mShader.mode == 3 ) btn_modeinfo.text = "DRAW MODE"; btn_aimsel.create(); btn_aim.create(); btn_aim.mode = btn_aimsel.mode; btn_reset.create(); btn_feedback.create(); btn_feedback.bypass=0.15; if (btn_feedback.pressed==true) { fbk=btn_feedback.vset; } btn_a.create(); btn_b.create(); btn_c.create(); btn_x.create(); btn_y.create(); btn_z.create(); btn_f.create(); btn_left.create(); if (btn_left.clicked==true) { mShader.mode = (mShader.mode-1)%mShader.modes_num; if(mShader.mode<0) mShader.mode = mShader.modes_num-1; } btn_right.create(); if (btn_right.clicked==true) { mShader.mode = (mShader.mode+1)%mShader.modes_num; } /* noFill(); vol < vol_av ? stroke(0) : stroke(255,255,0); circle(width / 2, height / 2, vol * btn_aim.width/3); stroke(0); circle(width / 2+1, height / 2+1, vol_av * btn_aim.width/3); stroke(255); circle(width / 2, height / 2, vol_av * btn_aim.width/3); */ noFill(); shaker.Ax < shaker.av_shake*2 ? stroke(0) : stroke(255,255,0); circle(width / 2, height / 2, constrain(shaker.Ax/(shaker.av_shake*2) * btn_aim.width/3, 10, btn_aim.width)); stroke(0); circle(width / 2+1, height / 2+1, btn_aim.width/3); stroke(255); circle(width / 2, height / 2, btn_aim.width/3); } if (scr_mode == 0) { btn_screenshot.create(); if (btn_screenshot.clicked==true) { btn_h.mode = 1; scr_mode = 1; mouseIsPressed = false; btn_cancel.lightable = false; btn_save.lightable = false; //image(stackImg, 0,0,feedImg.width,feedImg.height); //save(stackImg, 'WindyPixel_'+version+"-"+year()+nf(month(),2)+nf(day(),2)+"-"+nf(hour(),2)+nf(minute(),2)+nf(second(),2) +'.jpg'); } } else if (scr_mode == 1) { noStroke(); fill(255,64) rect(height*0.1,height*0.9,width-height*0.2,height*0.1); btn_save.create(); if (btn_save.clicked==true) { save(stackImg, 'WindyPixel_'+version+"-"+year()+nf(month(),2)+nf(day(),2)+"-"+nf(hour(),2)+nf(minute(),2)+nf(second(),2) +'.jpg'); btn_h.mode = 0; scr_mode = 0; mouseIsPressed = false; btn_screenshot.lightable = true; } btn_cancel.create(); if (btn_cancel.clicked==true) { btn_h.mode = 0; scr_mode = 0; mouseIsPressed = false; btn_screenshot.lightable = false; } } btn_fx.create(); if (btn_fx.clicked==true) { if (top_mode != 3) { pr_mode = top_mode; top_mode = 3; } else if (top_mode == 3) { top_mode = pr_mode; } } if (top_mode == 3) { fill(255,128); noStroke(); rect(btn_fx.x,btn_fx.y,btn_fx.width,btn_fx.height); rect(0,0,width,height*0.9); for (let i = 0; i<=26; i++) { btn_new[i].create(); } let i; i = 0 ; btn_new[i].text="FULL\nAUTO"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; btn_a.mode=1; btn_b.mode=1; btn_c.mode=1; autom.let_aim1 = true; autom.let_aim2 = true; autom.let_aim3 = true; autom.let_blur = true; autom.let_x = true; autom.let_y = true; autom.let_z = true; mouseIsPressed = false; } i = 1 ; btn_new[i].text="FULL\nRESET"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=0; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0; btn_aim.y1set=0; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; autom.let_aim1 = false; autom.let_aim2 = false; autom.let_aim3 = false; autom.let_blur = false; autom.let_x = false; autom.let_y = false; autom.let_z = false; mouseIsPressed = false; } i = 2 ; btn_new[i].text="FULL\nRANDOM"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=int(random(2)); btn_y.mode=int(random(2)); btn_z.mode=0; btn_aim.x1set=random(-1,1); btn_aim.y1set=random(-1,1); btn_aim.x2set=random(-1,1); btn_aim.y2set=random(-1,1); btn_aim.x3set=random(-1,1); btn_aim.y3set=random(-1,1); btn_feedback.vset=random(); fbk=btn_feedback.vset; mouseIsPressed = false; } i = 3 ; btn_new[i].text="JUST\nCOPY"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=1; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 4 ; btn_new[i].text="JUST\nSTAMP"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=2; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 5 ; btn_new[i].text="JUST\nDRAW"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=3; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 6 ; btn_new[i].text="ALT\nCOPY"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=1; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=1; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 7 ; btn_new[i].text="ALT\nSTAMP"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=2; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=1; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 8 ; btn_new[i].text="ALT\nDRAW"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=3; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=1; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 9 ; btn_new[i].text="AUTO\nCOPY"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=1; btn_a.mode=1; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; autom.let_aim1 = true; autom.let_aim2 = true; autom.let_aim3 = true; autom.let_blur = true; autom.let_x = true; autom.let_y = true; autom.let_z = true; mouseIsPressed = false; } i = 10 ; btn_new[i].text="AUTO\nSTAMP"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=2; btn_a.mode=1; btn_b.mode=1; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; autom.let_aim1 = true; autom.let_aim2 = true; autom.let_aim3 = true; autom.let_blur = true; autom.let_x = true; autom.let_y = true; autom.let_z = true; mouseIsPressed = false; } i = 11 ; btn_new[i].text="AUTO\nDRAW"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=3; btn_a.mode=1; btn_b.mode=1; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; autom.let_aim1 = true; autom.let_aim2 = true; autom.let_aim3 = true; autom.let_blur = true; autom.let_x = true; autom.let_y = true; autom.let_z = true; mouseIsPressed = false; } i = 12 ; btn_new[i].text="SOFT\nCOPY"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=1; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=1; btn_y.mode=1; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0.5; btn_aim.y2set=0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.5; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 13 ; btn_new[i].text="SOFT\nSTAMP"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=2; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=1; btn_y.mode=1; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0.5; btn_aim.y2set=0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.5; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 14 ; btn_new[i].text="SOFT\nDRAW"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=3; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=1; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0.5; btn_aim.y2set=0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.5; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 15 ; btn_new[i].text="ACID\nCOPY"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=1; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=1; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.55; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 16 ; btn_new[i].text="ACID\nSTAMP"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=2; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=1; btn_y.mode=0; btn_z.mode=1; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0.5; btn_aim.y2set=0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.55; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 17 ; btn_new[i].text="ACID\nDRAW"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=3; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=1; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0.5; btn_aim.y2set=0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.55; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 18 ; btn_new[i].text="GLOWING\nCOPY"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=1; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=1; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.25; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 19 ; btn_new[i].text="GLOWING\nSTAMP"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=2; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=1; btn_y.mode=0; btn_z.mode=1; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0.5; btn_aim.y2set=0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.25; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 20 ; btn_new[i].text="GLOWING\nDRAW"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=3; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=1; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0.5; btn_aim.y2set=0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.25; fbk=btn_feedback.vset; mouseIsPressed = false; } i = 21 ; btn_new[i].text="PORTRAIT"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; //btn_aim.x1set=0.5; //btn_aim.y1set=-0.5; //btn_aim.x2set=0; //btn_aim.y2set=-0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.66; fbk=btn_feedback.vset; btn_a.mode=1; autom.let_aim1 = true; autom.let_aim2 = true; autom.let_aim3 = false; autom.let_blur = false; autom.let_x = false; autom.let_y = false; autom.let_z = false; mouseIsPressed = false; } i = 22 ; btn_new[i].text="GB-CAM"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=0; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_f.mode=1; btn_aim.x1set=0; btn_aim.y1set=0; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0; fbk=btn_feedback.vset; autom.let_aim1 = false; autom.let_aim2 = false; autom.let_aim3 = false; autom.let_blur = false; autom.let_x = false; autom.let_y = false; autom.let_z = false; mouseIsPressed = false; } i = 23 ; btn_new[i].text="SHIFTED"; if (btn_new[i].clicked==true) { storeItem('def_fx', i); top_mode = pr_mode; mShader.mode=0; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_f.mode=0; btn_aim.x1set=0; btn_aim.y1set=0; btn_aim.x2set=0; btn_aim.y2set=0; btn_aim.x3set=0.5; btn_aim.y3set=-0.5; btn_feedback.vset=0; fbk=btn_feedback.vset; autom.let_aim1 = false; autom.let_aim2 = false; autom.let_aim3 = false; autom.let_blur = false; autom.let_x = false; autom.let_y = false; autom.let_z = false; mouseIsPressed = false; } } /* btn_new[9].text="BCN"; if (btn_new[9].clicked==true) { top_mode = pr_mode; mShader.mode=0; btn_a.mode=1; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=0; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0; btn_aim.y2set=-0.5; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.66; fbk=btn_feedback.vset; mouseIsPressed = false; } btn_new[10].text="SOFT\nDRAW"; if (btn_new[10].clicked==true) { top_mode = pr_mode; mShader.mode=3; btn_a.mode=0; btn_b.mode=0; btn_c.mode=0; btn_x.mode=0; btn_y.mode=1; btn_z.mode=0; btn_aim.x1set=0.5; btn_aim.y1set=-0.5; btn_aim.x2set=0.25; btn_aim.y2set=-0.25; btn_aim.x3set=0; btn_aim.y3set=0; btn_feedback.vset=0.5; fbk=btn_feedback.vset; mouseIsPressed = false; } */ btn_plus.create(); shaker.create(); autom.create(); if (btn_a.clicked==true) { if (abs(btn_aim.x1set)+abs(btn_aim.y1set) > 0.01) { autom.let_aim1 = true; //print('autom.let_aim1 = true'); } else { autom.let_aim1 = false; //print('autom.let_aim1 = false'); } if (abs(btn_aim.x2set)+abs(btn_aim.y2set) > 0.01) { autom.let_aim2 = true; //print('autom.let_aim2 = true'); } else { autom.let_aim2 = false; //print('autom.let_aim2 = false'); } if (abs(btn_aim.x3set)+abs(btn_aim.y3set) > 0.01) { autom.let_aim3 = true; //print('autom.let_aim3 = true'); } else { autom.let_aim3 = false; //print('autom.let_aim3 = false'); } if (btn_x.mode == 1) { autom.let_x = true; //print('autom.let_x = true'); } else { autom.let_x = false; //print('autom.let_x = false'); } if (btn_y.mode == 1) { autom.let_y = true; //print('autom.let_y = true'); } else { autom.let_y = false; //print('autom.let_y = false'); } if (btn_z.mode == 1) { autom.let_z = true; //print('autom.let_z = true'); } else { autom.let_z = false; //print('autom.let_z = false'); } if (fbk>0.15) { autom.let_blur = true; //print('autom.let_blur = true'); } else { autom.let_blur = false; //print('autom.let_blur = false'); } } /* if (sound_enabled == 1) { vol = pow(mic.getLevel()+1.0,8); volArray[frameCount%vol_len] = vol; if (frameCount%vol_len==0) { vol_av = 0; for (i = 0; i< vol_len; i++) vol_av += volArray[i]; vol_av/=vol_len; vol_av*=1.05; } } */ } function create_camera() { camera_mode = getItem('camera_mode'); if (camera_mode==getItem('empty_item')) camera_mode = 0.0; //print("camera_mode = " + camera_mode); if (windowWidth>windowHeight) { createCanvas(windowHeight*4/3, windowHeight); } else { createCanvas(windowWidth, windowWidth*4/3); } noStroke(); let camera_mode_string; if (camera_mode == 0.0) camera_mode_string = "environment"; else camera_mode_string = "user"; var camera_settings = { audio: false, video: { // width: {min: 640, ideal: 1280, max: 1920}, // height: {min: 480, ideal: 720, max: 1080}, facingMode: camera_mode_string } }; camera_input = createCapture(camera_settings); //camera_input.size(width, height); camera_input.hide(); } // ============================ MAIN ========================================= // ---------------------------- SETUP ---------------------------------------- function setup() { /* sound_enabled = getItem('sound_enabled'); if (sound_enabled==getItem('empty_item')) sound_enabled = 0; */ top_mode = getItem('top_mode'); if (top_mode==getItem('empty_item')) top_mode = 1; pr_mode = top_mode; set_resolution = getItem('set_resolution'); if (set_resolution==getItem('empty_item')) set_resolution = 1.0; //print("set_resolution = " + set_resolution); pixelDensity(pixelDensity()*set_resolution); def_fx = getItem('def_fx'); if (def_fx==getItem('empty_item')) def_fx = 0; create_camera(); create_buttons(); if (getItem('av_shake') == getItem('empty_item')) shaker.calibration_timer = shaker.calibration_steps; preImg = createGraphics(width, height, WEBGL); preShader = preImg.createShader(shader_vert, preShader_frag); preImg.noStroke(); mainImg = createGraphics(width, height, WEBGL); mainShader = mainImg.createShader(shader_vert, mainShader_frag); mainImg.noStroke(); mShader = new main_shader(); feedImg = createGraphics(width, height, WEBGL); feedShader = feedImg.createShader(shader_vert, feedShader_frag); feedImg.noStroke(); postImg = createGraphics(width, height, WEBGL); postShader = postImg.createShader(shader_vert, postShader_frag); postImg.noStroke(); outImg = createGraphics(width, height); stackImg = createGraphics(width, height); //stackImg0 = createGraphics(width, height); image_input = loadImage('https://sun9-39.userapi.com/ca2jDO-IqtAvr2JF-A-FgvTpkntYeaNOYsiHiw/ednomg14B5k.jpg'); top_mode=3; draw_buttons(); btn_new[def_fx].outclick=true; /* if (sound_enabled == 1) { mic = new p5.AudioIn(); mic.start(); volArray = []; vol_len = 20; } */ } // ----------------------------- DRAW ----------------------------------------- function draw() { //print(top_mode); DT = deltaTime /25; if (btn_f.mode==1 ) { // abs(btn_aim.x1set)+abs(btn_aim.y1set) > 0.01 preShader.setUniform('img_input', camera_input); //preShader.setUniform('img_input', image_input); preShader.setUniform('aimX', btn_aim.x1set/2.0); preShader.setUniform('aimY', btn_aim.y1set/2.0); preShader.setUniform('alt', btn_x.mode); preShader.setUniform('width', width); preShader.setUniform('height', height); preShader.setUniform('piTime', random()); preShader.setUniform('rndX', random()); preShader.setUniform('rndY', random()); preShader.setUniform('pixelSize', 2); // 1+abs(int(btn_aim.x1set*height/10)) preImg.shader(preShader); preImg.rect(0,0,preImg.width, preImg.height); outImg = preImg; //stackImg0.copy(outImg,int(-outImg.width/2),int(-outImg.height/2),outImg.width,outImg.height,0,0,stackImg0.width,stackImg0.height); //outImg = stackImg0; } else outImg = camera_input; if (btn_y.mode == 0) { mShader.create(outImg); outImg = mShader.outImg; } if (fbk>0.15) { feedShader.setUniform('img_input', outImg); feedShader.setUniform('fb_input', feedImg); feedShader.setUniform('fbk', 1.0-(1.0-fbk)*(1.0-fbk) ); feedShader.setUniform('zebra', btn_z.mode); feedShader.setUniform('freeze', btn_h.mode); feedImg.shader(feedShader); feedImg.rect(0,0,feedImg.width, feedImg.height); outImg = feedImg; } if (btn_y.mode == 1) { mShader.create(outImg); outImg = mShader.outImg; } if (abs(btn_aim.x2set)+abs(btn_aim.y2set) > 0.01 || abs(btn_aim.x3set)+abs(btn_aim.y3set) > 0.01) { postShader.setUniform('img_input', outImg); postShader.setUniform('aimX', btn_aim.x2set*2.0); postShader.setUniform('aimY', btn_aim.y2set*2.0); postShader.setUniform('aimX3', btn_aim.x3set); postShader.setUniform('aimY3', btn_aim.y3set); postImg.shader(postShader); postImg.rect(0,0,postImg.width, postImg.height); outImg = postImg; } if (outImg != camera_input) stackImg.copy(outImg,int(-outImg.width/2),int(-outImg.height/2),outImg.width,outImg.height,0,0,stackImg.width,stackImg.height); else stackImg.copy(camera_input,0,0,camera_input.width,camera_input.height,0,0,stackImg.width,stackImg.height); image(stackImg, 0,0,feedImg.width,feedImg.height); draw_buttons(); }