xxxxxxxxxx
// By Roni Kaufman
// inspired by https://www.openprocessing.org/sketch/867695
// and by https://www.openprocessing.org/sketch/494102
// and also after Jack Kirby's collages
let particles;
let squiggliness = 1/500;
//let palette = [0.01, 0.13, 0.4, 0.5, 0.65, 0.9];
let palette = 1;
let nPlanets, nStars;
let surfer;
function preload() {
surfer = loadImage('surfer.png');
}
function setup() {
createCanvas(600, 600);
colorMode(HSB, 1);
noStroke();
background(0.14, 0.5, 0.05);
createParticles(0.9);
nPlanets = floor(random(15, 25));
nStars = floor(random(100, 150));
surfer.resize(random(200, 300), 0);
}
function draw() {
if (frameCount < 500) {
for (let p of particles) {
p.draw();
p.move();
}
} else if (frameCount < 600) {
addStars();
}else if (frameCount < 600 + nPlanets) {
addPlanet();
} else {
addSurfer();
noLoop();
}
}
function createParticles(hue) {
particles = [];
for (let i = 0; i < 1000; i++) {
let x_ = random(-10, width+10);
let y_ = random(-10, height+10);
let s_ = 1;
let c_ = color(hue, 0.05);
particles.push(new Particle(x_, y_, s_, c_));
}
}
function Particle(x_, y_, s_, c_) {
this.x = x_;
this.y = y_;
this.size = s_;
this.c = c_;
this.dist = 0.5;
this.move = function() {
let theta = noise(this.x * squiggliness, this.y * squiggliness)*PI/squiggliness;
let v = p5.Vector.fromAngle(theta, this.dist);
this.x += v.x;
this.y += v.y;
}
this.draw = function() {
fill(this.c);
circle(this.x, this.y, this.size);
}
}
function addPlanet() {
/*
let sep = 50;
let x1 = floor(random(sep)+1/2)*width/sep;
let y1 = floor(random(sep)+1/2)*height/sep;
*/
let x1 = random(width);
let y1 = random(height);
let size = random(10, 130);
let hue = random(palette);
drawingContext.shadowBlur = 8;
drawingContext.shadowColor = color(0);
fill(hue, 0.9, 1);
circle(x1, y1, size);
drawingContext.shadowBlur = 0;
let density = size * random(0.5, 1.5);
fill((hue + 0.5)%1, 0.8, 1, 0.8);
for (let i = 0; i < pow(size, 2)*5; i++) {
let x2 = random(x1 - size/2, x1 + size/2);
let y2 = random(y1 - size/2, y1 + size/2);
let noize = noise(x2 / density, y2 / density, frameCount);
if (dist(x1, y1, x2, y2) < size/2) {
if (floor(noize*50) % 2 === 0) {
fill(hue, 0.9, 0.8, 0.9);
} else {
fill((hue + 0.5)%1, 0.9, 1, 0.9);
}
circle(x2, y2, noize);
}
}
}
function addStars() {
fill(0.9, 1);
let density = 100;
for (let i = 0; i < nStars; i++) {
let x = random(width);
let y = random(height);
let size = random(1, 2);
let noize = noise(x / density, y / density);
if (floor(noize * 10) % 2 === 0) {
x += random(-5, 5);
y += random(-5, 5);
circle(x, y, size);
}
}
}
function addSurfer() {
image(surfer, random(width - surfer.width), random(height - surfer.height));
}