xxxxxxxxxx
// by SamuelYAN
// more works //
// https://twitter.com/SamuelAnn0924
// https://www.instagram.com/samuel_yan_1990/
// reference: https://gorillasun.de/blog/Radial-Perlin-Noise-and-Generative-Tree-Rings
// reference: https://www.reddit.com/r/processing/comments/awzkgd/tree_rings_made_with_perlin_noise/
// Shape of TIME
let mySize, radius;
var Tree_r;
var Stroke_Weight;
// colors without alpha
const palettes = [
["#ffffff", "#008000", "#00623e", "#5c5d", "#74905d"],
["#ffffff", "#008000", "#00623e", "#5c5d", "#74905d"],
["#ffffff", "#008000", "#00623e", "#5c5d", "#74905d"],
["#F1D302", "#358600", "#095256e", "#5EFC8D", "#087F8C"],
["#F1D302", "#358600", "#095256e", "#5EFC8D", "#087F8C"]
]
/** OPC START **/
OPC.slider('TIME', Math.floor(Math.random() * 1000), 0, 1000, 1); // seed
OPC.slider('age', 200, 100, 200, 1); //tree_rings
OPC.slider('youth', 3, 0, palettes.length - 1, 1); // color
OPC.slider('Wrinkle', 0.015, 0.005, 0.020, 0.001);
OPC.slider('pressure', 25, 20, 40, 1); // noise_scale
/** OPC END **/
let PTIME = TIME;
let Page = age;
let Pyouth = youth;
let Pwrinkle = Wrinkle;
let Ppressure = pressure;
function setup() {
// pixelDensity(5);
randomSeed(TIME);
noiseSeed(TIME);
mySize = min(windowWidth, windowHeight);
createCanvas(windowWidth, windowHeight);
background("#fafdff");
Tree_r = 2;
Stroke_Weight = 2;
}
function draw() {
randomSeed(TIME);
noiseSeed(TIME);
background("#eb6424");
noFill();
radius = mySize / 5 * Tree_r;
push();
translate(width / 2, height / 2);
rotate(random(-TAU,TAU));
for (let r = -radius / age; r < radius; r += radius / age) {
stroke(random(palettes[youth]));
strokeWeight(random(Stroke_Weight/2,Stroke_Weight));
strokeCap(SQUARE);
beginShape();
for (
let a = -TAU / (age-2); a < TAU + TAU / age; a += TAU / age
) {
let x = r *1.2 * cos(a);
let y =r *1.2 * sin(a);
let n = map(noise(x * Wrinkle, y * Wrinkle), 0, 1, -pressure, pressure);
curveVertex(x + n, y + n);
if (random(1) > 0.75 - 0.25 * sin(r)) {
endShape();
beginShape();
}
}
endShape();
}
pop();
if (PTIME != TIME ||
Page != age ||
Pyouth != youth ||
Pwrinkle != Wrinkle ||
Ppressure != pressure ) {
PTIME = TIME;
Page = age;
Pyouth = youth;
Pwrinkle = Wrinkle;
Ppressure = pressure;
randomSeed(TIME);
noiseSeed(TIME);
background("#fafdff");
Stroke_Weight = random(1,4);
}
}
function keyTyped() {
if (key === "s" || key === "S") {
saveCanvas("Shape of TIME_tree rings", "png");
}
}