xxxxxxxxxx
90
var angle, angle2; // global variables for the main angles determining the design of my fractals
var tround = 0; // global variable controlling the spin direction of the nebulae
var xoff = 0; // the variable to offset Perlin noise value
let mySound;
function preload() {
soundFormats('mp3', 'ogg');
mySound = loadSound('music/music.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
textSize(16);
mySound.loop();
}
function draw() {
background(0);
fill(255);
text('Mouse Move or Press', windowWidth / 2, windowHeight / 2)
textAlign(CENTER, CENTER);
var nr = map(noise(xoff), 0, 1, PI / 6, PI / 2);
// Perlin noise will be used for the angle of my fractal branches (30 - 90)
//2 angles will vary based on the mouse position: vertical and horizontal axes
angle = map(mouseX, 0, width, nr, nr * 2);
angle2 = map(mouseY, 0, height, -nr / 2, nr / 2);
push()
// Start the tree from the center
translate(width / 2, height / 2);
if (mouseIsPressed) { //keep the mouse pressed for more hypnotic results
rotate(tround * 3);
tround++;
}
// here are multiple calls for all my branches to grow
for (t = 0; t <= 360; t += 36) {
var nc = floor(map(nr, PI / 6, PI / 2, 0, 55)); // color of the branches is also determined by Perlin Noise
// print(nc);
// stroke(200 + nc, nc, 120+nc);
stroke(100 + nc, nc, 120 + nc);
push();
rotate(angle2 + t);
branch(angle * 100, 1);
pop();
// stroke(150 + nc, nc * 2, 120+nc);
stroke(150 + nc, nc, 120 + nc);
push();
rotate(angle2 + t);
branch(angle * 200, 1);
pop();
// stroke(100 + nc, nc * 4, 120+nc);
stroke(50 + nc, nc, 120 + nc);
push();
rotate(angle2 + t);
branch(angle * 300, 1);
pop();
}
pop();
xoff += 0.01; // moving forward my Perlin Noise "timeline"
}
function branch(len, generation) {
// Draw the branch
strokeWeight(map(generation, 1, 10, 0, 3));
line(0, 0, 0, -len);
// Move to the end and shrink.
translate(0, -len);
len *= 0.66;
generation++;
// the recursion happens here
if (len > 2) {
push();
rotate(angle / 2 * angle);
branch(len * 0.5, generation);
pop();
// the other branch
push();
rotate(angle2 * 2);
branch(len, generation);
pop();
}
}