xxxxxxxxxx
59
let pixShader = `precision highp float;
// x,y coordinates, given from the vertex shader
varying vec2 vTexCoord;
// the canvas contents, given from filter()
uniform sampler2D tex0;
// other useful information from the canvas
uniform vec2 texelSize;
uniform vec2 canvasSize;
// a custom variable from this sketch
uniform float darkness;
void main() {
float dist = sqrt( ( 0.5 - vTexCoord.x )*( 0.5 - vTexCoord.x ) + ( 0.5 - vTexCoord.y )*( 0.5 - vTexCoord.y ) );
float rot = atan(( 0.5 - vTexCoord.y ) / ( 0.5 - vTexCoord.x ));
if(vTexCoord.x < 0.5){
rot += 3.14159265359;
}
if(dist<1.0){
rot += 1.0/((dist+0.03)*4.0);
}
vec2 coord = vec2(0.5 + cos(rot)*dist, 0.5 + sin(rot)*dist);
// get the color at current pixel
// no
vec4 color = texture2D(tex0, coord);
// set the output color
color *= 1.0;
gl_FragColor = vec4(color.rgb, 1.0);
}
`
let img
let Filter
function preload(){
img = loadImage("/image.png")
}
function setup() {
createCanvas(808, 459);
Filter = createFilterShader(pixShader)
}
function draw() {
background(10);
image(img,0,0)
filter(Filter)
}