xxxxxxxxxx
138
let postProcessShader;
let buffer;
let fullnessSlider;
let washoutSlider;
let testImage;
let lake;
let aurora;
let miami;
let mom1;
let mom2;
let eightBitSquare;
let eightBitSquareShadow;
let locke;
let doug;
let chip;
let img;
let atlas;
let chips = [];
let chipIndex = 0;
let frameDelay = 4;
let frameCounter = 0;
const chipCount = 16;
const defaultFrameDelay = 4;
let scaleX;
let scaleY;
function preload()
{
postProcessShader = loadShader("FullQuad.vert", "Textify.frag");
testImage = loadImage("Ambient occlusion test image.png");
lake = loadImage("A Perfect Lake.jpg");
aurora = loadImage("Alaskan Aurora.jpg");
miami = loadImage("MiamiSoftware.png");
eightBitSquare = loadImage("EightBitSquare.png");
eightBitSquareShadow = loadImage("EightBitSquareShadow.png");
mom1 = loadImage("Mom Playing Zelda pt 1.jpg");
mom2 = loadImage("Mom Playing Zelda pt 2.jpg");
locke = loadImage("LockeLarge.png");
doug = loadImage("Silly portrait of Doug.jpg");
chip = loadImage("SpinningChipWithText.gif");
for (let i = 0; i < chipCount; ++i)
{
let numStr = i < 10 ? `0${i}` : `${i}`;
let path = `Images/Chip${numStr}.png`;
chips.push(loadImage(path));
}
}
function setup()
{
img = chips[0];
atlas = eightBitSquare;
scaleX = 4;
scaleY = 4;
let w = img.width * scaleX;
let h = img.height * scaleY;
createCanvas(w, h, WEBGL);
shader(postProcessShader);
}
function draw()
{
let sw = img.width * scaleX;
let sh = img.height * scaleY;
let aw = atlas.width;
let ah = atlas.height;
let tw = 8;
let th = 8;
let indexMin = 5;
let bg = [0, 0, 0];
postProcessShader.setUniform("uSource", chips[chipIndex]);
postProcessShader.setUniform("uTileAtlas", atlas);
postProcessShader.setUniform("uSourceSize", [sw, sh]);
postProcessShader.setUniform("uAtlasSize", [aw, ah]);
postProcessShader.setUniform("uTileSize", [tw, th]);
postProcessShader.setUniform("uTileIndexMin", indexMin);
postProcessShader.setUniform("uBackgroundColor", bg);
rect(0, 0, 0, 0);
++frameCounter;
if (frameCounter >= frameDelay)
{
frameCounter %= frameDelay;
chipIndex = (chipIndex + 1) % chipCount;
}
}
function keyPressed()
{
if (keyCode === 32)
TogglePause();
else if (keyCode === RIGHT_ARROW)
Step();
}
function TogglePause()
{
if (isLooping())
Pause();
else
Unpause();
}
function Pause()
{
noLoop();
frameDelay = 1;
}
function Unpause()
{
loop();
frameDelay = defaultFrameDelay;
}
function Step()
{
Pause();
redraw();
}