@@ -21,10 +21,15 @@ import { LangtonAutomaton } from "./2d/langton/langton"
21
21
import { QuadLifeAutomaton } from "./2d/quadlife/quadlife"
22
22
import { CCA3D } from "./3d/cca_3d"
23
23
import type { AutomatonBase } from "./types/Automaton"
24
- import type { Movie } from "./types/MoviePalette"
25
24
import type { Settings } from "./types/Settings"
26
25
import { slugify } from "./utils/slugify"
27
26
27
+ interface StoredPalette {
28
+ colors : [ number , number , number ] [ ]
29
+ }
30
+
31
+ const moviePalettes = new Map < string , StoredPalette > ( )
32
+
28
33
let pane : Pane
29
34
let settings : Settings
30
35
let automaton : AutomatonBase
@@ -353,13 +358,24 @@ window.onload = () => {
353
358
fetch ( `${ MOVIES_PALETTES_API } /movies` )
354
359
. then ( ( response ) => response . json ( ) )
355
360
. then ( ( data ) => {
356
- const options = [
357
- { text : "Random" , value : null } ,
358
- ...data . movies . map ( ( movie ) => ( {
359
- text : `${ movie . title } (${ movie . year || "N/A" } )` ,
360
- value : slugify ( movie . title ) ,
361
- } ) ) ,
362
- ]
361
+ const options = [ { text : "Random" , value : null } ]
362
+
363
+ // Filter movies with palettes and store their colors
364
+ data . movies . forEach ( ( movie ) => {
365
+ if ( movie . palettes && movie . palettes . length > 0 ) {
366
+ const slug = slugify ( movie . title )
367
+ // Store the palette colors
368
+ moviePalettes . set ( slug , {
369
+ colors : movie . palettes [ 0 ] . colors ,
370
+ } )
371
+ // Add to dropdown options
372
+ options . push ( {
373
+ text : `${ movie . title } (${ movie . year || "N/A" } )` ,
374
+ value : slug ,
375
+ } )
376
+ }
377
+ } )
378
+
363
379
paletteSelector . options = options
364
380
} )
365
381
. catch ( ( error ) => {
@@ -383,17 +399,26 @@ const getSettings = (pane: Pane): Settings => {
383
399
return settings as Settings
384
400
}
385
401
386
- const createAutomaton = (
402
+ const createAutomaton = async (
387
403
canvasEl : HTMLCanvasElement ,
388
404
width : number ,
389
405
height : number ,
390
406
settings : Settings ,
391
- ) : AutomatonBase => {
407
+ ) : Promise < AutomatonBase > => {
392
408
const resolution : number = settings . resolution || 5
409
+ const paletteColors = settings . palette
410
+ ? moviePalettes . get ( settings . palette ) ?. colors
411
+ : undefined
393
412
394
413
switch ( settings . algo ) {
395
414
case "cca-1D" :
396
- return new CCA1D ( canvasEl , width , height , settings . cca1dColorsCount || 4 )
415
+ return await CCA1D . create (
416
+ canvasEl ,
417
+ width ,
418
+ height ,
419
+ settings . cca1dColorsCount || 4 ,
420
+ paletteColors ,
421
+ )
397
422
case "cca-2D" :
398
423
return new CCA2D (
399
424
settings . cca2dThreshold ,
0 commit comments