0x92cb54e8…dc61sent to0x499f4943…3001·#15,255,285·view on Etherscan
BigBangH0xc7baaa5cab68007340396847497c487dc1311fc51ac186f0c170b7aaaf73af53```
const DEFAULT_DIM = 400;
let background;
let ballArea;
let balls;
let blendMode;
let borders;
let margin;
let metadata;
let quantized;
let trailWipe;
let waitTime;
let wrap;
function Ball(index, color) {
// Start centered.
this.x = ballArea / 2;
this.y = ballArea / 2;
this.size = p.floor(p.random(3, 51));
// Initial direction and speed.
const direction = p.random(p.TWO_PI);
const speed = 7 * p.sqrt(p.random());
this.xspeed = speed * p.sin(direction);
this.yspeed = speed * p.cos(direction);
if (quantized) {
this.xspeed = p.round(this.xspeed);
this.yspeed = p.round(this.yspeed);
}
this.color = color;
metadata[`Ball #${index + 1} - Size`] = this.size;
metadata[`Ball #${index + 1} - X Speed`] = this.xspeed;
metadata[`Ball #${index + 1} - Y Speed`] = this.yspeed;
metadata[`Ball #${index + 1} - Color`] = this.color.toString("#rrggbb");
this.update = function() {
this.x += this.xspeed;
this.y += this.yspeed;
if (wrap) {
this.wrap();
} else {
this.bounce();
}
};
this.display = function() {
p.fill(this.color);
p.ellipse(this.x, this.y, this.size, this.size);
if (wrap) {
p.ellipse(this.x - ballArea, this.y - ballArea, this.size, this.size);
p.ellipse(this.x - ballArea, this.y, this.size, this.size);
p.ellipse(this.x - ballArea, this.y + ballArea, this.size, this.size);
p.ellipse(this.x, this.y - ballArea, this.size, this.size);
p.ellipse(this.x, this.y + ballArea, this.size, this.size);
p.ellipse(this.x + ballArea, this.y - ballArea, this.size, this.size);
p.ellipse(this.x + ballArea, this.y, this.size, this.size);
p.ellipse(this.x + ballArea, this.y + ballArea, this.size, this.size);
}
};
this.bounce = function() {
if (this.x < 0) {
this.x *= -1;
this.xspeed *= -1;
} else if (this.x > ballArea) {
this.x = 2 * ballArea - this.x;
this.xspeed *= -1;
}
if (this.y < 0) {
this.y *= -1;
this.yspeed *= -1;
} else if (this.y > ballArea) {
this.y = 2 * ballArea - this.y;
this.yspeed *= -1;
}
};
this.wrap = function() {
if (this.x < 0) {
this.x += ballArea;
} else if (this.x > ballArea) {
this.x -= ballArea;
}
if (this.y < 0) {
this.y += ballArea;
} else if (this.y > ballArea) {
this.y -= ballArea;
}
};
}
p.myCustomRedrawAccordingToNewPropsHandler = props => {
if (props.transactionHash && props.square) {
const WIDTH = (window.innerWidth) / props.square * 0.8;
const HEIGHT = (window.innerHeight) / props.square * 0.8;
const DIM = p.min(WIDTH, HEIGHT);
p.createCanvas(DIM, DIM);
p.frameRate(60);
metadata = {};
// Seed the p5js random seed using the first 32 bits of the hash.
if(props.editionId &&
((props.editionId >= 586 && props.editionId <= 635) ||
(props.editionId >= 938 && props.editionId <= 962)
)
)
{
p.randomSeed(+props.transactionHash.substr(0, 10));
metadata["ExtraRandom"] = "True";
const burn = 150 * (props.editionId % 50);
for (let i = 0; i < burn; i++) {
p.random();
}
} else {
p.randomSeed(+props.transactionHash.substr(0, 10));
metadata["ExtraRandom"] = "False";
}
// Set up the style.
let getBallColor;
let styleThreshold = 0;
const style = p.random(100);
p.colorMode(p.HSL, 1);
blendMode = p.BLEND;
margin = 25 * p.floor(p.random(4));
ballArea = DEFAULT_DIM - 2 * margin;
borders = p.random(7) >= 1;
quantized = p.random(18) >= 1;
waitTime = p.floor(p.random(300));
wrap = p.random(10) < 1;
const trail = p.random(6) < 1;
const ballCount = p.floor(p.random(2, 4) * p.random(2, 5));
if (style < (styleThreshold += 16)) {
metadata["Style"] = "Monochrome";
const hue = p.random();
const saturation = p.random();
getBallColor = _ => p.color(hue, saturation, p.random());
const lightness = p.random();
background = p.color(hue, saturation, lightness);
trailWipe = p.color(hue, saturation, lightness, trail ? 2 / 3 : 1);
} else if (style < (styleThreshold += 14)) {
metadata["Style"] = "Spectrum";
const hue = p.random();
const span = 0.25 + p.random(0.25);
getBallColor = i =>
p.color(hue + span * (i / (ballCount - 1)), p.random(0.5, 1), p.random(1, 2) / 3);
const saturation = p.random(0.25, 0.75);
const lightness = p.random();
const backgroundHue = hue + p.random(span);
background = p.color(backgroundHue, 1 - saturation, lightness);
trailWipe = p.color(backgroundHue, 1 - saturation, lightness, trail ? 2 / 3 : 1);
} else if (style < (styleThreshold += 20)) {
metadata["Style"] = "Spotlight";
blendMode = p.ADD;
borders = !borders;
getBallColor = _ => p.color(p.floor(p.random(6)) / 6, p.random() < 0.1, p.random() ** 1.5);
background = p.color(0);
trailWipe = p.color(0, 0, 0, trail ? 2 / 3 : 1);
} else {
metadata["Style"] = "Random";
p.colorMode(p.RGB, 1);
getBallColor = _ => p.color(p.random(), p.random(), p.random());
const red = p.random(),
green = p.random(),
blue = p.random();
background = p.color(red, green, blue);
trailWipe = p.color(red, green, blue, trail ? 2 / 3 : 1);
}
p.background(background);
metadata["Background"] = background.toString("#rrggbb");
metadata["Borders"] = borders ? "Yes" : "No";
metadata["Dwell Before Bang"] = waitTime;
metadata["Edges"] = wrap ? "Wrap" : "Bounce";
metadata["Margin"] = margin;
metadata["Number of Balls"] = ballCount;
metadata["Speeds"] = quantized ? "Quantized" : "Varied";
metadata["Trails"] = trail ? "Yes" : "No";
metadata["transactionHash"] = props.transactionHash;
// Create ball objects.
balls = [];
for (var i = 0; i < ballCount; i++) {
balls[i] = new Ball(i, getBallColor(i));
}
metadata["Stillness"] =
balls.some(ball => !ball.xspeed && !ball.yspeed) ? "Yes" : "No";
console.log("metadata: ", metadata);
}
};
p.draw = _ => {
if (balls.length) {
// Allows all calculations to be based on DEFAULT_DIM.
p.scale(p.width / DEFAULT_DIM);
p.translate(margin, margin);
p.blendMode(p.BLEND);
p.background(trailWipe);
p.blendMode(blendMode);
if (borders) {
p.stroke(0);
p.strokeWeight(+borders);
} else {
p.noStroke();
}
// Update and draw each ball.
if (p.frameCount == 1 || p.frameCount > waitTime) {
for (var i = 0; i < balls.length; i++) {
balls[i].update();
balls[i].display();
}
} else {
for (var i = 0; i < balls.length; i++) {
balls[i].display();
}
}
p.fill(background);
if (margin && wrap) {
p.noStroke();
p.rect(-margin, -margin, DEFAULT_DIM, margin);
p.rect(-margin, -margin, margin, DEFAULT_DIM);
p.rect(-margin, ballArea, DEFAULT_DIM, margin);
p.rect(ballArea, -margin, margin, DEFAULT_DIM);
}
}
}
```