-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaurora.html
195 lines (170 loc) · 6.55 KB
/
aurora.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
height: 100%;
}
canvas {
display: block;
}
</style>
</head>
<body>
<script>
let waveGroups = [];
const numGroups = 5;
const linesPerGroup = 6;
let trees = [];
const numTrees = 8; // Reduced for better spacing
const colorGradient = [
[220, 255, 220],
[180, 235, 200],
[140, 215, 180],
[100, 195, 160],
[60, 175, 140],
[20, 155, 120]
];
function setup() {
createCanvas(windowWidth, windowHeight);
resetWaveGroups();
createTrees();
}
function isTreeTooClose(newX, existingTrees, minDistance) {
return existingTrees.some(tree => {
const distance = abs(newX - tree.x);
return distance < minDistance;
});
}
function createTrees() {
trees = [];
const minTreeSpacing = width * 0.12; // Minimum spacing between trees
// Define specific positions across the width
const positions = [
{ x: width * 0.15, depth: 0.85 },
{ x: width * 0.3, depth: 0.6 },
{ x: width * 0.45, depth: 0.7 },
{ x: width * 0.6, depth: 0.5 },
{ x: width * 0.75, depth: 0.65 },
{ x: width * 0.85, depth: 0.8 }
];
positions.forEach(pos => {
// Add some randomness to the planned positions
const x = pos.x + random(-width * 0.03, width * 0.03);
// Only add the tree if it's not too close to existing trees
if (!isTreeTooClose(x, trees, minTreeSpacing)) {
// Base height affected by depth
const baseHeight = map(pos.depth, 0.5, 0.9, 140, 80);
trees.push({
x: x,
y: height - (height * 0.15) + sin(x * 0.02) * (height * 0.03),
height: baseHeight + random(-10, 10),
swayOffset: random(TWO_PI),
depth: pos.depth
});
}
});
}
function drawTree(x, y, treeHeight, swayOffset, depth) {
push();
translate(x, y);
// Adjust opacity based on depth
const opacity = map(depth, 0.5, 0.9, 255, 200);
// Static trunk
stroke(101, 67, 33, opacity);
strokeWeight(map(depth, 0.5, 0.9, 6, 4));
line(0, 0, 0, -treeHeight * 0.3);
// Tree sections with progressive sway
noStroke();
// Draw multiple sections, with more sway at the top
for (let i = 0; i < 5; i++) {
let sectionHeight = treeHeight * (0.8 - i * 0.15);
let sectionWidth = treeHeight * 0.3 * (1 - i * 0.15);
let sectionY = -treeHeight * 0.3 - (i * sectionHeight * 0.25);
// Increased sway amount for higher sections
let swayAmount = map(i, 0, 4, 0.05, 0.2);
let swayX = sin(frameCount * 0.015 + swayOffset) * (treeHeight * swayAmount);
// Adjust green color based on depth
fill(34, 139, 34, opacity);
// Draw triangular section
triangle(
-sectionWidth + swayX,
sectionY + sectionHeight * 0.5,
sectionWidth + swayX,
sectionY + sectionHeight * 0.5,
0 + swayX,
sectionY - sectionHeight * 0.2
);
}
pop();
}
function resetWaveGroups() {
waveGroups = [];
for (let i = 0; i < numGroups; i++) {
let group = {
baseY: (i * windowHeight/2) / numGroups,
amplitude: windowHeight * 0.075,
frequency: random(0.002, 0.003),
speed: random(0.002, 0.003),
offset: random(TWO_PI)
};
waveGroups.push(group);
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
resetWaveGroups();
createTrees();
}
function draw() {
background(20, 30, 40);
// Draw northern lights
noFill();
strokeWeight(4);
for (let i = 0; i < waveGroups.length; i++) {
let group = waveGroups[i];
for (let j = 0; j < linesPerGroup; j++) {
stroke(
colorGradient[j][0],
colorGradient[j][1],
colorGradient[j][2],
230
);
beginShape();
for (let x = 0; x < width; x += 5) {
let xOffset = (x * group.frequency);
let yOffset = group.offset + frameCount * group.speed;
let y = group.baseY + (j * windowHeight * 0.01) +
sin(xOffset + yOffset) * group.amplitude +
sin(xOffset * 2 + yOffset * 1.5) * (group.amplitude * 0.3);
curveVertex(x, y);
}
endShape();
}
}
// Draw snow landscape
fill(240);
noStroke();
beginShape();
vertex(0, height);
for (let x = 0; x < width; x += 20) {
let y = height - (height * 0.15) + sin(x * 0.02) * (height * 0.03);
vertex(x, y);
}
vertex(width, height);
endShape(CLOSE);
// Sort trees by depth before drawing
trees.sort((a, b) => b.depth - a.depth);
// Draw trees
trees.forEach(tree => {
drawTree(tree.x, tree.y, tree.height, tree.swayOffset, tree.depth);
});
}
</script>
</body>
</html>