-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi-noise-text.html
116 lines (93 loc) · 3.63 KB
/
multi-noise-text.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
<pre id="portrait"></pre>
<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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/simplex-noise/2.4.0/simplex-noise.js"></script>
<script>
let {noise, random, dist, millis, map} = p5.prototype
let r = 3
const simplex = new SimplexNoise()
new p5();
let text = `Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way.`
let $portrait = document.querySelector('#portrait')
let width = innerWidth,
height = innerHeight,
noiseFn = simplex.noise3D.bind(simplex),
whiteness = 0,
speedFactor = 0.0000001,
t = 0,
barX= 0,
lineLength = 0,
textI = 0
function setup() {
addEventListener('resize', () => {
width = innerWidth
height = innerHeight
})
addEventListener('mousemove', e => {
if (mouseIsPressed) {
whiteness = map(e.clientY, 0, innerHeight, -0.3, 0.3)
speedFactor = map(e.clientX, 0, innerWidth, 0.0000001, 0.000003)
barX = map(e.clientX, 0, innerWidth, 0, lineLength)
}
})
addEventListener('keydown', ({key}) => {
if (key == '1')
noiseFn = simplex.noise3D.bind(simplex)
if (key == '2')
noiseFn = noise
if (key == 'Escape') {
paused = !paused
}
})
}
function draw() {
let lines = ""
lineLength = width / 8.4
for (let y = 0; y < height / 9; y++) {
let str = ""
for (let x = 0; x < width / 8.4; x++) {
str += charForPos(x, y, char)
}
lines += str + "\n"
}
$portrait.innerHTML = lines
}
/**
* Draw, basically
*/
function charForPos(x, y, char) {
let n;
if (mouseIsPressed) {
// speed lines
if ((y <= 1 ) && x <= barX) {
return " "
}
}
t += speedFactor
n = noiseFn(x * 0.04, y * 0.04, t)
// noise
if (n > .9 + whiteness) return " "
if (n > .7 + whiteness) return "."
if (n > .65 + whiteness) return "~"
if (n > .55 + whiteness) {
return text[(x * y) % text.length]
}
if (n > .5 + whiteness) return "3"
if (n > .4 + whiteness) return "▓"
return '█'
}
</script>
<style>
body {
cursor: none;
margin: 0;
overflow: hidden;
cursor: default;
user-select: none;
}
#portrait {
font-family: monospace;
line-height: .65;
font-size: 14px;
}
</style>