-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
490 additions
and
173 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
Ignore everything beyound this line. | ||
*/ | ||
.example { | ||
position: absolute; | ||
top: 0px; | ||
left: calc(var(--p) * 100%); | ||
transform: translateX(calc(var(--p) * -100%)); | ||
|
||
height: 100%; | ||
aspect-ratio: 1; | ||
border-radius: 9999px; | ||
border: 1px solid var(--color-beige); | ||
} | ||
|
||
.example-steps { | ||
position: absolute; | ||
height: 100%; | ||
aspect-ratio: 1; | ||
border-radius: 9999px; | ||
background-color: var(--color-beige); | ||
|
||
left: calc(100% * var(--step)); | ||
transform: translateX(calc(-100% * var(--step))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
let modifier = 16; | ||
|
||
let lastTime = 0; | ||
let step = 0; | ||
let counter = 0; | ||
|
||
function animate() { | ||
window.requestAnimationFrame(animate); | ||
|
||
const now = performance.now(); | ||
const delta = now - lastTime; | ||
lastTime = now; | ||
counter += 0.001 * delta; | ||
|
||
const bezier = cubicBezier(0.4, 0, 0.6, 1); | ||
|
||
step = Math.round(counter * modifier * 0.5) % modifier; | ||
step = Math.abs(step - modifier * 0.5); | ||
step = bezier(step / (modifier * 0.5)); | ||
|
||
console.log(step); | ||
document.body.style.setProperty("--step", step); | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function () { | ||
animate(performance.now()); | ||
|
||
const bezier = cubicBezier(0.4, 0, 0.6, 1); | ||
const elements = document.getElementsByClassName("example"); | ||
|
||
for (let i = 0; i < elements.length; i++) { | ||
elements[i].style.setProperty("--p", bezier(i / (elements.length - 1))); | ||
} | ||
}); | ||
|
||
function updateModifier() { | ||
const el = document.querySelector("input"); | ||
modifier = +el.value; | ||
} | ||
|
||
function cubicBezier(x0, y0, x1, y1, options) { | ||
const precision = options?.precision ?? 256; | ||
const maxIterations = options?.maxIterations ?? 32; | ||
const maxErrorMargin = options?.maxErrorMargin ?? 1 / 10 ** 8; | ||
|
||
const getBezierFunction = (p1, p2, t) => { | ||
const a0 = 3 * t * (1 - t) ** 2 * p1; | ||
const a1 = 3 * (1 - t) * t ** 2 * p2; | ||
return a0 + a1 + t ** 3; | ||
}; | ||
|
||
const sampleX = (u) => getBezierFunction(x0, x1, u); | ||
const sampleY = (u) => getBezierFunction(y0, y1, u); | ||
const steps = new Array(precision + 1); | ||
|
||
for (let index = 0; index <= precision; index++) { | ||
let x0 = index / precision - 1 / 10 ** 3; | ||
let x1 = index / precision + 1 / 10 ** 3; | ||
let x2 = 0; | ||
|
||
for (let iteration = 0; iteration < maxIterations; iteration++) { | ||
const ox0 = sampleX(x0) - index / precision; | ||
const ox1 = sampleX(x1) - index / precision; | ||
|
||
x2 = (x0 * ox1 - x1 * ox0) / (ox1 - ox0); | ||
x0 = x1; | ||
x1 = x2; | ||
|
||
if (Math.abs(sampleX(x2) - index / precision) < maxErrorMargin) { | ||
break; | ||
} | ||
} | ||
|
||
steps[index] = sampleY(x2); | ||
} | ||
|
||
return (x) => { | ||
const upper = Math.floor(x * precision); | ||
const lower = Math.ceil(x * precision); | ||
|
||
const x0 = upper / precision ?? 0; | ||
const x1 = lower / precision ?? 1; | ||
const y0 = steps[upper] ?? 0; | ||
const y1 = steps[lower] ?? 1; | ||
|
||
const percentage = (x - x0) / (x1 - x0) || 0; | ||
return (y1 - y0) * percentage + y0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>2.2: Animation Basics</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<link rel="stylesheet" href="../overall.css" /> | ||
<link rel="stylesheet" href="ignore.css" /> | ||
<script src="ignore.js"></script> | ||
<script src="scripts.js"></script> | ||
</head> | ||
<body> | ||
<header> | ||
<div></div> | ||
<a href="../2-3-loop/index.html"></a> | ||
</header> | ||
|
||
<div | ||
class="container fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex flex-col gap-[64px] w-[50vw]" | ||
> | ||
<div class="relative w-full h-[96px]"> | ||
<div class="example"></div> | ||
<div class="example"></div> | ||
<div class="example"></div> | ||
<div class="example"></div> | ||
<div class="example"></div> | ||
<div class="example"></div> | ||
<div class="example"></div> | ||
<div class="example"></div> | ||
<div class="example"></div> | ||
</div> | ||
|
||
<div class="relative w-full h-[96px]"> | ||
<div class="example-steps"></div> | ||
</div> | ||
|
||
<input | ||
id="range" | ||
type="range" | ||
min="18" | ||
step="1" | ||
value="18" | ||
max="120" | ||
oninput="updateModifier()" | ||
class="w-[200px] mx-auto" | ||
/> | ||
</div> | ||
</body> | ||
</html> |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>2.3: Animation Loops</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<link rel="stylesheet" href="../overall.css" /> | ||
<link rel="stylesheet" href="ignore.css" /> | ||
<script src="ignore.js"></script> | ||
<script src="scripts.js"></script> | ||
</head> | ||
<body> | ||
<header> | ||
<div></div> | ||
<a href="../2-4-interpolation/index.html"></a> | ||
</header> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>2.4: Interpolation</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<link rel="stylesheet" href="../overall.css" /> | ||
<link rel="stylesheet" href="styles.css" /> | ||
<script src="scripts.js"></script> | ||
</head> | ||
<body> | ||
<header> | ||
<div></div> | ||
<a href="../2-5-clippath-mouse/index.html"></a> | ||
</header> | ||
|
||
<div | ||
class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex flex-col gap-32 w-[50vw]" | ||
> | ||
<div class="timeline"> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
</div> | ||
|
||
<div class="target"> | ||
<div></div> | ||
</div> | ||
|
||
<input | ||
id="range" | ||
type="range" | ||
min="0" | ||
step="1" | ||
value="0" | ||
max="400" | ||
oninput="updateModifier()" | ||
class="w-[200px] mx-auto" | ||
/> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.