Skip to content

Commit c5282fc

Browse files
committed
add section titles
1 parent 7637075 commit c5282fc

File tree

4 files changed

+63
-36
lines changed

4 files changed

+63
-36
lines changed

demo/content.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {addCanvas, colors, sizes} from "./internal/layout";
1+
import {addCanvas, addTitle, colors, sizes} from "./internal/layout";
22
import {
33
point,
44
drawOpen,
@@ -26,6 +26,27 @@ import {genFromOptions} from "../internal/gen";
2626
import {BlobOptions} from "../public/blobs";
2727
import {interpolateBetween} from "../internal/animate/interpolate";
2828

29+
const makePoly = (pointCount: number, radius: number, center: Coord): Point[] => {
30+
const angle = (2 * Math.PI) / pointCount;
31+
const points: Point[] = [];
32+
const nullHandle = {angle: 0, length: 0};
33+
for (let i = 0; i < pointCount; i++) {
34+
const coord = expandHandle(center, {angle: i * angle, length: radius});
35+
points.push({...coord, handleIn: nullHandle, handleOut: nullHandle});
36+
}
37+
return points;
38+
};
39+
40+
const centeredBlob = (options: BlobOptions, center: Coord): Point[] => {
41+
return mapPoints(genFromOptions(options), ({curr}) => {
42+
curr.x += center.x - options.size / 2;
43+
curr.y += center.y - options.size / 2;
44+
return curr;
45+
});
46+
};
47+
48+
addTitle(4, "What are vector graphics?");
49+
2950
addCanvas(
3051
1.3,
3152
// Pixelated circle.
@@ -170,16 +191,7 @@ addCanvas(2, (ctx, width, height, animate) => {
170191
can be approximated instead.`;
171192
});
172193

173-
const makePoly = (pointCount: number, radius: number, center: Coord): Point[] => {
174-
const angle = (2 * Math.PI) / pointCount;
175-
const points: Point[] = [];
176-
const nullHandle = {angle: 0, length: 0};
177-
for (let i = 0; i < pointCount; i++) {
178-
const coord = expandHandle(center, {angle: i * angle, length: radius});
179-
points.push({...coord, handleIn: nullHandle, handleOut: nullHandle});
180-
}
181-
return points;
182-
};
194+
addTitle(4, "How are blobs made?");
183195

184196
addCanvas(
185197
1.3,
@@ -252,14 +264,6 @@ addCanvas(
252264
},
253265
);
254266

255-
const centeredBlob = (options: BlobOptions, center: Coord): Point[] => {
256-
return mapPoints(genFromOptions(options), ({curr}) => {
257-
curr.x += center.x - options.size / 2;
258-
curr.y += center.y - options.size / 2;
259-
return curr;
260-
});
261-
};
262-
263267
addCanvas(
264268
1.3,
265269
(ctx, width, height) => {
@@ -338,6 +342,8 @@ addCanvas(
338342
},
339343
);
340344

345+
addTitle(4, "How are animated blobs interpolated?");
346+
341347
addCanvas(2, (ctx, width, height, animate) => {
342348
const period = Math.PI * 1000;
343349
const center: Coord = {x: width * 0.5, y: height * 0.5};
@@ -392,4 +398,10 @@ addCanvas(2, (ctx, width, height, animate) => {
392398

393399
drawClosed(ctx, interpolateBetween(percentage, blobA, blobB), true);
394400
});
401+
402+
// TODO have content about why being able to interrupt transitions with another.
403+
return `Interpolating between two blobs requires transforming the x,y coordinates of each point
404+
as well as its handles. However this has two important prerequisites. First, both blobs must
405+
have the same number of points. Second, the points must be matched with their nearest
406+
counterpart in the target shape.`;
395407
});

demo/example.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {CanvasKeyframe, canvasPath} from "../public/animate";
22

3+
// TODO add click me prompt before clicked.
4+
35
// Fetch reference to example container.
46
const exampleContainer = document.querySelector(".example")!;
57

demo/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
padding: 2.5rem 0 8rem;
4747
}
4848

49+
.container .title {
50+
color: #aaa;
51+
font-weight: 700;
52+
max-width: 1000px;
53+
text-transform: uppercase;
54+
user-select: none;
55+
width: 100%;
56+
}
57+
4958
.container .section {
5059
border: 1px solid #eee;
5160
border-radius: 0.5rem;

demo/internal/layout.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,29 @@ export const sizes = (): {width: number; pt: number} => {
4444
const createSection = (): HTMLElement => {
4545
const numberLabel = ("000" + cells.length).substr(-3);
4646

47-
const section = document.createElement("div");
48-
section.classList.add("section");
49-
section.setAttribute("id", numberLabel);
50-
containerElement.appendChild(section);
47+
const sectionElement = document.createElement("div");
48+
sectionElement.classList.add("section");
49+
sectionElement.setAttribute("id", numberLabel);
50+
containerElement.appendChild(sectionElement);
5151

5252
const numberElement = document.createElement("a");
5353
numberElement.classList.add("number");
5454
numberElement.setAttribute("href", "#" + numberLabel);
5555
numberElement.appendChild(document.createTextNode(numberLabel));
56-
section.appendChild(numberElement);
56+
sectionElement.appendChild(numberElement);
5757

58-
return section;
58+
return sectionElement;
5959
};
6060

6161
// Adds a section of text to the bottom of the layout.
62-
export const addTitle = (text: string) => {
63-
const sectionElement = createSection();
62+
export const addTitle = (heading: number, text: string) => {
63+
const wrapperElement = document.createElement(`h${heading}`);
64+
wrapperElement.classList.add("title");
65+
containerElement.appendChild(wrapperElement);
6466

6567
const textWrapperElement = document.createElement("div");
6668
textWrapperElement.classList.add("text");
67-
sectionElement.appendChild(textWrapperElement);
69+
wrapperElement.appendChild(textWrapperElement);
6870

6971
text = text.replace("\n", " ").replace(/\s+/g, " ").trim();
7072
const textElement = document.createTextNode(text);
@@ -120,10 +122,11 @@ const redraw = () => {
120122
// Draw canvas debug info.
121123
const drawDebug = () => {
122124
if (debug) {
123-
tempStyles(cell.ctx, () => {
124-
cell.ctx.strokeStyle = colors.debug;
125-
cell.ctx.strokeRect(0, 0, cellWidth, cellHeight - 1);
126-
});
125+
tempStyles(
126+
cell.ctx,
127+
() => (cell.ctx.strokeStyle = colors.debug),
128+
() => cell.ctx.strokeRect(0, 0, cellWidth, cellHeight - 1),
129+
);
127130
}
128131
};
129132
drawDebug();
@@ -144,10 +147,11 @@ const redraw = () => {
144147
cell.ctx.clearRect(0, 0, cellWidth, cellHeight);
145148
drawDebug();
146149
if (debug) {
147-
tempStyles(cell.ctx, () => {
148-
cell.ctx.fillStyle = colors.debug;
149-
cell.ctx.fillText(String(frameTime), 10, 15);
150-
});
150+
tempStyles(
151+
cell.ctx,
152+
() => (cell.ctx.fillStyle = colors.debug),
153+
() => cell.ctx.fillText(String(frameTime), 10, 15),
154+
);
151155
}
152156

153157
painter(frameTime);

0 commit comments

Comments
 (0)