xxxxxxxxxx
91
let canvasSize = 600;
let seed = 1;
let tileAmount = 20; // amount of grid tiles (across) in the canvas.
let tileSize; // size of tiles in pixels
let drawGridCorners = true;
function setup() {
createCanvas(canvasSize, canvasSize);
background(220);
tileSize = canvasSize / tileAmount;
for (gridX = 0; gridX < tileAmount; gridX++)
{
for (gridY = 0; gridY < tileAmount; gridY++)
{
// fill in from (grid_x,grid_y) to (grid_x+1,grid_y+1)
// get a random vector corresponding to each corner.
// dot product the location of the point (as a vector from a corner) with the random vector (of that corner), and average each of those?
// random vector:
let TL_RandomCornerVector = GetCornerVector(gridX, gridY);
let TR_RandomCornerVector = GetCornerVector(gridX + 1, gridY);
let BR_RandomCornerVector = GetCornerVector(gridX + 1, gridY + 1);
let BL_RandomCornerVector = GetCornerVector(gridX, gridY + 1);
stroke(0);
fill(0);
if (drawGridCorners)
{
circle(gridX * tileSize, gridY * tileSize, 2);
line(gridX * tileSize, gridY * tileSize,
TL_RandomCornerVector.x * 5 + gridX * tileSize,
TL_RandomCornerVector.y * 5 + gridY * tileSize);
line((gridX + 1) * tileSize, (gridY + 1) * tileSize,
BR_RandomCornerVector.x * 5 + (gridX + 1) * tileSize,
BR_RandomCornerVector.y * 5 + (gridY + 1) * tileSize);
}
//
for (x = gridX * tileSize; x < (gridX + 1) * tileSize; x ++)
{
for (y = gridY * tileSize; y < (gridY + 1) * tileSize; y ++)
{
let TL = GetDot(x, y, TL_RandomCornerVector);
let TR = GetDot(x - tileSize, y, TR_RandomCornerVector);
//TR = 1;
let BR = GetDot(x - tileSize, y - tileSize, BR_RandomCornerVector);
let BL = GetDot(x, y - tileSize, BL_RandomCornerVector);
let average = (TL + TR + BR + BL) / 4;
//console.log(TL + " " + TR + " " + BR + " " + BL);
console.log(average * 255);
stroke((average + 0.5) * 255);
point(x, y);
}
}
//
}
}
}
function draw() {
}
function GetCornerVector(indexX, indexY)
{
let angle = (sin(indexX + indexY) + cos(indexX - indexY)) * 0.5; // probably switch this to x - y or something, anything to reduce the symmetry.
//let x = cos(angle);
let x = cos(indexX);
//let y = sin(angle);
let y = cos(indexY);
//return createVector(x, y);
return p5.Vector.random2D();
}
function GetDot(x, y, randomVector)
{
let cornerPositionVector = createVector(x - gridX * tileSize, y - gridX * tileSize);
cornerPositionVector = cornerPositionVector.normalize();
return cornerPositionVector.dot(randomVector);
}