-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplice.js
59 lines (51 loc) · 1.88 KB
/
splice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// P5 autocomplete/helpers for VSCODE
/// <reference path="./types/p5.global-mode.d.ts" />
// "use strict";
/**
* @param {Object} args all inputs
* @param {object} args.p5 the p5 instance
* @param {object} args.params the parameters
* @param {object[]} args.params.colors the input colors
* @param {p5.Color} args.params.colors[].color the p5 color object
* @param {number} args.params.colors[].freq the frequency of that color in the original
* @param {string} args.params.colors[].hex the color hex value
* @param {number[]} args.params.colors[].rgb the 3 RGB values of that color
* @param {object} args.dim
* @param {number} args.dim.w the canvas width
* @param {number} args.dim.h the canvas height
*/
///////////////// YOUR CODE STARTS HERE ///////////////////////
function splice({ p5, params, dim }) {
// all your code must go inside this function.
// no animation, no draw() function needed
//destructure input parameters
const { colors } = params;
// CLASSES must be defined before THE ALGORITHM
class C {
constructor() {
this.x = dim.w / 2;
this.y = dim.h / 2;
}
}
// FUNCTIONS can be defined before or after THE ALGORITHM
// the random seed is deterministic / derived from the NFT origin (@see params.js)
function randomCircle(x, y) {
const radius = p5.random(100, 200);
p5.fill(p5.random(colors).color);
p5.stroke(p5.random(colors).color);
p5.strokeWeight(p5.random(1, 5));
p5.ellipse(x, y, radius, radius);
}
/////////////////// THE ALGORITHM ////////////////////////////////
let y = dim.h;
for (let color of colors) {
p5.fill(color.color); // colors[].color is a p5 color
p5.strokeWeight(0);
y = y - color.freq * dim.h;
p5.rect(0, y, dim.w, color.freq * dim.h);
}
let center = new C();
p5.noStroke();
randomCircle(center.x, center.y);
}
/////////////// END OF YOUR CODE ////////////////////////