-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaker.html
167 lines (144 loc) · 5.35 KB
/
baker.html
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
161
162
163
164
165
166
167
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mountain Terrain (Snow with Alpenglow)</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
overflow: hidden;
}
body {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: rgb(25, 25, 35);
}
canvas {
display: block;
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<script>
let terrain = [];
let cols, rows;
const scl = 30;
let flying = 0;
let rotation = 0;
let graphics;
let snowLineOffset = 0;
const colors = [
[40, 42, 54], // Dark base
[86, 67, 104], // Deep purple-gray
[191, 131, 170], // Mauve/pink
[255, 175, 189], // Soft pink
[255, 233, 235], // Snow with pink tint
[255, 255, 255] // Pure white
];
const backgroundColor = [25, 25, 35];
const snowColor = [225, 210, 220]; // More muted, dusty rose snow color
const colorCache = new Map();
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
graphics = createGraphics(width, height, WEBGL);
frameRate(30);
updateTerrain();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
graphics = createGraphics(width, height, WEBGL);
updateTerrain();
}
function updateTerrain() {
cols = ceil(width / scl);
rows = ceil(height / scl);
terrain = new Array(cols);
for (let x = 0; x < cols; x++) {
terrain[x] = new Array(rows).fill(0);
}
}
function getAlpenglowColor(h) {
const cacheKey = Math.floor(h * 10) / 10;
if (colorCache.has(cacheKey)) {
return colorCache.get(cacheKey);
}
let colorIndex = map(h, -100, 350, 0, colors.length - 1);
colorIndex = constrain(colorIndex, 0, colors.length - 1);
const index = floor(colorIndex);
const blend = colorIndex - index;
let lineColor;
if (index < colors.length - 1) {
const c1 = colors[index];
const c2 = colors[index + 1];
const r = lerp(c1[0], c2[0], blend);
const g = lerp(c1[1], c2[1], blend);
const b = lerp(c1[2], c2[2], blend);
lineColor = color(r, g, b);
} else {
lineColor = color(colors[colors.length - 1]);
}
colorCache.set(cacheKey, lineColor);
return lineColor;
}
function draw() {
background(backgroundColor);
rotateX(PI/3);
rotateZ(rotation);
rotation += 0.005;
translate(-width/2, -height/2);
// Update snow line animation
snowLineOffset += 0.02;
const baseSnowLine = 150;
const snowLineAmplitude = 70;
const snowLine = baseSnowLine + sin(snowLineOffset) * snowLineAmplitude;
let yoff = flying;
const centerX = cols/2;
const centerY = rows/2;
for (let y = 0; y < rows; y++) {
let xoff = 0;
for (let x = 0; x < cols; x++) {
const distance = dist(x, y, centerX, centerY);
const peakHeight = constrain(map(distance, 0, cols/3, 350, 0), 0, 350);
const baseNoise = noise(xoff, yoff);
const detailNoise = noise(xoff * 2, yoff * 2) * 0.5;
terrain[x][y] = map(baseNoise + detailNoise, 0, 1.5, -100, 150) + peakHeight;
xoff += 0.1;
}
yoff += 0.1;
}
flying -= 0.003;
for (let y = 0; y < rows - 1; y++) {
beginShape(TRIANGLE_STRIP);
for (let x = 0; x < cols; x++) {
const h1 = terrain[x][y];
const h2 = terrain[x][y + 1];
// Always use alpenglow color for stroke
stroke(getAlpenglowColor(h1));
strokeWeight(1);
// Use snow fill above snow line, background color below
if (h1 > snowLine) {
const snowFill = color(snowColor);
snowFill.setAlpha(180); // More transparent snow
fill(snowFill);
} else {
fill(backgroundColor);
}
vertex(x * scl, y * scl, h1);
vertex(x * scl, (y + 1) * scl, h2);
}
endShape();
}
}
</script>
</body>
</html>