-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
239 lines (192 loc) · 4.71 KB
/
Copy pathapp.js
File metadata and controls
239 lines (192 loc) · 4.71 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
let font
let tilesX = 4
let tilesY = 4
let tileW
let tileH
let vw = window.innerWidth * 0.01
QuickSettings.useExtStyleSheet()
var settings = QuickSettings.create(20, 20, 'Controls')
.addRange('Text Size', 10, 45, 30, 1, setTextSize)
.addRange('Color', 0, 360, 80, 20, setTextCol)
.addRange('Repeats', 1, 9, 3, 1, setRepeater)
.addDropDown(
'Track',
['BASS', 'SNARE', 'KICK', 'PERC', 'ARPEG', 'LEAD', 'CHORD'],
setDropDown
)
.addRange('Num Columns', 2, 80, 4, 2, setTileX)
.addRange('Num Rows', 2, 80, 4, 2, setTileY)
.addRange('Amplitude', 50, 500, 100, 10, setMultiplier)
.addRange('Tempo', 0.025, 0.55, 0.125, 0.025, setWave)
// Quick Settings variables
let message = 'BASS' //Initial
let multiplier = 100
let wave = 0.125
let loopNum = 3
let fontsize = 30
let visible = true
// Colors
let textHue = 80
let backgroundColor = textHue + 180
let hslCol
// Repeater
let wordRepeat = 3
let repeats = []
function preload() {
font = loadFont('font/graphik-medium.otf')
}
function setup() {
colorMode(HSL)
frameRate(30)
tileW = windowWidth / tilesX
tileH = windowHeight / tilesY
pixelDensity(1)
createCanvas(windowWidth, windowHeight)
setUpGraphics()
}
// Initial Value
function setUpGraphics() {
hslCol = color(`hsl(${textHue}, 100%, 50%)`)
background(color(`hsl(${backgroundColor}, 100%, 20%)`))
repeats.length = 0 // clears Array
for (let i = 0; i < wordRepeat; i++) {
let img = createGraphics(windowWidth, windowHeight)
img.push()
/*------- DEBUG WRAPPER -------- */
// pg.background('rgba(255, 0, 0, 0.4)')
// pg.stroke('red')
// pg.strokeWeight(4)
/*------- DEBUG WRAPPER -------- */
img.textFont(font)
img.textSize(vw * fontsize)
img.translate(windowWidth / 2, windowHeight / 2)
img.textAlign(CENTER, CENTER)
if (i != 0) {
img.noFill()
img.stroke(hslCol)
img.strokeWeight(3)
} else {
img.noStroke()
img.fill(hslCol)
}
img.text(message, i * 200, i * -100)
img.pop()
repeats.push(img)
}
}
function setRepeater(value) {
wordRepeat = value
setUpGraphics()
}
function setTextSize(value) {
fontsize = value
setUpGraphics()
}
function setTextCol(value) {
textHue = value
if (textHue < 180 || textHue === 0) {
backgroundColor = textHue + 180
} else if (textHue > 180 || textHue === 360) {
backgroundColor = textHue - 180
}
setUpGraphics()
}
function setTileY(value) {
tilesY = value
// Updates since tileWidth is set in draw function
}
function setTileX(value) {
tilesX = value
// Updates since tileWidth is set in draw function
}
function setMessage(value) {
message = value
setUpGraphics()
}
function setBgColor(value) {
backgroundColor = value
setUpGraphics()
}
function setTypeColor(value) {
textColor = value
setUpGraphics()
}
function setDropDown(track) {
message = track.value
setUpGraphics()
}
function setMultiplier(value) {
multiplier = value
return multiplier
}
function setWave(value) {
wave = value
return wave
}
function vwUnit() {
let vwUnit
vwUnit = window.innerWidth * 0.01
return vwUnit
}
function tileWidth(tileXPos) {
let width
width = window.innerWidth / tileXPos
return width
}
function tileHeight(tileYPos) {
let height
height = window.innerHeight / tileYPos
return height
}
function draw() {
// console.log('hslCol: ' + hslCol)
// console.log('textHue: ' + textHue)
vw = vwUnit()
tileW = tileWidth(tilesX)
tileH = tileHeight(tilesY)
background(color(`hsl(${backgroundColor}, 100%, 20%)`))
// Two dimensional grid, going left to right (y first), top to bottom (x second)
for (let yDir = 0; yDir < tilesY; yDir++) {
for (let xDir = 0; xDir < tilesX; xDir++) {
// SINE TIME
let distortionX =
tan(frameCount * wave + xDir * wave + yDir * wave) * multiplier
let distortionY =
tan(frameCount * (wave / 2) + xDir * yDir * wave) * multiplier
// SOURCE
let sx = xDir * tileW + distortionX
let sy = yDir * tileH + distortionY
let sw = tileW /* + distortionY */
let sh = tileH
// DESTINATION
let dx = xDir * tileW
let dy = yDir * tileH
let dw = tileW
let dh = tileH
for (let i = 0; i < repeats.length; i++) {
image(repeats[i], dx, dy, dw, dh, sx, sy, sw, sh)
}
}
}
}
function resizeEverything() {
resizeCanvas(windowWidth, windowHeight)
// pg.clear()
setUpGraphics()
}
function windowResized() {
resizeEverything()
}
function keyPressed() {
if (keyCode === UP_ARROW) {
visible = !visible
if (visible) {
// hide controls
settings.hide()
} else {
// show controls
settings.show()
}
}
return false
}