Skip to content

Commit 4cdb348

Browse files
committed
upload new example
1 parent 9edc597 commit 4cdb348

File tree

2 files changed

+247
-0
lines changed

2 files changed

+247
-0
lines changed

src/assets/circular.html

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<div class="grid-container">
2+
<div class="row row-1">
3+
</div>
4+
<div class="row row-2">
5+
<div class="bigbang" >
6+
<div class="gravity-spot">
7+
<div class="gravity-spot">
8+
<div class="orbit-9" >
9+
<div class="satellite grow-1x time-display">
10+
<div class="capsule">
11+
<span style="font-weight: bold; margin-right: 5px">{{ tiempoRestante && tiempoRestante}} </span> {{ tiempoRestante && tiempoRestante > 1 ? ' sec' : ' secs'}}
12+
</div>
13+
</div>
14+
</div>
15+
<div class="orbit-7" >
16+
<div class="satellite grow-1x">
17+
<div class="capsule">
18+
<svg height="48px" viewBox="0 -960 960 960" width="48px" fill="#5f6368">
19+
<path d="M480-360 280-559h400L480-360Z"/>
20+
</svg>
21+
</div>
22+
</div>
23+
</div>
24+
<div class="orbit-6 disc" :class="`from-${rotationAngle}`">
25+
<div class="satellite inner-orbit spin-lock" v-for="n in 12" :key="'number-' + n">
26+
<div class="capsule flip">{{ (n - 1) * 5 }}</div>
27+
</div>
28+
</div>
29+
<div class="orbit-5":class="`from-${rotationAngle}`">
30+
<div class="vector shrink-80 inner-orbit" v-for="n in 60" :key="'small-' + n"></div>
31+
</div>
32+
<div class="orbit-5":class="`from-${rotationAngle}`">
33+
<div class="vector shrink-70 inner-orbit" v-for="n in 12" :key="'big-' + n"></div>
34+
</div>
35+
<div class="orbit-6 " :class="`from-${rotationAngle}`">
36+
<o-progress
37+
class="inner-orbit grow-2.5x time"
38+
:value="progressValue"
39+
max="360"
40+
></o-progress>
41+
</div>
42+
<div
43+
class="orbit-6 panel"
44+
ref="time_panel"
45+
@mousedown="startDrag" @touchstart.passive="startDrag"
46+
></div>
47+
<div class="orbit-0">
48+
<div class="satellite grow-0.8x control"
49+
@click="toggleRestore"
50+
@mousedown="startLongPress"
51+
@mouseup="endLongPress"
52+
@touchstart.passive="startLongPress"
53+
@touchend="endLongPress">
54+
<div class="capsule">
55+
<svg height="48px" viewBox="0 -960 960 960" width="48px" fill="white">
56+
<path ref="icon_control" d=""/>
57+
</svg>
58+
</div>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
64+
</div>
65+
</div>
66+
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
title: Circular time
3+
4+
---
5+
6+
import ZumerPlay from '/src/components/ZumerCode.astro';
7+
import htmlCal from '/src/assets/circular.html?raw';
8+
9+
10+
export const CSS = `
11+
.grid-container {
12+
display: grid;
13+
grid-template-rows: 5% 95%;
14+
height: 100vh;
15+
}
16+
* {
17+
user-select: none
18+
}
19+
.satellite {
20+
border: none;
21+
}
22+
.disc{
23+
background: white; font-size: 13px;
24+
}
25+
.time {
26+
--o-fill: red; --o-stroke: red; --o-stroke-width: 2; fill-opacity: 0.3
27+
28+
}
29+
.panel{
30+
pointer-events: all; cursor: grab
31+
}
32+
.control {
33+
background: black; cursor: pointer;color: white
34+
}
35+
.time-display {
36+
color: var(--o-gray-dark);
37+
font-size: 25px;
38+
}
39+
`
40+
41+
export const vue = `
42+
{
43+
data() {
44+
return {
45+
isDragging: false,
46+
startAngle: 0,
47+
rotationAngle: 359,
48+
progressValue: 1,
49+
};
50+
},
51+
computed: {
52+
tiempoRestante() {
53+
const gradosRestantes = 360 - this.rotationAngle;
54+
const segundos = Math.round(gradosRestantes / 6);
55+
const minutos = Math.round(segundos / 60);
56+
console.log(this.rotationAngle, this.progressValue)
57+
return segundos;
58+
},
59+
},
60+
methods: {
61+
getAngle(event) {
62+
const orbit7 = this.$refs.time_panel;
63+
const rect = orbit7.getBoundingClientRect();
64+
const centerX = rect.left + rect.width / 2;
65+
const centerY = rect.top + rect.height / 2;
66+
const clientX = event.clientX || event.touches[0].clientX;
67+
const clientY = event.clientY || event.touches[0].clientY;
68+
const deltaX = clientX - centerX;
69+
const deltaY = clientY - centerY;
70+
return Math.atan2(deltaY, deltaX) * (180 / Math.PI);
71+
},
72+
startDrag(event) {
73+
this.isDragging = true;
74+
this.startAngle = Math.round(this.getAngle(event) - this.rotationAngle);
75+
76+
// Add event listeners for dragging
77+
window.addEventListener('mousemove', this.duringDrag);
78+
window.addEventListener('touchmove', this.duringDrag);
79+
window.addEventListener('mouseup', this.stopDrag);
80+
window.addEventListener('touchend', this.stopDrag);
81+
},
82+
duringDrag(event) {
83+
if (!this.isDragging) return;
84+
85+
// Calculate the new rotation angle and round it to the nearest integer
86+
let angle = Math.round(this.getAngle(event) - this.startAngle);
87+
88+
// Ensure the angle is always between 0 and 360
89+
this.rotationAngle = (angle % 360 + 360) % 360;
90+
// Update the progress value based on the rotation angle
91+
this.progressValue = (360 - this.rotationAngle);
92+
93+
},
94+
stopDrag() {
95+
this.isDragging = false;
96+
let iconControl = this.$refs.icon_control
97+
iconControl.setAttribute('d', 'M320-203v-560l440 280-440 280Zm60-280Zm0 171 269-171-269-171v342Z')
98+
// Remove event listeners
99+
window.removeEventListener('mousemove', this.duringDrag);
100+
window.removeEventListener('touchmove', this.duringDrag);
101+
window.removeEventListener('mouseup', this.stopDrag);
102+
window.removeEventListener('touchend', this.stopDrag);
103+
},
104+
toggleRestore(e) {
105+
let iconControl = this.$refs.icon_control
106+
if (this.isRestoring) {
107+
// Pause restoration
108+
iconControl.setAttribute('d', 'M320-203v-560l440 280-440 280Zm60-280Zm0 171 269-171-269-171v342Z')
109+
clearInterval(this.restoreInterval);
110+
this.isRestoring = false;
111+
} else if (!this.isRestoring && this.rotationAngle !== 359) {
112+
// Start restoration
113+
iconControl.setAttribute('d', 'M525-200v-560h235v560H525Zm-325 0v-560h235v560H200Zm385-60h115v-440H585v440Zm-325 0h115v-440H260v440Zm0-440v440-440Zm325 0v440-440Z')
114+
this.startRestoration();
115+
} else {
116+
iconControl.setAttribute('d', '')
117+
}
118+
},
119+
startRestoration() {
120+
// Stop any existing animation
121+
if (this.restoreInterval) {
122+
clearInterval(this.restoreInterval);
123+
}
124+
125+
// Calculate the delta angle and duration
126+
const deltaAngle = this.startAngle - this.rotationAngle;
127+
const duration = Math.abs(deltaAngle) * 1000;
128+
129+
// Calculate the step size and interval time
130+
const step = deltaAngle > 0 ? 1 : -1;
131+
const intervalTime = 1000 / 6 ;
132+
133+
// Start the animation
134+
this.isRestoring = true;
135+
this.restoreInterval = setInterval(() => {
136+
if (this.rotationAngle !== 359 && this.isRestoring && this.progressValue !== 1) {
137+
this.rotationAngle -= step;
138+
this.rotationAngle = (this.rotationAngle % 360 + 360) % 360;
139+
this.progressValue = 360 - this.rotationAngle;
140+
console.log(this.rotationAngle,this.isRestoring,this.progressValue)
141+
} else {
142+
this.resetToZero
143+
}
144+
}, intervalTime);
145+
},
146+
startLongPress() {
147+
// Start long press timer
148+
this.longPressTimer = setTimeout(() => {
149+
this.resetToZero();
150+
}, 1000);
151+
},
152+
endLongPress() {
153+
// Clear long press timer if not triggered
154+
clearTimeout(this.longPressTimer);
155+
},
156+
resetToZero() {
157+
158+
clearInterval(this.restoreInterval);
159+
this.isRestoring = false;
160+
161+
162+
this.rotationAngle = 359;
163+
this.progressValue = 1;
164+
},
165+
166+
167+
}
168+
}
169+
`
170+
171+
172+
<ZumerPlay name={'scifi1'} framework="vue" htmlCode={htmlCal} cssCode={CSS} jsCode={vue} height={'500px'} />
173+
174+
**Credits:** reference author repo TODO
175+
176+
177+
## Show & Tell
178+
179+
Join to our [Github Discussion](https://github.com/zumerlab/orbit/discussions/15) and show off what have you done with Orbit.
180+
181+

0 commit comments

Comments
 (0)