|
1 | | -import {addCanvas, colors, sizes} from "./internal/layout"; |
| 1 | +import {addCanvas, addTitle, colors, sizes} from "./internal/layout"; |
2 | 2 | import { |
3 | 3 | point, |
4 | 4 | drawOpen, |
@@ -26,6 +26,27 @@ import {genFromOptions} from "../internal/gen"; |
26 | 26 | import {BlobOptions} from "../public/blobs"; |
27 | 27 | import {interpolateBetween} from "../internal/animate/interpolate"; |
28 | 28 |
|
| 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 | + |
29 | 50 | addCanvas( |
30 | 51 | 1.3, |
31 | 52 | // Pixelated circle. |
@@ -170,16 +191,7 @@ addCanvas(2, (ctx, width, height, animate) => { |
170 | 191 | can be approximated instead.`; |
171 | 192 | }); |
172 | 193 |
|
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?"); |
183 | 195 |
|
184 | 196 | addCanvas( |
185 | 197 | 1.3, |
@@ -252,14 +264,6 @@ addCanvas( |
252 | 264 | }, |
253 | 265 | ); |
254 | 266 |
|
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 | | - |
263 | 267 | addCanvas( |
264 | 268 | 1.3, |
265 | 269 | (ctx, width, height) => { |
@@ -338,6 +342,8 @@ addCanvas( |
338 | 342 | }, |
339 | 343 | ); |
340 | 344 |
|
| 345 | +addTitle(4, "How are animated blobs interpolated?"); |
| 346 | + |
341 | 347 | addCanvas(2, (ctx, width, height, animate) => { |
342 | 348 | const period = Math.PI * 1000; |
343 | 349 | const center: Coord = {x: width * 0.5, y: height * 0.5}; |
@@ -392,4 +398,10 @@ addCanvas(2, (ctx, width, height, animate) => { |
392 | 398 |
|
393 | 399 | drawClosed(ctx, interpolateBetween(percentage, blobA, blobB), true); |
394 | 400 | }); |
| 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.`; |
395 | 407 | }); |
0 commit comments