Skip to content

Commit bb15f8b

Browse files
committed
Don't show dynamic background by default
1 parent 3f9f6b1 commit bb15f8b

File tree

9 files changed

+117
-20
lines changed

9 files changed

+117
-20
lines changed

components/DynamicBackground.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<div>
3-
<div class="dynamicbackground" />
3+
<div
4+
class="dynamicbackground"
5+
:class="{ 'dynamicbackground--hidden': !visualsStore.visible }"
6+
/>
47
</div>
58
</template>
69

@@ -21,6 +24,9 @@ onMounted(() => {
2124
)
2225
visualsStore.setRenderer(rendererInstance)
2326
rendererInstance.initialise()
27+
visualsStore.listeners.onStart = () => {
28+
rendererInstance.start()
29+
}
2430
renderer.value = rendererInstance
2531
},
2632
isSafari ? 500 : 100, // Give Safari more time to init
@@ -44,5 +50,9 @@ onUnmounted(() => {
4450
z-index: -100;
4551
transition: opacity 0.4s;
4652
cursor: pointer;
53+
54+
&--hidden {
55+
opacity: 0;
56+
}
4757
}
4858
</style>

components/ProfilePhoto.vue

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
<template>
22
<div
33
class="profilephoto"
4-
@click="randomiseProfile"
4+
@click="onClick"
55
>
66
<img src="/me.png?v=6">
77
<div class="profilephoto-bg" />
8+
<div class="profilephoto-fallback">
9+
<img src="/me-bg.png">
10+
</div>
811
</div>
912
</template>
1013

1114
<script setup lang="ts">
1215
import { ref, onMounted, onUnmounted } from 'vue'
13-
import { isSafari } from 'react-device-detect'
1416
import { Renderer } from '~/util/3d/renderer'
1517
import { PartialSphere, Sphere } from '~/util/3d/geometry'
1618
19+
const visualsStore = useVisualsStore()
20+
1721
const rendererZoomLevel = 12
1822
const geometryDefinition = [
1923
{
@@ -45,9 +49,10 @@ const geometryRotationSpeed = 20
4549
4650
const renderer = ref<Renderer | undefined>(undefined)
4751
48-
const randomiseProfile = (): void => {
52+
const onClick = (): void => {
4953
renderer.value?.randomiseRotations()
5054
renderer.value?.randomiseColors()
55+
visualsStore.randomise()
5156
}
5257
5358
onMounted(() => {
@@ -63,7 +68,7 @@ onMounted(() => {
6368
.setOnRenderTick(renderer =>
6469
renderer.getGeometry()?.forEach(geometry => geometry.rotate()),
6570
)
66-
.setOnInit((renderer) => {
71+
.setOnStart((renderer) => {
6772
renderer.getGeometry()?.forEach((geometry) => {
6873
geometry.setRotationSpeed({
6974
x: geometryRotationSpeed,
@@ -73,9 +78,10 @@ onMounted(() => {
7378
})
7479
.setGetZoom(() => rendererZoomLevel)
7580
.initialise()
81+
.start()
7682
7783
renderer.value.getCanvasElement()?.style.setProperty('border-radius', '50%')
78-
}, isSafari ? 500 : 100)
84+
}, 500)
7985
})
8086
8187
onUnmounted(() => {
@@ -103,7 +109,7 @@ onUnmounted(() => {
103109
width: 8rem;
104110
}
105111
106-
&-bg {
112+
&-bg, &-fallback {
107113
position: absolute;
108114
top: 0;
109115
left: 0;
@@ -129,5 +135,19 @@ onUnmounted(() => {
129135
border: var(--color-highlight) 1px solid;
130136
box-sizing: border-box;
131137
}
138+
139+
&-fallback {
140+
position: absolute;
141+
top: 0;
142+
left: 0;
143+
z-index: 0;
144+
width: inherit;
145+
height: inherit;
146+
147+
& > img {
148+
z-index: 0;
149+
}
150+
}
151+
132152
}
133153
</style>

pages/visuals/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
import { ref, computed, onMounted, onUnmounted } from 'vue'
129129
import { isMobile } from 'is-mobile'
130130
import { AutoZoomMode, useVisualsStore } from '~/stores/visuals'
131+
import { useShowBackground } from '~/util/hooks/useShowBackground'
132+
133+
useShowBackground()
131134
132135
const visualsStore = useVisualsStore()
133136

pages/visuals/shapes.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ import { ref, computed, onMounted, onUnmounted } from 'vue'
8282
import { useVisualsStore } from '~/stores/visuals'
8383
import { type GeometryAttributes, geometryClasses } from '~/util/3d/geometry'
8484
import { getColorName } from '~/util/color'
85+
import { useShowBackground } from '~/util/hooks/useShowBackground'
86+
87+
useShowBackground()
8588
8689
const visualsStore = useVisualsStore()
8790

public/me-bg.png

48.9 KB
Loading

stores/sequencer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ export const useSequencerStore = defineStore('sequencer', {
115115
},
116116

117117
initGrid(synths: Synth[]) {
118-
this.grid = synths.map((synth, index) => ({
118+
this.grid = synths.map(synth => ({
119119
synthId: synth.getId(),
120120
beats: Array(this.beatCount).fill(false),
121121
muted: false,
122-
visualsSynced: index === 0,
122+
visualsSynced: false,
123123
}))
124124
},
125125

@@ -225,10 +225,13 @@ export const useSequencerStore = defineStore('sequencer', {
225225
},
226226

227227
syncVisuals(rowIndex: number) {
228+
const visualStore = useVisualsStore()
228229
const currentState = this.grid![rowIndex].visualsSynced === true
229230
this.grid!.forEach(row => row.visualsSynced = false)
230231
this.grid![rowIndex].visualsSynced = !currentState
231-
console.log({ grid: this.grid })
232+
if (!visualStore.visible) {
233+
visualStore.start()
234+
}
232235
},
233236
},
234237
})

stores/visuals.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export interface VisualStore {
5151
}
5252
listeners: {
5353
onRandomise: (() => void) | undefined
54+
onStart?: () => void
5455
}
56+
visible: boolean
5557
}
5658

5759
export const defaultGeometry: GeometryAttributes[] = [
@@ -86,14 +88,14 @@ const initialState: VisualStore = {
8688
geometryConfig: defaultGeometry,
8789
followCursor: true,
8890
zoom: {
89-
min: -2,
91+
min: -6,
9092
max: 4,
91-
current: 4,
93+
current: -6,
9294
},
9395
autoZoom: {
9496
mode: AutoZoomMode.SMOOTH,
95-
speed: 5,
96-
direction: 'out',
97+
speed: 100,
98+
direction: 'in',
9799
beat: 0,
98100
},
99101
scrollToZoom: true,
@@ -109,6 +111,7 @@ const initialState: VisualStore = {
109111
listeners: {
110112
onRandomise: undefined,
111113
},
114+
visible: false,
112115
}
113116

114117
export const useVisualsStore = defineStore('visuals', {
@@ -134,6 +137,11 @@ export const useVisualsStore = defineStore('visuals', {
134137
},
135138

136139
randomise() {
140+
if (!this.renderer?.isStarted()) {
141+
this.start()
142+
return
143+
}
144+
137145
const siteStore = useSiteStore()
138146

139147
this.randomiseZoom()
@@ -361,8 +369,15 @@ export const useVisualsStore = defineStore('visuals', {
361369
.setOnRenderTick((_, positionData) => {
362370
this.tick(positionData)
363371
})
364-
.setOnInit(() => this.syncRotationSpeed())
365-
.setOnClick(() => this.randomise())
372+
.setOnStart(() => this.syncRotationSpeed())
373+
.setOnClick(() => {
374+
if (!this.renderer?.isStarted()) {
375+
this.start()
376+
}
377+
else {
378+
this.randomise()
379+
}
380+
})
366381
.setOnKeyDown((renderer, event) => {
367382
if (event.code === 'Space') {
368383
siteStore.tapBpm()
@@ -394,5 +409,26 @@ export const useVisualsStore = defineStore('visuals', {
394409
removeListener(name: keyof VisualStore['listeners']) {
395410
this.listeners[name] = undefined
396411
},
412+
413+
start() {
414+
if (!this.renderer?.isStarted()) {
415+
this.listeners.onStart?.()
416+
setTimeout(() => {
417+
this.autoZoom.speed = 5
418+
this.zoom.min = -2
419+
}, 500)
420+
}
421+
this.show()
422+
},
423+
424+
show() {
425+
this.visible = true
426+
},
427+
hide() {
428+
this.visible = false
429+
},
430+
toggleVisible() {
431+
this.visible = !this.visible
432+
},
397433
},
398434
})

util/3d/renderer.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class Renderer {
3232
},
3333
) => {}
3434

35-
protected onInit = (_renderer: this) => {}
35+
protected started = false
36+
protected onStart = (_renderer: this) => {}
3637

3738
protected getZoom = () => 1
3839
protected getWidth = () => this.container.clientWidth
@@ -85,8 +86,8 @@ export class Renderer {
8586
return this
8687
}
8788

88-
public setOnInit(onInit: (_renderer: this) => void) {
89-
this.onInit = onInit
89+
public setOnStart(onStart: (_renderer: this) => void) {
90+
this.onStart = onStart
9091
return this
9192
}
9293

@@ -121,11 +122,19 @@ export class Renderer {
121122
this.initialiseEventListeners()
122123

123124
this.container.appendChild(this.renderer.domElement)
125+
return this
126+
}
127+
128+
public start(): this {
129+
if (this.started) {
130+
return this
131+
}
124132

125133
const geometry = this.getDefaultGeometry().map(mapGeometryAttributes)
126134
this.placeGeometry(geometry)
127135

128-
this.onInit(this)
136+
this.onStart(this)
137+
this.started = true
129138

130139
this.animate()
131140

@@ -267,4 +276,8 @@ export class Renderer {
267276
public getCanvasElement(): HTMLCanvasElement | undefined {
268277
return this.renderer?.domElement
269278
}
279+
280+
public isStarted() {
281+
return this.started
282+
}
270283
}

util/hooks/useShowBackground.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useVisualsStore } from '~/stores/visuals'
2+
3+
export const useShowBackground = () => {
4+
const visualsStore = useVisualsStore()
5+
6+
onMounted(() => {
7+
visualsStore.start()
8+
})
9+
}

0 commit comments

Comments
 (0)