-
Notifications
You must be signed in to change notification settings - Fork 0
/
pond-fast.html
153 lines (119 loc) · 3.63 KB
/
pond-fast.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
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<head></head>
<script>
new p5();
const charWidth = 8.4
const charHeight = 9.0
let t = 0,
lineLength = 0
let ripples = []
let fishes = []
let m
for (let i = 0; i < 5; i++) {
addFish()
}
function addFish() {
fishes.push({
x: random(innerWidth / charWidth),
y: random(innerHeight / charHeight),
direction: random(360),
slowness: random(300, 500),
color: random(['▓', '░', '▒'])
})
}
addEventListener('mousedown', e => {
ripples.push({
x: e.clientX / charWidth,
y: e.clientY / charHeight,
r: 1
})
})
function draw() {
m = millis()
// Update ripples
for (let i = 0; i < ripples.length; i++) {
let ripple = ripples[i]
ripple.r += .5
if (ripple.r > 12) {
ripples.splice(i,1)
}
}
// Update fish
for (let i = 0; i < fishes.length; i++) {
let fish = fishes[i]
let v = p5.Vector.fromAngle(radians(fish.direction), .2)
fish.x -= v.x
fish.y += v.y
fish.direction += noise(millis()) - .5
if (fish.x > innerWidth / charWidth + 5 || fish.x < -5 ||
fish.y > innerHeight / charHeight + 5 || fish.y < -5) {
fishes.splice(i,1)
addFish()
}
}
// The update loop
let lines = []
lineLength = innerWidth / charWidth
for (let y = 0; y < innerHeight / charHeight; y++) {
lines.push("█".repeat(innerWidth / charWidth) + "\n")
}
lines[Math.floor(sin(millis() / 1000)) * 200][100] = '▒'
// Primitives library???
// Rect, line, img, ...
// Ripples
// for (const ripple of ripples) {
// let d = dist(ripple.x, ripple.y, x, y)
// if (d < ripple.r && d > ripple.r - 1) {
// if (ripple.r < 10) {
// return ripple.r > 5 ? "▓" : "▒"
// }
// }
// if (d < ripple.r - 3 && d > ripple.r - 4) {
// if (ripple.r < 11.5) {
// return "▓"
// }
// }
// }
document.body.innerHTML = lines
}
/**
* Draw, basically
*/
function charForPos(x, y, char) {
// fishes
for (const fish of fishes) {
if (dist(fish.x, fish.y, x, y) < 1.5) {
return fish.color
}
// Wagging tail
let v = p5.Vector.fromAngle(radians(fish.direction + sin(millis() / fish.slowness) * 20), 3)
if (dist(fish.x + v.x, fish.y - v.y, x, y) < 2) {
return fish.color
}
let v2 = p5.Vector.fromAngle(radians(fish.direction + sin(millis() / fish.slowness - fish.slowness / 2) * 5), 6)
if (dist(fish.x + v2.x, fish.y - v2.y, x, y) < 1) {
return fish.color
}
}
return '█'
}
</script>
<style>
* {
cursor: pointer;
}
body {
cursor: none;
margin: 0;
cursor: default;
user-select: none;
display: block;
unicode-bidi: embed;
white-space: pre;
overflow: hidden;
font-family: monospace;
line-height: .65;
font-size: 14px;
}
</style>