xxxxxxxxxx
//Creating an empty array
let noiseValues = [];
//Setting up the canvas and generating noise values
function setup() {
createCanvas(800, 800);
for (let i = 0; i < 100; i++) {
noiseValues[i] = [];
for (let j = 0; j < 100; j++) {
noiseValues[i][j] = noise(i * 0.05, j * 0.05);
}
}
}
//Drawing Perlin noise on the canvas using lines
function draw() {
for (let i = 0; i < 99; i++) {
for (let j = 0; j < 99; j++) {
//Setting the start and end points of the line
let x1 = i * 8 + 4;
let y1 = j * 8 + 4;
let x2 = (i + 1) * 8 + 4;
let y2 = (j + 1) * 8 + 4;
//Setting the stroke color based on the noise value
stroke(noiseValues[i][j] * 255);
//Determining the angle of the line based on the noise value
let angle = noiseValues[i][j] * TWO_PI;
//Drawing a straight line from the start point to the end point
line(x1, y1, x2, y2);
//Rotating the canvas around the start point
translate(x1, y1);
rotate(angle);
//Drawing a vertical line with the same length as the previous line
let lineLength = dist(x1, y1, x2, y2);
line(0, 0, 0, lineLength);
//Resetting the canvas rotation and translation
rotate(-angle);
translate(-x1, -y1);
}
}
}