xxxxxxxxxx
94
let frag, vert;
let sh, psh;
let fb;
let circleCount = 30;
let circleOffsets = [];
let curTime = 0;
let fps = 0;
let WEBGL_MODE;
function mod(a, b) {
return (a % b + b) % b;
}
function preload() {
frag = loadStrings('shader.frag');
vert = loadStrings('shader.vert');
pointFrag = loadStrings('point.frag');
pointVert = loadStrings('point.vert');
//result = loadStrings('/shader.frag');
}
function setup() {
createCanvas(600, 600, WEBGL);
background(0);
noStroke();
WEBGL_MODE = _renderer.drawingContext instanceof WebGLRenderingContext;
fb = createGraphics(width, height, WEBGL);
fb.noStroke();
frag = frag.join('\n');
vert = vert.join('\n');
sh = fb.createShader(vert, frag);
pointFrag = pointFrag.join('\n');
pointVert = pointVert.join('\n');
psh = createShader(pointVert, pointFrag);
for (let i = 0; i < circleCount * circleCount; i++) {
circleOffsets.push(createVector(random(0, 0), random(0, 0)));
}
fb.shader(sh);
}
function draw() {
sh.setUniform('uResolution', width, height);
sh.setUniform('uTime', millis() / 1000);
sh.setUniform('uFrame', frameCount);
fb.quad(-1, -1, 1, -1, 1, 1, -1, 1);
//image(fb, -width/2, -height/2);
fb.loadPixels();
if (WEBGL_MODE)
translate(-width/2, -height/2);
image(fb, 0, 0);
let pd = pixelDensity();
shader(psh);
//stroke(255, 120, 25);
beginShape(POINTS);
let r = width/circleCount*1.45;
for (let x = 0; x < circleCount; x++) {
for (let y = 0; y < circleCount; y++) {
let co = circleOffsets[x + y * circleCount];
let xp = int((x + co.x) / (circleCount-1) * width);
let yp = int((y + co.y) / (circleCount-1) * height);
let f = fb.pixels[(xp + mod(height - yp*2, height) * width) * pd * 4];
vertex(xp, yp);
//strokeWeight(r * f / 255);
//point(xp, yp);
}
}
endShape();
if (curTime > 1000) {
print('FPS: ' + fps);
curTime -= 1000;
fps = 0;
}
curTime += deltaTime;
fps++;
}