IF3Si/pde/IF3Si/tiles.pde

98 lines
3.3 KiB
Plaintext

/*
This file is part of "Interface Fractures III - Silicon".
Copyright (c) 2015 Luka Prinčič, All rights reserved.
This program is free software distributed under
GNU General Public Licence. See COPYING for more info.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
tiles.pde
*/
// TILES - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* TODO:
- different zooms (random?)
- better rotation
- multiple instances of the same thing - with
different texture & some parameters + parameterize
- zoom variations
- ?amount of speed variations accross tiles
*/
void tiles( boolean render, // should we render or not?
color bgfill, // backgorund color
color tilecolor, // tile color
int huedist, // tile color distance for interpolation
int blendMode, // blending mode of tiles
int numx, // number of tiles on X
int numy, // number of tiles on Y
int texBank,
int texNum,
float texSpeedX,
float texSpeedY,
float overlap )
{
if (render) {
colorMode(HSB, 360, 100, 100, 100);
blendMode(BLEND);
fill(bgfill);
noStroke();
rect(0, 0, width, height);
switchBlendMode(blendMode); // blendMode function using integers
texSpeedX *= 0.01;
texSpeedY *= 0.01;
texX += sq(texSpeedX);
texY += sq(texSpeedY);
float numxfact = 1 / float(numx);
float numyfact = 1 / float(numy);
float aspectRatio = (height / float(numy)) / (width / float(numx));
float offsetPerc = overlap * (300/127);
float uniZoom = numxfact * (float(width)/1024);
float offsetX = width * numxfact * offsetPerc * 0.01;
float offsetY = height * numyfact * offsetPerc * 0.01;
float texoffsetX = 1 + 0.01 * offsetPerc ;
float texoffsetY = texoffsetX;
float huefactor = float(huedist) / (numx * numy);
for (int nx=0; nx < numx; nx++) {
for (int ny=0; ny < numy; ny++) {
int tileID = nx * numy + ny;
float randX = rands[ (tileID % rands.length) ] * 0.01;
float randY = rands[ ((tileID + 50) % rands.length) ] * 0.01;
float newhue = hue(tilecolor) + huefactor * tileID;
tint(newhue, saturation(tilecolor), brightness(tilecolor), alpha(tilecolor));
textureWrap(REPEAT);
textureMode(NORMAL);
beginShape();
texture(imgPool[texBank][texNum]);
vertex(width * numxfact * nx - offsetX, height * numyfact * ny - offsetY, 0 + texX * randX, 0 + texY * randY);
vertex(width * numxfact * (nx + 1) + offsetX, height * numyfact * ny - offsetY, 1 * uniZoom * texoffsetX + texX * randX, 0 + texY * randY);
vertex(width * numxfact * (nx + 1) + offsetX, height * numyfact * (ny + 1) + offsetY, 1 * uniZoom * texoffsetX + texX * randX, aspectRatio * uniZoom * texoffsetY + texY * randY);
vertex(width * numxfact * nx - offsetX, height * numyfact * (ny + 1) + offsetY, 0 + texX * randX, aspectRatio * uniZoom * texoffsetY + texY * randY);
endShape();
}
}
}
}