1
0

palettes.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. #!/usr/bin/env python3
  2. """
  3. WLED Color Palettes for Raspberry Pi
  4. Ported from WLED palettes.cpp
  5. All 59 gradient palettes from WLED
  6. """
  7. from typing import List, Tuple
  8. from .colors import color_blend, rgb_to_color
  9. # Gradient palette format: [(index, r, g, b), ...]
  10. # Index is 0-255 position in the palette
  11. # Gradient palettes (indices 13-71 in WLED, 0-58 here)
  12. SUNSET_REAL = [
  13. (0, 181, 0, 0),
  14. (22, 218, 85, 0),
  15. (51, 255, 170, 0),
  16. (85, 211, 85, 77),
  17. (135, 167, 0, 169),
  18. (198, 73, 0, 188),
  19. (255, 0, 0, 207)
  20. ]
  21. RIVENDELL = [
  22. (0, 24, 69, 44),
  23. (101, 73, 105, 70),
  24. (165, 129, 140, 97),
  25. (242, 200, 204, 166),
  26. (255, 200, 204, 166)
  27. ]
  28. BREEZE = [
  29. (0, 16, 48, 51),
  30. (89, 27, 166, 175),
  31. (153, 197, 233, 255),
  32. (255, 0, 145, 152)
  33. ]
  34. RED_BLUE = [
  35. (0, 41, 14, 99),
  36. (31, 128, 24, 74),
  37. (63, 227, 34, 50),
  38. (95, 132, 31, 76),
  39. (127, 47, 29, 102),
  40. (159, 109, 47, 101),
  41. (191, 176, 66, 100),
  42. (223, 129, 57, 104),
  43. (255, 84, 48, 108)
  44. ]
  45. YELLOWOUT = [
  46. (0, 222, 191, 8),
  47. (255, 117, 52, 1)
  48. ]
  49. ANALOGOUS = [
  50. (0, 38, 0, 255),
  51. (63, 86, 0, 255),
  52. (127, 139, 0, 255),
  53. (191, 196, 0, 117),
  54. (255, 255, 0, 0)
  55. ]
  56. SPLASH = [
  57. (0, 186, 63, 255),
  58. (127, 227, 9, 85),
  59. (175, 234, 205, 213),
  60. (221, 205, 38, 176),
  61. (255, 205, 38, 176)
  62. ]
  63. PASTEL = [
  64. (0, 61, 135, 184),
  65. (36, 129, 188, 169),
  66. (87, 203, 241, 155),
  67. (100, 228, 237, 141),
  68. (107, 255, 232, 127),
  69. (115, 251, 202, 130),
  70. (120, 248, 172, 133),
  71. (128, 251, 202, 130),
  72. (180, 255, 232, 127),
  73. (223, 255, 242, 120),
  74. (255, 255, 252, 113)
  75. ]
  76. SUNSET2 = [
  77. (0, 175, 121, 62),
  78. (29, 128, 103, 60),
  79. (68, 84, 84, 58),
  80. (68, 248, 184, 55),
  81. (97, 239, 204, 93),
  82. (124, 230, 225, 133),
  83. (178, 102, 125, 129),
  84. (255, 0, 26, 125)
  85. ]
  86. BEECH = [
  87. (0, 255, 254, 236),
  88. (12, 255, 254, 236),
  89. (22, 255, 254, 236),
  90. (26, 223, 224, 178),
  91. (28, 192, 195, 124),
  92. (28, 176, 255, 231),
  93. (50, 123, 251, 236),
  94. (71, 74, 246, 241),
  95. (93, 33, 225, 228),
  96. (120, 0, 204, 215),
  97. (133, 4, 168, 178),
  98. (136, 10, 132, 143),
  99. (136, 51, 189, 212),
  100. (208, 23, 159, 201),
  101. (255, 0, 129, 190)
  102. ]
  103. VINTAGE = [
  104. (0, 41, 18, 24),
  105. (51, 73, 0, 22),
  106. (76, 165, 170, 38),
  107. (101, 255, 189, 80),
  108. (127, 139, 56, 40),
  109. (153, 73, 0, 22),
  110. (229, 41, 18, 24),
  111. (255, 41, 18, 24)
  112. ]
  113. DEPARTURE = [
  114. (0, 53, 34, 0),
  115. (42, 86, 51, 0),
  116. (63, 147, 108, 49),
  117. (84, 212, 166, 108),
  118. (106, 235, 212, 180),
  119. (116, 255, 255, 255),
  120. (138, 191, 255, 193),
  121. (148, 84, 255, 88),
  122. (170, 0, 255, 0),
  123. (191, 0, 192, 0),
  124. (212, 0, 128, 0),
  125. (255, 0, 128, 0)
  126. ]
  127. LANDSCAPE = [
  128. (0, 0, 0, 0),
  129. (37, 31, 89, 19),
  130. (76, 72, 178, 43),
  131. (127, 150, 235, 5),
  132. (128, 186, 234, 119),
  133. (130, 222, 233, 252),
  134. (153, 197, 219, 231),
  135. (204, 132, 179, 253),
  136. (255, 28, 107, 225)
  137. ]
  138. BEACH = [
  139. (0, 12, 45, 0),
  140. (19, 101, 86, 2),
  141. (38, 207, 128, 4),
  142. (63, 243, 197, 18),
  143. (66, 109, 196, 146),
  144. (255, 5, 39, 7)
  145. ]
  146. SHERBET = [
  147. (0, 255, 102, 41),
  148. (43, 255, 140, 90),
  149. (86, 255, 51, 90),
  150. (127, 255, 153, 169),
  151. (170, 255, 255, 249),
  152. (209, 113, 255, 85),
  153. (255, 157, 255, 137)
  154. ]
  155. HULT = [
  156. (0, 251, 216, 252),
  157. (48, 255, 192, 255),
  158. (89, 239, 95, 241),
  159. (160, 51, 153, 217),
  160. (216, 24, 184, 174),
  161. (255, 24, 184, 174)
  162. ]
  163. HULT64 = [
  164. (0, 24, 184, 174),
  165. (66, 8, 162, 150),
  166. (104, 124, 137, 7),
  167. (130, 178, 186, 22),
  168. (150, 124, 137, 7),
  169. (201, 6, 156, 144),
  170. (239, 0, 128, 117),
  171. (255, 0, 128, 117)
  172. ]
  173. DRYWET = [
  174. (0, 119, 97, 33),
  175. (42, 235, 199, 88),
  176. (84, 169, 238, 124),
  177. (127, 37, 238, 232),
  178. (170, 7, 120, 236),
  179. (212, 27, 1, 175),
  180. (255, 4, 51, 101)
  181. ]
  182. JUL = [
  183. (0, 226, 6, 12),
  184. (94, 26, 96, 78),
  185. (132, 130, 189, 94),
  186. (255, 177, 3, 9)
  187. ]
  188. GRINTAGE = [
  189. (0, 29, 8, 3),
  190. (53, 76, 1, 0),
  191. (104, 142, 96, 28),
  192. (153, 211, 191, 61),
  193. (255, 117, 129, 42)
  194. ]
  195. REWHI = [
  196. (0, 177, 160, 199),
  197. (72, 205, 158, 149),
  198. (89, 233, 155, 101),
  199. (107, 255, 95, 63),
  200. (141, 192, 98, 109),
  201. (255, 132, 101, 159)
  202. ]
  203. TERTIARY = [
  204. (0, 0, 25, 255),
  205. (63, 38, 140, 117),
  206. (127, 86, 255, 0),
  207. (191, 167, 140, 19),
  208. (255, 255, 25, 41)
  209. ]
  210. FIRE = [
  211. (0, 0, 0, 0),
  212. (46, 77, 0, 0),
  213. (96, 177, 0, 0),
  214. (108, 196, 38, 9),
  215. (119, 215, 76, 19),
  216. (146, 235, 115, 29),
  217. (174, 255, 153, 41),
  218. (188, 255, 178, 41),
  219. (202, 255, 204, 41),
  220. (218, 255, 230, 41),
  221. (234, 255, 255, 41),
  222. (244, 255, 255, 143),
  223. (255, 255, 255, 255)
  224. ]
  225. ICEFIRE = [
  226. (0, 0, 0, 0),
  227. (59, 0, 51, 117),
  228. (119, 0, 102, 255),
  229. (149, 38, 153, 255),
  230. (180, 86, 204, 255),
  231. (217, 167, 230, 255),
  232. (255, 255, 255, 255)
  233. ]
  234. CYANE = [
  235. (0, 61, 155, 44),
  236. (25, 95, 174, 77),
  237. (60, 132, 193, 113),
  238. (93, 154, 166, 125),
  239. (106, 175, 138, 136),
  240. (109, 183, 121, 137),
  241. (113, 194, 104, 138),
  242. (116, 225, 179, 165),
  243. (124, 255, 255, 192),
  244. (168, 167, 218, 203),
  245. (255, 84, 182, 215)
  246. ]
  247. LIGHT_PINK = [
  248. (0, 79, 32, 109),
  249. (25, 90, 40, 117),
  250. (51, 102, 48, 124),
  251. (76, 141, 135, 185),
  252. (102, 180, 222, 248),
  253. (109, 208, 236, 252),
  254. (114, 237, 250, 255),
  255. (122, 206, 200, 239),
  256. (149, 177, 149, 222),
  257. (183, 187, 130, 203),
  258. (255, 198, 111, 184)
  259. ]
  260. AUTUMN = [
  261. (0, 90, 14, 5),
  262. (51, 139, 41, 13),
  263. (84, 180, 70, 17),
  264. (104, 192, 202, 125),
  265. (112, 177, 137, 3),
  266. (122, 190, 200, 131),
  267. (124, 192, 202, 124),
  268. (135, 177, 137, 3),
  269. (142, 194, 203, 118),
  270. (163, 177, 68, 17),
  271. (204, 128, 35, 12),
  272. (249, 74, 5, 2),
  273. (255, 74, 5, 2)
  274. ]
  275. MAGENTA = [
  276. (0, 0, 0, 0),
  277. (42, 0, 0, 117),
  278. (84, 0, 0, 255),
  279. (127, 113, 0, 255),
  280. (170, 255, 0, 255),
  281. (212, 255, 128, 255),
  282. (255, 255, 255, 255)
  283. ]
  284. MAGRED = [
  285. (0, 0, 0, 0),
  286. (63, 113, 0, 117),
  287. (127, 255, 0, 255),
  288. (191, 255, 0, 117),
  289. (255, 255, 0, 0)
  290. ]
  291. YELMAG = [
  292. (0, 0, 0, 0),
  293. (42, 113, 0, 0),
  294. (84, 255, 0, 0),
  295. (127, 255, 0, 117),
  296. (170, 255, 0, 255),
  297. (212, 255, 128, 117),
  298. (255, 255, 255, 0)
  299. ]
  300. YELBLU = [
  301. (0, 0, 0, 255),
  302. (63, 0, 128, 255),
  303. (127, 0, 255, 255),
  304. (191, 113, 255, 117),
  305. (255, 255, 255, 0)
  306. ]
  307. ORANGE_TEAL = [
  308. (0, 0, 150, 92),
  309. (55, 0, 150, 92),
  310. (200, 255, 72, 0),
  311. (255, 255, 72, 0)
  312. ]
  313. TIAMAT = [
  314. (0, 1, 2, 14),
  315. (33, 2, 5, 35),
  316. (100, 13, 135, 92),
  317. (120, 43, 255, 193),
  318. (140, 247, 7, 249),
  319. (160, 193, 17, 208),
  320. (180, 39, 255, 154),
  321. (200, 4, 213, 236),
  322. (220, 39, 252, 135),
  323. (240, 193, 213, 253),
  324. (255, 255, 249, 255)
  325. ]
  326. APRIL_NIGHT = [
  327. (0, 1, 5, 45),
  328. (10, 1, 5, 45),
  329. (25, 5, 169, 175),
  330. (40, 1, 5, 45),
  331. (61, 1, 5, 45),
  332. (76, 45, 175, 31),
  333. (91, 1, 5, 45),
  334. (112, 1, 5, 45),
  335. (127, 249, 150, 5),
  336. (143, 1, 5, 45),
  337. (162, 1, 5, 45),
  338. (178, 255, 92, 0),
  339. (193, 1, 5, 45),
  340. (214, 1, 5, 45),
  341. (229, 223, 45, 72),
  342. (244, 1, 5, 45),
  343. (255, 1, 5, 45)
  344. ]
  345. ORANGERY = [
  346. (0, 255, 95, 23),
  347. (30, 255, 82, 0),
  348. (60, 223, 13, 8),
  349. (90, 144, 44, 2),
  350. (120, 255, 110, 17),
  351. (150, 255, 69, 0),
  352. (180, 158, 13, 11),
  353. (210, 241, 82, 17),
  354. (255, 213, 37, 4)
  355. ]
  356. C9 = [
  357. (0, 184, 4, 0),
  358. (60, 184, 4, 0),
  359. (65, 144, 44, 2),
  360. (125, 144, 44, 2),
  361. (130, 4, 96, 2),
  362. (190, 4, 96, 2),
  363. (195, 7, 7, 88),
  364. (255, 7, 7, 88)
  365. ]
  366. SAKURA = [
  367. (0, 196, 19, 10),
  368. (65, 255, 69, 45),
  369. (130, 223, 45, 72),
  370. (195, 255, 82, 103),
  371. (255, 223, 13, 17)
  372. ]
  373. AURORA = [
  374. (0, 1, 5, 45),
  375. (64, 0, 200, 23),
  376. (128, 0, 255, 0),
  377. (170, 0, 243, 45),
  378. (200, 0, 135, 7),
  379. (255, 1, 5, 45)
  380. ]
  381. ATLANTICA = [
  382. (0, 0, 28, 112),
  383. (50, 32, 96, 255),
  384. (100, 0, 243, 45),
  385. (150, 12, 95, 82),
  386. (200, 25, 190, 95),
  387. (255, 40, 170, 80)
  388. ]
  389. C9_2 = [
  390. (0, 6, 126, 2),
  391. (45, 6, 126, 2),
  392. (46, 4, 30, 114),
  393. (90, 4, 30, 114),
  394. (91, 255, 5, 0),
  395. (135, 255, 5, 0),
  396. (136, 196, 57, 2),
  397. (180, 196, 57, 2),
  398. (181, 137, 85, 2),
  399. (255, 137, 85, 2)
  400. ]
  401. C9_NEW = [
  402. (0, 255, 5, 0),
  403. (60, 255, 5, 0),
  404. (61, 196, 57, 2),
  405. (120, 196, 57, 2),
  406. (121, 6, 126, 2),
  407. (180, 6, 126, 2),
  408. (181, 4, 30, 114),
  409. (255, 4, 30, 114)
  410. ]
  411. TEMPERATURE = [
  412. (0, 20, 92, 171),
  413. (14, 15, 111, 186),
  414. (28, 6, 142, 211),
  415. (42, 2, 161, 227),
  416. (56, 16, 181, 239),
  417. (70, 38, 188, 201),
  418. (84, 86, 204, 200),
  419. (99, 139, 219, 176),
  420. (113, 182, 229, 125),
  421. (127, 196, 230, 63),
  422. (141, 241, 240, 22),
  423. (155, 254, 222, 30),
  424. (170, 251, 199, 4),
  425. (184, 247, 157, 9),
  426. (198, 243, 114, 15),
  427. (226, 213, 30, 29),
  428. (240, 151, 38, 35),
  429. (255, 151, 38, 35)
  430. ]
  431. AURORA2 = [
  432. (0, 17, 177, 13),
  433. (64, 121, 242, 5),
  434. (128, 25, 173, 121),
  435. (192, 250, 77, 127),
  436. (255, 171, 101, 221)
  437. ]
  438. RETRO_CLOWN = [
  439. (0, 242, 168, 38),
  440. (117, 226, 78, 80),
  441. (255, 161, 54, 225)
  442. ]
  443. CANDY = [
  444. (0, 243, 242, 23),
  445. (15, 242, 168, 38),
  446. (142, 111, 21, 151),
  447. (198, 74, 22, 150),
  448. (255, 0, 0, 117)
  449. ]
  450. TOXY_REAF = [
  451. (0, 2, 239, 126),
  452. (255, 145, 35, 217)
  453. ]
  454. FAIRY_REAF = [
  455. (0, 220, 19, 187),
  456. (160, 12, 225, 219),
  457. (219, 203, 242, 223),
  458. (255, 255, 255, 255)
  459. ]
  460. SEMI_BLUE = [
  461. (0, 0, 0, 0),
  462. (12, 24, 4, 38),
  463. (53, 55, 8, 84),
  464. (80, 43, 48, 159),
  465. (119, 31, 89, 237),
  466. (145, 50, 59, 166),
  467. (186, 71, 30, 98),
  468. (233, 31, 15, 45),
  469. (255, 0, 0, 0)
  470. ]
  471. PINK_CANDY = [
  472. (0, 255, 255, 255),
  473. (45, 50, 64, 255),
  474. (112, 242, 16, 186),
  475. (140, 255, 255, 255),
  476. (155, 242, 16, 186),
  477. (196, 116, 13, 166),
  478. (255, 255, 255, 255)
  479. ]
  480. RED_REAF = [
  481. (0, 36, 68, 114),
  482. (104, 149, 195, 248),
  483. (188, 255, 0, 0),
  484. (255, 94, 14, 9)
  485. ]
  486. AQUA_FLASH = [
  487. (0, 0, 0, 0),
  488. (66, 130, 242, 245),
  489. (96, 255, 255, 53),
  490. (124, 255, 255, 255),
  491. (153, 255, 255, 53),
  492. (188, 130, 242, 245),
  493. (255, 0, 0, 0)
  494. ]
  495. YELBLU_HOT = [
  496. (0, 43, 30, 57),
  497. (58, 73, 0, 119),
  498. (122, 87, 0, 74),
  499. (158, 197, 57, 22),
  500. (183, 218, 117, 27),
  501. (219, 239, 177, 32),
  502. (255, 246, 247, 27)
  503. ]
  504. LITE_LIGHT = [
  505. (0, 0, 0, 0),
  506. (9, 20, 21, 22),
  507. (40, 46, 43, 49),
  508. (66, 46, 43, 49),
  509. (101, 61, 16, 65),
  510. (255, 0, 0, 0)
  511. ]
  512. RED_FLASH = [
  513. (0, 0, 0, 0),
  514. (99, 242, 12, 8),
  515. (130, 253, 228, 163),
  516. (155, 242, 12, 8),
  517. (255, 0, 0, 0)
  518. ]
  519. BLINK_RED = [
  520. (0, 4, 7, 4),
  521. (43, 40, 25, 62),
  522. (76, 61, 15, 36),
  523. (109, 207, 39, 96),
  524. (127, 255, 156, 184),
  525. (165, 185, 73, 207),
  526. (204, 105, 66, 240),
  527. (255, 77, 29, 78)
  528. ]
  529. RED_SHIFT = [
  530. (0, 98, 22, 93),
  531. (45, 103, 22, 73),
  532. (99, 192, 45, 56),
  533. (132, 235, 187, 59),
  534. (175, 228, 85, 26),
  535. (201, 228, 56, 48),
  536. (255, 2, 0, 2)
  537. ]
  538. RED_TIDE = [
  539. (0, 251, 46, 0),
  540. (28, 255, 139, 25),
  541. (43, 246, 158, 63),
  542. (58, 246, 216, 123),
  543. (84, 243, 94, 10),
  544. (114, 177, 65, 11),
  545. (140, 255, 241, 115),
  546. (168, 177, 65, 11),
  547. (196, 250, 233, 158),
  548. (216, 255, 94, 6),
  549. (255, 126, 8, 4)
  550. ]
  551. CANDY2 = [
  552. (0, 109, 102, 102),
  553. (25, 42, 49, 71),
  554. (48, 121, 96, 84),
  555. (73, 241, 214, 26),
  556. (89, 216, 104, 44),
  557. (130, 42, 49, 71),
  558. (163, 255, 177, 47),
  559. (186, 241, 214, 26),
  560. (211, 109, 102, 102),
  561. (255, 20, 19, 13)
  562. ]
  563. TRAFFIC_LIGHT = [
  564. (0, 0, 0, 0),
  565. (85, 0, 255, 0),
  566. (170, 255, 255, 0),
  567. (255, 255, 0, 0)
  568. ]
  569. # All palettes in order (matching WLED indices 13-71, stored as 0-58 here)
  570. ALL_PALETTES = [
  571. SUNSET_REAL, # 0 (WLED 13)
  572. RIVENDELL, # 1
  573. BREEZE, # 2
  574. RED_BLUE, # 3
  575. YELLOWOUT, # 4
  576. ANALOGOUS, # 5
  577. SPLASH, # 6
  578. PASTEL, # 7
  579. SUNSET2, # 8
  580. BEECH, # 9
  581. VINTAGE, # 10
  582. DEPARTURE, # 11
  583. LANDSCAPE, # 12
  584. BEACH, # 13
  585. SHERBET, # 14
  586. HULT, # 15
  587. HULT64, # 16
  588. DRYWET, # 17
  589. JUL, # 18
  590. GRINTAGE, # 19
  591. REWHI, # 20
  592. TERTIARY, # 21
  593. FIRE, # 22
  594. ICEFIRE, # 23
  595. CYANE, # 24
  596. LIGHT_PINK, # 25
  597. AUTUMN, # 26
  598. MAGENTA, # 27
  599. MAGRED, # 28
  600. YELMAG, # 29
  601. YELBLU, # 30
  602. ORANGE_TEAL, # 31
  603. TIAMAT, # 32
  604. APRIL_NIGHT, # 33
  605. ORANGERY, # 34
  606. C9, # 35
  607. SAKURA, # 36
  608. AURORA, # 37
  609. ATLANTICA, # 38
  610. C9_2, # 39
  611. C9_NEW, # 40
  612. TEMPERATURE, # 41
  613. AURORA2, # 42
  614. RETRO_CLOWN, # 43
  615. CANDY, # 44
  616. TOXY_REAF, # 45
  617. FAIRY_REAF, # 46
  618. SEMI_BLUE, # 47
  619. PINK_CANDY, # 48
  620. RED_REAF, # 49
  621. AQUA_FLASH, # 50
  622. YELBLU_HOT, # 51
  623. LITE_LIGHT, # 52
  624. RED_FLASH, # 53
  625. BLINK_RED, # 54
  626. RED_SHIFT, # 55
  627. RED_TIDE, # 56
  628. CANDY2, # 57
  629. TRAFFIC_LIGHT # 58
  630. ]
  631. PALETTE_NAMES = [
  632. "Sunset", "Rivendell", "Breeze", "Red & Blue", "Yellowout",
  633. "Analogous", "Splash", "Pastel", "Sunset2", "Beech",
  634. "Vintage", "Departure", "Landscape", "Beach", "Sherbet",
  635. "Hult", "Hult64", "Drywet", "Jul", "Grintage",
  636. "Rewhi", "Tertiary", "Fire", "Icefire", "Cyane",
  637. "Light Pink", "Autumn", "Magenta", "Magred", "Yelmag",
  638. "Yelblu", "Orange & Teal", "Tiamat", "April Night", "Orangery",
  639. "C9", "Sakura", "Aurora", "Atlantica", "C9 2",
  640. "C9 New", "Temperature", "Aurora 2", "Retro Clown", "Candy",
  641. "Toxy Reaf", "Fairy Reaf", "Semi Blue", "Pink Candy", "Red Reaf",
  642. "Aqua Flash", "Yelblu Hot", "Lite Light", "Red Flash", "Blink Red",
  643. "Red Shift", "Red Tide", "Candy2", "Traffic Light"
  644. ]
  645. def color_from_palette(palette: List[Tuple[int, int, int, int]],
  646. index: int,
  647. brightness: int = 255) -> int:
  648. """
  649. Get color from gradient palette at given index
  650. index: 0-255 position in palette
  651. brightness: 0-255 brightness scaling
  652. Returns: 32-bit RGB color
  653. """
  654. index = index & 0xFF
  655. # Find the two palette entries to blend between
  656. for i in range(len(palette) - 1):
  657. if index <= palette[i + 1][0]:
  658. idx1, r1, g1, b1 = palette[i]
  659. idx2, r2, g2, b2 = palette[i + 1]
  660. # Calculate blend amount
  661. if idx2 == idx1:
  662. blend = 0
  663. else:
  664. blend = ((index - idx1) * 255) // (idx2 - idx1)
  665. # Blend colors
  666. r = ((r1 * (255 - blend)) + (r2 * blend)) // 255
  667. g = ((g1 * (255 - blend)) + (g2 * blend)) // 255
  668. b = ((b1 * (255 - blend)) + (b2 * blend)) // 255
  669. # Apply brightness
  670. if brightness < 255:
  671. r = (r * brightness) // 255
  672. g = (g * brightness) // 255
  673. b = (b * brightness) // 255
  674. return rgb_to_color(r, g, b)
  675. # If we're past the last entry, use the last color
  676. idx, r, g, b = palette[-1]
  677. if brightness < 255:
  678. r = (r * brightness) // 255
  679. g = (g * brightness) // 255
  680. b = (b * brightness) // 255
  681. return rgb_to_color(r, g, b)
  682. def get_palette(palette_id: int) -> List[Tuple[int, int, int, int]]:
  683. """Get palette by ID (0-58)"""
  684. if 0 <= palette_id < len(ALL_PALETTES):
  685. return ALL_PALETTES[palette_id]
  686. return ALL_PALETTES[0] # Default to Sunset
  687. def get_palette_name(palette_id: int) -> str:
  688. """Get palette name by ID"""
  689. if 0 <= palette_id < len(PALETTE_NAMES):
  690. return PALETTE_NAMES[palette_id]
  691. return "Unknown"