forked from ehmorris/lunar-lander
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththeme.js
160 lines (144 loc) · 4.13 KB
/
theme.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { LANDER_WIDTH } from "./helpers/constants.js";
const horizon = 0.72;
const makeLanderGradient = (
CTX,
color1,
color2,
color3,
color4,
width = LANDER_WIDTH
) => {
const gradient = CTX.createLinearGradient(-width / 2, 0, width / 2, 0);
gradient.addColorStop(0, color1);
gradient.addColorStop(0.3, color2);
gradient.addColorStop(0.6, color3);
gradient.addColorStop(1, color4);
return gradient;
};
const makeHawaiiBackgroundGradient = (CTX, canvasHeight) => {
const gradient = CTX.createLinearGradient(0, 0, 0, canvasHeight);
gradient.addColorStop(0, "#547CA6");
gradient.addColorStop(horizon - 0.01, "#DB966D");
gradient.addColorStop(horizon, "#CC9B7A");
gradient.addColorStop(horizon + 0.01, "#CFBCB1");
gradient.addColorStop(0.9, "#567DA6");
return gradient;
};
const makeSpaceBackgroundGradient = (CTX, canvasHeight, backgroundColor) => {
const gradient = CTX.createLinearGradient(0, 0, 0, canvasHeight);
gradient.addColorStop(0, "#000");
gradient.addColorStop(0.5, backgroundColor);
return gradient;
};
const makeHawaiiBackgroundTerrainGradient = (CTX, canvasHeight) => {
const y = canvasHeight * horizon + 12;
const height = canvasHeight * 0.1;
const gradient = CTX.createLinearGradient(0, y - height, 0, y);
gradient.addColorStop(0, "#815962");
gradient.addColorStop(0.8, "#815962");
gradient.addColorStop(1, "rgba(129, 89, 98, 0)");
return [y, gradient, height];
};
export const makeTheme = (state) => {
const CTX = state.get("CTX");
const canvasHeight = state.get("canvasHeight");
const canvasWidth = state.get("canvasWidth");
const spaceTheme = {
bodyFontColor: "rgba(255, 255, 255, 0.75)",
headlineFontColor: "#fff",
infoFontColor: "#fff",
background: "#02071e",
backgroundGradient: makeSpaceBackgroundGradient(
CTX,
canvasHeight,
"#02071e"
),
landerGradient: makeLanderGradient(
CTX,
"#DFE5E5",
"#BDBCC3",
"#4A4E6F",
"#3D4264"
),
toyLanderGradient: (width) =>
makeLanderGradient(
CTX,
"#DFE5E5",
"#BDBCC3",
"#4A4E6F",
"#3D4264",
width
),
asteroid: "#898482",
star: "#ffffff",
terrain: "#757579",
meterGradient:
"linear-gradient(90deg, hsl(142deg 100% 48%) 0%, hsl(84deg 100% 42%) 6%, hsl(61deg 100% 35%) 15%, hsl(41deg 100% 40%) 29%, hsl(25deg 100% 44%) 50%, hsl(0deg 100% 46%) 100%)",
};
const drawHawaiiBackground = () => {
const [y, gradient, height] = makeHawaiiBackgroundTerrainGradient(
CTX,
canvasHeight
);
CTX.save();
CTX.fillStyle = gradient;
CTX.moveTo(0, y);
CTX.lineTo(0, y - height);
CTX.lineTo(canvasWidth * 0.1, y - height * 1.1);
CTX.lineTo(canvasWidth * 0.2, y - height * 0.9);
CTX.lineTo(canvasWidth * 0.3, y - height * 0.8);
CTX.lineTo(canvasWidth * 0.4, y);
CTX.lineTo(0, y);
CTX.closePath();
CTX.fill();
CTX.restore();
};
const hawaiiTheme = {
bodyFontColor: "rgba(255, 255, 255, 0.75)",
headlineFontColor: "#fff",
infoFontColor: "#fff",
background: "#547CA6",
backgroundGradient: makeHawaiiBackgroundGradient(CTX, canvasHeight),
drawBackgroundTerrain: drawHawaiiBackground,
horizon,
landerGradient: makeLanderGradient(
CTX,
"#FFE9DC",
"#FDD1B6",
"#5E5B7A",
"#44354A"
),
toyLanderGradient: (width) =>
makeLanderGradient(
CTX,
"#FFE9DC",
"#FDD1B6",
"#5E5B7A",
"#44354A",
width
),
asteroid: "#CAA78D",
star: "#ffffff",
terrain: "#B28171",
meterGradient:
"linear-gradient(90deg, #fdf7c3 0%, #ffab5a 24%, #c08d6c 68%, #6b5a6c 100%)",
};
const activeTheme = spaceTheme;
document.documentElement.style.setProperty(
"--background",
activeTheme.background
);
document.documentElement.style.setProperty(
"--body-font-color",
activeTheme.bodyFontColor
);
document.documentElement.style.setProperty(
"--headline-font-color",
activeTheme.headlineFontColor
);
document.documentElement.style.setProperty(
"--meter-gradient",
activeTheme.meterGradient
);
return activeTheme;
};