-
Notifications
You must be signed in to change notification settings - Fork 0
/
space-image.js
49 lines (46 loc) · 1.3 KB
/
space-image.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
var spaceImage;
function setup() {
createCanvas(windowWidth, windowHeight);
spaceImage = generateSpaceImage();
}
function draw() {
image(spaceImage, 0, 0);
}
function generateSpaceImage() {
let image = createGraphics(width, height);
image.pixelDensity(1);
image.noSmooth();
let backgroundColor = color('#1F1F1F');
let purple = color('#4a455a');
image.background(backgroundColor);
for (let i = 0; i < width; i++) {
let mappedWidth = map(i, 0, width, -1, 1);
let lerpedPurple = lerpColor(purple, backgroundColor, abs(mappedWidth));
image.stroke(lerpedPurple);
image.line(i, 0, i, height);
}
let maxStars = width;
let starWarm = color('#eaeace');
let starCold = color('#ffc4c4');
let starHot = color('#ceeae9');
for (let i = 0; i < maxStars; i++) {
let locationX = random(0, width);
let locationY = random(0, height);
let starSize = random(0.1, 1.5);
let randomAlpha = random(1, 200);
let pickColor = floor(random(0, 3));
let strokeColor;
if (pickColor === 0) {
strokeColor = starWarm;
} else if (pickColor === 1) {
strokeColor = starCold;
} else {
strokeColor = starHot;
}
strokeColor.setAlpha(randomAlpha);
image.stroke(strokeColor);
image.strokeWeight(starSize);
image.point(locationX, locationY);
}
return image;
}