xxxxxxxxxx
let url = "https://coolors.co/355070-6d597a-b56576-e56b6f-eaac8b";
let palette;
let points = [];
let points_num = 50;
let sw = 1;
let angleMax = 180; // 0~1のノイズを角度に当てはめるときの幅(この場合0°~180°)
function setup() {
createCanvas(800, 800);
colorMode(HSB, 360, 100, 100, 100);
angleMode(DEGREES);
palette = createPalette(url);
noSmooth();
points = [];
for (let i = 0; i < points_num; i++) {
let x = random(width);
let y = random(height);
let p = createVector(x, y);
p.color = random(palette);
p.ns = random(400, 1800);
points.push(p);
}
background(0, 0, 100);
}
function draw() {
// blendMode(BLEND);
// copy(0,0,width,height,-5,-5,width+10,height+10);
// background(0, 0, 100, 1);
// blendMode(ADD);
// clear();
for (let p of points) {
//点pの位置を基にしたnoiseを用いて角度を作る
let angle = noise(p.x / p.ns, p.y / p.ns) * angleMax;
//角度を基にVectorを作成し,点pに足す
p.add(p5.Vector.fromAngle(angle));
if (p.x > width + sw) {
p.x = 0;
p.y = random(height);
}
if (p.y > height + sw) {
p.x = random(width);
p.y = 0;
}
if (p.x < 0 - sw) {
p.x = width;
p.y = random(height);
}
if (p.y < 0 - sw) {
p.x = random(width);
p.y = height;
}
for (let q of points) {
if (q.equals(p) != true) {
let dMax = 150;
let distance = p5.Vector.dist(p, q);
let distance_ratio = distance / dMax;
if (distance < dMax) {
stroke(q.color);
strokeWeight(sw - sw * distance_ratio);
// point(q.x, q.y);
// strokeWeight(3 - distance_ratio * 3);
// stroke(0, 0, 100, 100 - distance_ratio * 100);
colorMode(RGB);
let nc = lerpColor(q.color, p.color, 0.5);
colorMode(HSB, 360, 100, 100, 100);
stroke(nc);
// stroke(0,0,100);
line(p.x, p.y, q.x, q.y);
}
}
}
}
if (frameCount % 1000 == 0) {
setup();
}
}
function createPalette(_url) {
let slash_index = _url.lastIndexOf('/');
let pallate_str = _url.slice(slash_index + 1);
let arr = pallate_str.split('-');
for (let i = 0; i < arr.length; i++) {
arr[i] = color('#' + arr[i]);
}
return arr;
}