@@ -12,67 +12,72 @@ const dependencies: IDependency[] = []
12
12
const currentTab = ref (' experiment' )
13
13
14
14
const codeBlockString: string = `
15
- <script setup lang="ts">
16
- import { ref, onMounted } from 'vue'
17
-
18
- const leftball = ref(true)
19
-
20
- onMounted(() => {
21
- setInterval(() => {
22
- leftball.value = !leftball.value
23
- }, 1100)
24
- })
25
- <\/ script>
15
+ <script setup lang="ts"><\/ script>
26
16
27
17
<template>
28
18
<div class="flex flex-row">
29
- <div class="flex flex-col grow">
30
- <div class="w-full h-2 bg-black rounded-full p-2 relative top-1"></div>
31
- <div class="flex flex-row">
32
- <div :class="['flex flex-col items-center', { leftball }]">
33
- <div class="flex bg-black w-1 h-32"></div>
34
- <div class="flex w-8 h-8 bg-black rounded-full border-2 border-black"></div>
35
- </div>
36
- <div v-for="index in 5" :key="index">
37
- <div class="flex flex-col items-center">
19
+ <div class="flex flex-row grow">
20
+ <div
21
+ class="flex h-full bg-black w-2 rotate-15 rounded-full items-center justify-center"
22
+ ></div>
23
+ <div class="flex flex-col">
24
+ <div class="w-full h-2 bg-black rounded-full relative top-2"></div>
25
+ <div class="flex flex-row">
26
+ <div class="flex flex-col items-center leftball">
27
+ <div class="flex bg-black w-1 h-32"></div>
28
+ <div class="flex w-8 h-8 bg-black rounded-full border-2 border-black"></div>
29
+ </div>
30
+ <div v-for="index in 3" :key="index">
31
+ <div class="flex flex-col items-center">
32
+ <div class="flex bg-black w-1 h-32"></div>
33
+ <div class="flex w-8 h-8 bg-black rounded-full border-2 border-black"></div>
34
+ </div>
35
+ </div>
36
+ <div class="flex flex-col items-center rightball">
38
37
<div class="flex bg-black w-1 h-32"></div>
39
38
<div class="flex w-8 h-8 bg-black rounded-full border-2 border-black"></div>
40
39
</div>
41
- </div>
42
- <div :class="['flex flex-col items-center', { rightball: !leftball }]">
43
- <div class="flex bg-black w-1 h-32"></div>
44
- <div class="flex w-8 h-8 bg-black rounded-full border-2 border-black"></div>
45
40
</div>
46
41
</div>
42
+ <div
43
+ class="flex h-full bg-black w-2 -rotate-15 rounded-full items-center justify-center"
44
+ ></div>
47
45
</div>
48
46
</div>
49
47
</template>
50
48
51
49
<style>
52
50
.leftball {
53
- animation: leftball 1.2s cubic-bezier(0.5, 0, 0.5, 1) both;
51
+ animation: leftball 2.5s cubic-bezier(0.5, 0, 0.5, 1) infinite both;
54
52
transform: rotate(0deg);
55
53
transform-origin: 50% 0%;
56
54
}
57
55
58
56
.rightball {
59
- animation: rightball 1.2s cubic-bezier(0.5, 0, 0.5, 1) both;
57
+ animation: rightball 2.5s cubic-bezier(0.5, 0, 0.5, 1) 1.25s infinite both;
60
58
transform: rotate(0deg);
61
59
transform-origin: 50% 0%;
62
60
}
63
61
64
62
@keyframes leftball {
63
+ 25% {
64
+ transform: rotate(75deg);
65
+ }
65
66
50% {
66
- transform: rotate(60deg );
67
+ transform: rotate(0deg );
67
68
}
68
69
}
69
70
70
71
@keyframes rightball {
72
+ 25% {
73
+ transform: rotate(-75deg);
74
+ }
71
75
50% {
72
- transform: rotate(-60deg );
76
+ transform: rotate(0deg );
73
77
}
74
78
}
75
79
</style>
80
+
76
81
`
77
82
</script >
78
83
@@ -81,12 +86,14 @@ onMounted(() => {
81
86
<div class =" flex flex-col mb-4 text-xl" >
82
87
<h2 class =" text-5xl font-light mb-4" >Newton's Cradle</h2 >
83
88
<div class =" flex flex-col space-y-2" >
84
- <span >Mimicking conservation of momentum with Vue animations</span >
89
+ <span >Mimicking conservation of momentum with CSS animations. </span >
85
90
<span >
86
91
An animated version of the classic Newton's Cradle toy. An alternative would be to use
87
92
something like
88
93
<a href =" https://brm.io/matter-js/" target =" _blank" class =" font-bold" > Matter.js </a > for
89
- a more realistic physics simulation.
94
+ a more realistic physics simulation. This ended up using no Vue / Javascript and just CSS
95
+ animations. Originally I used Vue to toggle the applied css classes to make the animation
96
+ infinite but this can be done more easily using CSS.
90
97
</span >
91
98
<div class =" flex flex-row space-x-2 py-4" >
92
99
<span >Dependencies:</span >
0 commit comments