Advertisement
Anatoly03

Colors 8

Jan 11th, 2020
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.63 KB | None | 0 0
  1.  
  2. --# Colors
  3.  
  4. --[[
  5.  
  6. Name: Colors
  7. Author: Anatoly
  8. License: ISC
  9. Description: Colors is a library, that manipulates colors.
  10. Thread: https://codea.io/talk/discussion/10043/colors
  11. Release: 8
  12.  
  13. Color{}
  14. - NEW VALUE - desaturate = "min"
  15. - INSTEAD OF "origin", you can now use "hue"
  16. - "shade" supports latest adds
  17. - Suffixes now step in fives: red-5 to red-95
  18.  
  19. Main
  20. - Color wheel sorted by color.
  21.  
  22. ]]
  23.  
  24. colors = {}
  25.  
  26. do
  27.  
  28. local colors1 = {}
  29.  
  30. -- Origins
  31. colors1["red"] = color(255, 0, 0, 255)
  32. colors1["orangered"] = color(255, 80, 0, 255)
  33. colors1["orange"] = color(255, 150, 0, 255)
  34. colors1["brown"] = color(200, 115, 45, 255)
  35. colors1["darkbrown"] = color(115, 75, 40, 255)
  36. colors1["strawberry-red"] = color(223, 85, 111, 255)
  37. colors1["yellow"] = color(255, 255, 0, 255)
  38. colors1["gold"] = color(225, 180, 60, 255)
  39. colors1["bronze"] = color(190, 155, 90, 255)
  40. colors1["forestgreen"] = color(0, 155, 0, 255)
  41. colors1["middlegreen"] = color(150, 155, 0, 255)
  42. colors1["green"] = color(0, 255, 0, 255)
  43. colors1["grassgreen"] = color(150, 255, 0, 255)
  44. colors1["turquoise"] = color(0, 255, 150, 255)
  45. colors1["neon-green"] = color(210, 255, 0, 255)
  46. colors1["blue"] = color(0, 0, 255, 255)
  47. colors1["skyblue"] = color(0, 150, 255, 255)
  48. colors1["seablue"] = color(50, 200, 255)
  49. colors1["diamondblue"] = color(95, 170, 225, 255)
  50. colors1["cyan"] = color(0, 255, 255, 255)
  51. colors1["silver"] = color(180, 210, 210, 255)
  52. colors1["cold-white"] = color(192, 212, 225, 255)
  53. colors1["warm-white"] = color(228, 223, 207, 255)
  54. colors1["purple"] = color(160, 0, 255, 255)
  55. colors1["rosa"] = color(255, 0, 150, 255)
  56. colors1["magenta"] = color(255, 0, 255, 255)
  57. colors1["pink"] = color(255, 150, 255, 255)
  58. colors1["violet"] = color(125, 0, 255, 255)
  59. colors1["darkviolet"] = color(150, 25, 120, 255)
  60.  
  61. -- SVG, X11
  62. -- Author: Andrew Stacey, adopted by Anatoly
  63. -- Website: http://www.math.ntnu.no/~stacey/HowDidIDoThat/iPad/Codea.html
  64. -- Source: https://github.com/loopspace/Codea-Library-Base/blob/master/ColourExt.lua
  65. -- Licence: CC0 (http://wiki.creativecommons.org/CC0)
  66.  
  67. -- SVG
  68.  
  69. local schema = {}
  70.  
  71. schema.svg = {}
  72. schema.svg.AliceBlue = color(239,247,255,255)
  73. schema.svg.AntiqueWhite = color(249,234,215,255)
  74. schema.svg.Aqua = color(0,255,255,255)
  75. schema.svg.Aquamarine = color(126,255,211,255)
  76. schema.svg.Azure = color(239,255,255,255)
  77. schema.svg.Beige = color(244,244,220,255)
  78. schema.svg.Bisque = color(255,227,196,255)
  79. schema.svg.Black = color(0,0,0,255)
  80. schema.svg.BlanchedAlmond = color(255,234,205,255)
  81. schema.svg.Blue = color(0,0,255,255)
  82. schema.svg.BlueViolet = color(137,43,226,255)
  83. schema.svg.Brown = color(165,42,42,255)
  84. schema.svg.BurlyWood = color(221,183,135,255)
  85. schema.svg.CadetBlue = color(94,158,160,255)
  86. schema.svg.Chartreuse = color(126,255,0,255)
  87. schema.svg.Chocolate = color(210,104,29,255)
  88. schema.svg.Coral = color(255,126,79,255)
  89. schema.svg.CornflowerBlue = color(99,149,237,255)
  90. schema.svg.Cornsilk = color(255,247,220,255)
  91. schema.svg.Crimson = color(220,20,59,255)
  92. schema.svg.Cyan = color(0,255,255,255)
  93. schema.svg.DarkBlue = color(0,0,138,255)
  94. schema.svg.DarkCyan = color(0,138,138,255)
  95. schema.svg.DarkGoldenrod = color(183,133,11,255)
  96. schema.svg.DarkGray = color(169,169,169,255)
  97. schema.svg.DarkGreen = color(0,99,0,255)
  98. schema.svg.DarkGrey = color(169,169,169,255)
  99. schema.svg.DarkKhaki = color(188,182,107,255)
  100. schema.svg.DarkMagenta = color(138,0,138,255)
  101. schema.svg.DarkOliveGreen = color(84,107,47,255)
  102. schema.svg.DarkOrange = color(255,140,0,255)
  103. schema.svg.DarkOrchid = color(183,49,204,255)
  104. schema.svg.DarkRed = color(138,0,0,255)
  105. schema.svg.DarkSalmon = color(232,150,122,255)
  106. schema.svg.DarkSeaGreen = color(142,187,142,255)
  107. schema.svg.DarkSlateBlue = color(72,61,138,255)
  108. schema.svg.DarkSlateGray = color(47,79,79,255)
  109. schema.svg.DarkSlateGrey = color(47,79,79,255)
  110. schema.svg.DarkTurquoise = color(0,206,209,255)
  111. schema.svg.DarkViolet = color(147,0,211,255)
  112. schema.svg.DeepPink = color(255,20,146,255)
  113. schema.svg.DeepSkyBlue = color(0,191,255,255)
  114. schema.svg.DimGray = color(104,104,104,255)
  115. schema.svg.DimGrey = color(104,104,104,255)
  116. schema.svg.DodgerBlue = color(29,144,255,255)
  117. schema.svg.FireBrick = color(177,33,33,255)
  118. schema.svg.FloralWhite = color(255,249,239,255)
  119. schema.svg.ForestGreen = color(33,138,33,255)
  120. schema.svg.Fuchsia = color(255,0,255,255)
  121. schema.svg.Gainsboro = color(220,220,220,255)
  122. schema.svg.GhostWhite = color(247,247,255,255)
  123. schema.svg.Gold = color(255,215,0,255)
  124. schema.svg.Goldenrod = color(218,165,31,255)
  125. schema.svg.Gray = color(127,127,127,255)
  126. schema.svg.Green = color(0,127,0,255)
  127. schema.svg.GreenYellow = color(173,255,47,255)
  128. schema.svg.Grey = color(127,127,127,255)
  129. schema.svg.Honeydew = color(239,255,239,255)
  130. schema.svg.HotPink = color(255,104,179,255)
  131. schema.svg.IndianRed = color(205,91,91,255)
  132. schema.svg.Indigo = color(74,0,130,255)
  133. schema.svg.Ivory = color(255,255,239,255)
  134. schema.svg.Khaki = color(239,229,140,255)
  135. schema.svg.Lavender = color(229,229,249,255)
  136. schema.svg.LavenderBlush = color(255,239,244,255)
  137. schema.svg.LawnGreen = color(124,252,0,255)
  138. schema.svg.LemonChiffon = color(255,249,205,255)
  139. schema.svg.LightBlue = color(173,216,229,255)
  140. schema.svg.LightCoral = color(239,127,127,255)
  141. schema.svg.LightCyan = color(224,255,255,255)
  142. schema.svg.LightGoldenrod = color(237,221,130,255)
  143. schema.svg.LightGoldenrodYellow = color(249,249,210,255)
  144. schema.svg.LightGray = color(211,211,211,255)
  145. schema.svg.LightGreen = color(144,237,144,255)
  146. schema.svg.LightGrey = color(211,211,211,255)
  147. schema.svg.LightPink = color(255,181,192,255)
  148. schema.svg.LightSalmon = color(255,160,122,255)
  149. schema.svg.LightSeaGreen = color(31,177,170,255)
  150. schema.svg.LightSkyBlue = color(135,206,249,255)
  151. schema.svg.LightSlateBlue = color(132,112,255,255)
  152. schema.svg.LightSlateGray = color(119,135,153,255)
  153. schema.svg.LightSlateGrey = color(119,135,153,255)
  154. schema.svg.LightSteelBlue = color(175,196,221,255)
  155. schema.svg.LightYellow = color(255,255,224,255)
  156. schema.svg.Lime = color(0,255,0,255)
  157. schema.svg.LimeGreen = color(49,205,49,255)
  158. schema.svg.Linen = color(249,239,229,255)
  159. schema.svg.Magenta = color(255,0,255,255)
  160. schema.svg.Maroon = color(127,0,0,255)
  161. schema.svg.MediumAquamarine = color(102,205,170,255)
  162. schema.svg.MediumBlue = color(0,0,205,255)
  163. schema.svg.MediumOrchid = color(186,84,211,255)
  164. schema.svg.MediumPurple = color(146,112,219,255)
  165. schema.svg.MediumSeaGreen = color(59,178,113,255)
  166. schema.svg.MediumSlateBlue = color(123,104,237,255)
  167. schema.svg.MediumSpringGreen = color(0,249,154,255)
  168. schema.svg.MediumTurquoise = color(72,209,204,255)
  169. schema.svg.MediumVioletRed = color(198,21,132,255)
  170. schema.svg.MidnightBlue = color(24,24,112,255)
  171. schema.svg.MintCream = color(244,255,249,255)
  172. schema.svg.MistyRose = color(255,227,225,255)
  173. schema.svg.Moccasin = color(255,227,181,255)
  174. schema.svg.NavajoWhite = color(255,221,173,255)
  175. schema.svg.Navy = color(0,0,127,255)
  176. schema.svg.NavyBlue = color(0,0,127,255)
  177. schema.svg.OldLace = color(252,244,229,255)
  178. schema.svg.Olive = color(127,127,0,255)
  179. schema.svg.OliveDrab = color(107,141,34,255)
  180. schema.svg.Orange = color(255,165,0,255)
  181. schema.svg.OrangeRed = color(255,68,0,255)
  182. schema.svg.Orchid = color(218,112,214,255)
  183. schema.svg.PaleGoldenrod = color(237,232,170,255)
  184. schema.svg.PaleGreen = color(151,251,151,255)
  185. schema.svg.PaleTurquoise = color(175,237,237,255)
  186. schema.svg.PaleVioletRed = color(219,112,146,255)
  187. schema.svg.PapayaWhip = color(255,238,212,255)
  188. schema.svg.PeachPuff = color(255,218,184,255)
  189. schema.svg.Peru = color(205,132,63,255)
  190. schema.svg.Pink = color(255,191,202,255)
  191. schema.svg.Plum = color(221,160,221,255)
  192. schema.svg.PowderBlue = color(175,224,229,255)
  193. schema.svg.Purple = color(127,0,127,255)
  194. schema.svg.Red = color(255,0,0,255)
  195. schema.svg.RosyBrown = color(187,142,142,255)
  196. schema.svg.RoyalBlue = color(65,104,225,255)
  197. schema.svg.SaddleBrown = color(138,68,19,255)
  198. schema.svg.Salmon = color(249,127,114,255)
  199. schema.svg.SandyBrown = color(243,164,95,255)
  200. schema.svg.SeaGreen = color(45,138,86,255)
  201. schema.svg.Seashell = color(255,244,237,255)
  202. schema.svg.Sienna = color(160,81,44,255)
  203. schema.svg.Silver = color(191,191,191,255)
  204. schema.svg.SkyBlue = color(135,206,234,255)
  205. schema.svg.SlateBlue = color(105,89,205,255)
  206. schema.svg.SlateGray = color(112,127,144,255)
  207. schema.svg.SlateGrey = color(112,127,144,255)
  208. schema.svg.Snow = color(255,249,249,255)
  209. schema.svg.SpringGreen = color(0,255,126,255)
  210. schema.svg.SteelBlue = color(70,130,179,255)
  211. schema.svg.Tan = color(210,179,140,255)
  212. schema.svg.Teal = color(0,127,127,255)
  213. schema.svg.Thistle = color(216,191,216,255)
  214. schema.svg.Tomato = color(255,99,71,255)
  215. schema.svg.Turquoise = color(63,224,207,255)
  216. schema.svg.Violet = color(237,130,237,255)
  217. schema.svg.VioletRed = color(208,31,144,255)
  218. schema.svg.Wheat = color(244,221,178,255)
  219. schema.svg.White = color(255,255,255,255)
  220. schema.svg.WhiteSmoke = color(244,244,244,255)
  221. schema.svg.Yellow = color(255,255,0,255)
  222. schema.svg.YellowGreen = color(154,205,49,255)
  223.  
  224. for a, b in pairs(schema.svg) do
  225. colors["svg-" .. string.lower(a)] = b
  226. end
  227.  
  228. -- X11
  229.  
  230. schema.x11 = {}
  231. schema.x11.AntiqueWhite1 = color(255,238,219,255)
  232. schema.x11.AntiqueWhite2 = color(237,223,204,255)
  233. schema.x11.AntiqueWhite3 = color(205,191,175,255)
  234. schema.x11.AntiqueWhite4 = color(138,130,119,255)
  235. schema.x11.Aquamarine1 = color(126,255,211,255)
  236. schema.x11.Aquamarine2 = color(118,237,197,255)
  237. schema.x11.Aquamarine3 = color(102,205,170,255)
  238. schema.x11.Aquamarine4 = color(68,138,116,255)
  239. schema.x11.Azure1 = color(239,255,255,255)
  240. schema.x11.Azure2 = color(224,237,237,255)
  241. schema.x11.Azure3 = color(192,205,205,255)
  242. schema.x11.Azure4 = color(130,138,138,255)
  243. schema.x11.Bisque1 = color(255,227,196,255)
  244. schema.x11.Bisque2 = color(237,212,182,255)
  245. schema.x11.Bisque3 = color(205,182,158,255)
  246. schema.x11.Bisque4 = color(138,124,107,255)
  247. schema.x11.Blue1 = color(0,0,255,255)
  248. schema.x11.Blue2 = color(0,0,237,255)
  249. schema.x11.Blue3 = color(0,0,205,255)
  250. schema.x11.Blue4 = color(0,0,138,255)
  251. schema.x11.Brown1 = color(255,63,63,255)
  252. schema.x11.Brown2 = color(237,58,58,255)
  253. schema.x11.Brown3 = color(205,51,51,255)
  254. schema.x11.Brown4 = color(138,34,34,255)
  255. schema.x11.Burlywood1 = color(255,211,155,255)
  256. schema.x11.Burlywood2 = color(237,196,145,255)
  257. schema.x11.Burlywood3 = color(205,170,124,255)
  258. schema.x11.Burlywood4 = color(138,114,84,255)
  259. schema.x11.CadetBlue1 = color(151,244,255,255)
  260. schema.x11.CadetBlue2 = color(141,228,237,255)
  261. schema.x11.CadetBlue3 = color(122,196,205,255)
  262. schema.x11.CadetBlue4 = color(82,133,138,255)
  263. schema.x11.Chartreuse1 = color(126,255,0,255)
  264. schema.x11.Chartreuse2 = color(118,237,0,255)
  265. schema.x11.Chartreuse3 = color(102,205,0,255)
  266. schema.x11.Chartreuse4 = color(68,138,0,255)
  267. schema.x11.Chocolate1 = color(255,126,35,255)
  268. schema.x11.Chocolate2 = color(237,118,33,255)
  269. schema.x11.Chocolate3 = color(205,102,28,255)
  270. schema.x11.Chocolate4 = color(138,68,19,255)
  271. schema.x11.Coral1 = color(255,114,85,255)
  272. schema.x11.Coral2 = color(237,105,79,255)
  273. schema.x11.Coral3 = color(205,90,68,255)
  274. schema.x11.Coral4 = color(138,62,47,255)
  275. schema.x11.Cornsilk1 = color(255,247,220,255)
  276. schema.x11.Cornsilk2 = color(237,232,205,255)
  277. schema.x11.Cornsilk3 = color(205,200,176,255)
  278. schema.x11.Cornsilk4 = color(138,135,119,255)
  279. schema.x11.Cyan1 = color(0,255,255,255)
  280. schema.x11.Cyan2 = color(0,237,237,255)
  281. schema.x11.Cyan3 = color(0,205,205,255)
  282. schema.x11.Cyan4 = color(0,138,138,255)
  283. schema.x11.DarkGoldenrod1 = color(255,184,15,255)
  284. schema.x11.DarkGoldenrod2 = color(237,173,14,255)
  285. schema.x11.DarkGoldenrod3 = color(205,149,12,255)
  286. schema.x11.DarkGoldenrod4 = color(138,100,7,255)
  287. schema.x11.DarkOliveGreen1 = color(201,255,112,255)
  288. schema.x11.DarkOliveGreen2 = color(187,237,104,255)
  289. schema.x11.DarkOliveGreen3 = color(161,205,89,255)
  290. schema.x11.DarkOliveGreen4 = color(109,138,61,255)
  291. schema.x11.DarkOrange1 = color(255,126,0,255)
  292. schema.x11.DarkOrange2 = color(237,118,0,255)
  293. schema.x11.DarkOrange3 = color(205,102,0,255)
  294. schema.x11.DarkOrange4 = color(138,68,0,255)
  295. schema.x11.DarkOrchid1 = color(191,62,255,255)
  296. schema.x11.DarkOrchid2 = color(177,58,237,255)
  297. schema.x11.DarkOrchid3 = color(154,49,205,255)
  298. schema.x11.DarkOrchid4 = color(104,33,138,255)
  299. schema.x11.DarkSeaGreen1 = color(192,255,192,255)
  300. schema.x11.DarkSeaGreen2 = color(179,237,179,255)
  301. schema.x11.DarkSeaGreen3 = color(155,205,155,255)
  302. schema.x11.DarkSeaGreen4 = color(104,138,104,255)
  303. schema.x11.DarkSlateGray1 = color(150,255,255,255)
  304. schema.x11.DarkSlateGray2 = color(140,237,237,255)
  305. schema.x11.DarkSlateGray3 = color(121,205,205,255)
  306. schema.x11.DarkSlateGray4 = color(81,138,138,255)
  307. schema.x11.DeepPink1 = color(255,20,146,255)
  308. schema.x11.DeepPink2 = color(237,17,136,255)
  309. schema.x11.DeepPink3 = color(205,16,118,255)
  310. schema.x11.DeepPink4 = color(138,10,79,255)
  311. schema.x11.DeepSkyBlue1 = color(0,191,255,255)
  312. schema.x11.DeepSkyBlue2 = color(0,177,237,255)
  313. schema.x11.DeepSkyBlue3 = color(0,154,205,255)
  314. schema.x11.DeepSkyBlue4 = color(0,104,138,255)
  315. schema.x11.DodgerBlue1 = color(29,144,255,255)
  316. schema.x11.DodgerBlue2 = color(28,133,237,255)
  317. schema.x11.DodgerBlue3 = color(23,116,205,255)
  318. schema.x11.DodgerBlue4 = color(16,77,138,255)
  319. schema.x11.Firebrick1 = color(255,48,48,255)
  320. schema.x11.Firebrick2 = color(237,43,43,255)
  321. schema.x11.Firebrick3 = color(205,38,38,255)
  322. schema.x11.Firebrick4 = color(138,25,25,255)
  323. schema.x11.Gold1 = color(255,215,0,255)
  324. schema.x11.Gold2 = color(237,201,0,255)
  325. schema.x11.Gold3 = color(205,173,0,255)
  326. schema.x11.Gold4 = color(138,117,0,255)
  327. schema.x11.Goldenrod1 = color(255,192,36,255)
  328. schema.x11.Goldenrod2 = color(237,179,33,255)
  329. schema.x11.Goldenrod3 = color(205,155,28,255)
  330. schema.x11.Goldenrod4 = color(138,104,20,255)
  331. schema.x11.Green1 = color(0,255,0,255)
  332. schema.x11.Green2 = color(0,237,0,255)
  333. schema.x11.Green3 = color(0,205,0,255)
  334. schema.x11.Green4 = color(0,138,0,255)
  335. schema.x11.Honeydew1 = color(239,255,239,255)
  336. schema.x11.Honeydew2 = color(224,237,224,255)
  337. schema.x11.Honeydew3 = color(192,205,192,255)
  338. schema.x11.Honeydew4 = color(130,138,130,255)
  339. schema.x11.HotPink1 = color(255,109,179,255)
  340. schema.x11.HotPink2 = color(237,105,167,255)
  341. schema.x11.HotPink3 = color(205,95,144,255)
  342. schema.x11.HotPink4 = color(138,58,98,255)
  343. schema.x11.IndianRed1 = color(255,105,105,255)
  344. schema.x11.IndianRed2 = color(237,99,99,255)
  345. schema.x11.IndianRed3 = color(205,84,84,255)
  346. schema.x11.IndianRed4 = color(138,58,58,255)
  347. schema.x11.Ivory1 = color(255,255,239,255)
  348. schema.x11.Ivory2 = color(237,237,224,255)
  349. schema.x11.Ivory3 = color(205,205,192,255)
  350. schema.x11.Ivory4 = color(138,138,130,255)
  351. schema.x11.Khaki1 = color(255,246,142,255)
  352. schema.x11.Khaki2 = color(237,229,132,255)
  353. schema.x11.Khaki3 = color(205,197,114,255)
  354. schema.x11.Khaki4 = color(138,133,77,255)
  355. schema.x11.LavenderBlush1 = color(255,239,244,255)
  356. schema.x11.LavenderBlush2 = color(237,224,228,255)
  357. schema.x11.LavenderBlush3 = color(205,192,196,255)
  358. schema.x11.LavenderBlush4 = color(138,130,133,255)
  359. schema.x11.LemonChiffon1 = color(255,249,205,255)
  360. schema.x11.LemonChiffon2 = color(237,232,191,255)
  361. schema.x11.LemonChiffon3 = color(205,201,165,255)
  362. schema.x11.LemonChiffon4 = color(138,136,112,255)
  363. schema.x11.LightBlue1 = color(191,238,255,255)
  364. schema.x11.LightBlue2 = color(177,223,237,255)
  365. schema.x11.LightBlue3 = color(154,191,205,255)
  366. schema.x11.LightBlue4 = color(104,130,138,255)
  367. schema.x11.LightCyan1 = color(224,255,255,255)
  368. schema.x11.LightCyan2 = color(209,237,237,255)
  369. schema.x11.LightCyan3 = color(179,205,205,255)
  370. schema.x11.LightCyan4 = color(122,138,138,255)
  371. schema.x11.LightGoldenrod1 = color(255,235,138,255)
  372. schema.x11.LightGoldenrod2 = color(237,220,130,255)
  373. schema.x11.LightGoldenrod3 = color(205,189,112,255)
  374. schema.x11.LightGoldenrod4 = color(138,128,75,255)
  375. schema.x11.LightPink1 = color(255,174,184,255)
  376. schema.x11.LightPink2 = color(237,161,173,255)
  377. schema.x11.LightPink3 = color(205,140,149,255)
  378. schema.x11.LightPink4 = color(138,94,100,255)
  379. schema.x11.LightSalmon1 = color(255,160,122,255)
  380. schema.x11.LightSalmon2 = color(237,149,114,255)
  381. schema.x11.LightSalmon3 = color(205,128,98,255)
  382. schema.x11.LightSalmon4 = color(138,86,66,255)
  383. schema.x11.LightSkyBlue1 = color(175,226,255,255)
  384. schema.x11.LightSkyBlue2 = color(164,211,237,255)
  385. schema.x11.LightSkyBlue3 = color(140,181,205,255)
  386. schema.x11.LightSkyBlue4 = color(95,123,138,255)
  387. schema.x11.LightSteelBlue1 = color(201,225,255,255)
  388. schema.x11.LightSteelBlue2 = color(187,210,237,255)
  389. schema.x11.LightSteelBlue3 = color(161,181,205,255)
  390. schema.x11.LightSteelBlue4 = color(109,123,138,255)
  391. schema.x11.LightYellow1 = color(255,255,224,255)
  392. schema.x11.LightYellow2 = color(237,237,209,255)
  393. schema.x11.LightYellow3 = color(205,205,179,255)
  394. schema.x11.LightYellow4 = color(138,138,122,255)
  395. schema.x11.Magenta1 = color(255,0,255,255)
  396. schema.x11.Magenta2 = color(237,0,237,255)
  397. schema.x11.Magenta3 = color(205,0,205,255)
  398. schema.x11.Magenta4 = color(138,0,138,255)
  399. schema.x11.Maroon1 = color(255,52,178,255)
  400. schema.x11.Maroon2 = color(237,48,167,255)
  401. schema.x11.Maroon3 = color(205,40,144,255)
  402. schema.x11.Maroon4 = color(138,28,98,255)
  403. schema.x11.MediumOrchid1 = color(224,102,255,255)
  404. schema.x11.MediumOrchid2 = color(209,94,237,255)
  405. schema.x11.MediumOrchid3 = color(179,81,205,255)
  406. schema.x11.MediumOrchid4 = color(122,54,138,255)
  407. schema.x11.MediumPurple1 = color(170,130,255,255)
  408. schema.x11.MediumPurple2 = color(159,121,237,255)
  409. schema.x11.MediumPurple3 = color(136,104,205,255)
  410. schema.x11.MediumPurple4 = color(93,71,138,255)
  411. schema.x11.MistyRose1 = color(255,227,225,255)
  412. schema.x11.MistyRose2 = color(237,212,210,255)
  413. schema.x11.MistyRose3 = color(205,182,181,255)
  414. schema.x11.MistyRose4 = color(138,124,123,255)
  415. schema.x11.NavajoWhite1 = color(255,221,173,255)
  416. schema.x11.NavajoWhite2 = color(237,206,160,255)
  417. schema.x11.NavajoWhite3 = color(205,178,138,255)
  418. schema.x11.NavajoWhite4 = color(138,121,94,255)
  419. schema.x11.OliveDrab1 = color(191,255,62,255)
  420. schema.x11.OliveDrab2 = color(178,237,58,255)
  421. schema.x11.OliveDrab3 = color(154,205,49,255)
  422. schema.x11.OliveDrab4 = color(104,138,33,255)
  423. schema.x11.Orange1 = color(255,165,0,255)
  424. schema.x11.Orange2 = color(237,154,0,255)
  425. schema.x11.Orange3 = color(205,132,0,255)
  426. schema.x11.Orange4 = color(138,89,0,255)
  427. schema.x11.OrangeRed1 = color(255,68,0,255)
  428. schema.x11.OrangeRed2 = color(237,63,0,255)
  429. schema.x11.OrangeRed3 = color(205,54,0,255)
  430. schema.x11.OrangeRed4 = color(138,36,0,255)
  431. schema.x11.Orchid1 = color(255,130,249,255)
  432. schema.x11.Orchid2 = color(237,122,232,255)
  433. schema.x11.Orchid3 = color(205,104,201,255)
  434. schema.x11.Orchid4 = color(138,71,136,255)
  435. schema.x11.PaleGreen1 = color(154,255,154,255)
  436. schema.x11.PaleGreen2 = color(144,237,144,255)
  437. schema.x11.PaleGreen3 = color(124,205,124,255)
  438. schema.x11.PaleGreen4 = color(84,138,84,255)
  439. schema.x11.PaleTurquoise1 = color(186,255,255,255)
  440. schema.x11.PaleTurquoise2 = color(174,237,237,255)
  441. schema.x11.PaleTurquoise3 = color(150,205,205,255)
  442. schema.x11.PaleTurquoise4 = color(102,138,138,255)
  443. schema.x11.PaleVioletRed1 = color(255,130,170,255)
  444. schema.x11.PaleVioletRed2 = color(237,121,159,255)
  445. schema.x11.PaleVioletRed3 = color(205,104,136,255)
  446. schema.x11.PaleVioletRed4 = color(138,71,93,255)
  447. schema.x11.PeachPuff1 = color(255,218,184,255)
  448. schema.x11.PeachPuff2 = color(237,202,173,255)
  449. schema.x11.PeachPuff3 = color(205,175,149,255)
  450. schema.x11.PeachPuff4 = color(138,119,100,255)
  451. schema.x11.Pink1 = color(255,181,196,255)
  452. schema.x11.Pink2 = color(237,169,183,255)
  453. schema.x11.Pink3 = color(205,145,158,255)
  454. schema.x11.Pink4 = color(138,99,108,255)
  455. schema.x11.Plum1 = color(255,186,255,255)
  456. schema.x11.Plum2 = color(237,174,237,255)
  457. schema.x11.Plum3 = color(205,150,205,255)
  458. schema.x11.Plum4 = color(138,102,138,255)
  459. schema.x11.Purple1 = color(155,48,255,255)
  460. schema.x11.Purple2 = color(145,43,237,255)
  461. schema.x11.Purple3 = color(124,38,205,255)
  462. schema.x11.Purple4 = color(84,25,138,255)
  463. schema.x11.Red1 = color(255,0,0,255)
  464. schema.x11.Red2 = color(237,0,0,255)
  465. schema.x11.Red3 = color(205,0,0,255)
  466. schema.x11.Red4 = color(138,0,0,255)
  467. schema.x11.RosyBrown1 = color(255,192,192,255)
  468. schema.x11.RosyBrown2 = color(237,179,179,255)
  469. schema.x11.RosyBrown3 = color(205,155,155,255)
  470. schema.x11.RosyBrown4 = color(138,104,104,255)
  471. schema.x11.RoyalBlue1 = color(72,118,255,255)
  472. schema.x11.RoyalBlue2 = color(67,109,237,255)
  473. schema.x11.RoyalBlue3 = color(58,94,205,255)
  474. schema.x11.RoyalBlue4 = color(38,63,138,255)
  475. schema.x11.Salmon1 = color(255,140,104,255)
  476. schema.x11.Salmon2 = color(237,130,98,255)
  477. schema.x11.Salmon3 = color(205,112,84,255)
  478. schema.x11.Salmon4 = color(138,75,57,255)
  479. schema.x11.SeaGreen1 = color(84,255,159,255)
  480. schema.x11.SeaGreen2 = color(77,237,147,255)
  481. schema.x11.SeaGreen3 = color(67,205,127,255)
  482. schema.x11.SeaGreen4 = color(45,138,86,255)
  483. schema.x11.Seashell1 = color(255,244,237,255)
  484. schema.x11.Seashell2 = color(237,228,221,255)
  485. schema.x11.Seashell3 = color(205,196,191,255)
  486. schema.x11.Seashell4 = color(138,133,130,255)
  487. schema.x11.Sienna1 = color(255,130,71,255)
  488. schema.x11.Sienna2 = color(237,121,66,255)
  489. schema.x11.Sienna3 = color(205,104,57,255)
  490. schema.x11.Sienna4 = color(138,71,38,255)
  491. schema.x11.SkyBlue1 = color(135,206,255,255)
  492. schema.x11.SkyBlue2 = color(125,191,237,255)
  493. schema.x11.SkyBlue3 = color(108,165,205,255)
  494. schema.x11.SkyBlue4 = color(73,112,138,255)
  495. schema.x11.SlateBlue1 = color(130,110,255,255)
  496. schema.x11.SlateBlue2 = color(122,103,237,255)
  497. schema.x11.SlateBlue3 = color(104,89,205,255)
  498. schema.x11.SlateBlue4 = color(71,59,138,255)
  499. schema.x11.SlateGray1 = color(197,226,255,255)
  500. schema.x11.SlateGray2 = color(184,211,237,255)
  501. schema.x11.SlateGray3 = color(159,181,205,255)
  502. schema.x11.SlateGray4 = color(108,123,138,255)
  503. schema.x11.Snow1 = color(255,249,249,255)
  504. schema.x11.Snow2 = color(237,232,232,255)
  505. schema.x11.Snow3 = color(205,201,201,255)
  506. schema.x11.Snow4 = color(138,136,136,255)
  507. schema.x11.SpringGreen1 = color(0,255,126,255)
  508. schema.x11.SpringGreen2 = color(0,237,118,255)
  509. schema.x11.SpringGreen3 = color(0,205,102,255)
  510. schema.x11.SpringGreen4 = color(0,138,68,255)
  511. schema.x11.SteelBlue1 = color(99,183,255,255)
  512. schema.x11.SteelBlue2 = color(91,172,237,255)
  513. schema.x11.SteelBlue3 = color(79,147,205,255)
  514. schema.x11.SteelBlue4 = color(53,99,138,255)
  515. schema.x11.Tan1 = color(255,165,79,255)
  516. schema.x11.Tan2 = color(237,154,73,255)
  517. schema.x11.Tan3 = color(205,132,63,255)
  518. schema.x11.Tan4 = color(138,89,43,255)
  519. schema.x11.Thistle1 = color(255,225,255,255)
  520. schema.x11.Thistle2 = color(237,210,237,255)
  521. schema.x11.Thistle3 = color(205,181,205,255)
  522. schema.x11.Thistle4 = color(138,123,138,255)
  523. schema.x11.Tomato1 = color(255,99,71,255)
  524. schema.x11.Tomato2 = color(237,91,66,255)
  525. schema.x11.Tomato3 = color(205,79,57,255)
  526. schema.x11.Tomato4 = color(138,53,38,255)
  527. schema.x11.Turquoise1 = color(0,244,255,255)
  528. schema.x11.Turquoise2 = color(0,228,237,255)
  529. schema.x11.Turquoise3 = color(0,196,205,255)
  530. schema.x11.Turquoise4 = color(0,133,138,255)
  531. schema.x11.VioletRed1 = color(255,62,150,255)
  532. schema.x11.VioletRed2 = color(237,58,140,255)
  533. schema.x11.VioletRed3 = color(205,49,119,255)
  534. schema.x11.VioletRed4 = color(138,33,81,255)
  535. schema.x11.Wheat1 = color(255,230,186,255)
  536. schema.x11.Wheat2 = color(237,216,174,255)
  537. schema.x11.Wheat3 = color(205,186,150,255)
  538. schema.x11.Wheat4 = color(138,125,102,255)
  539. schema.x11.Yellow1 = color(255,255,0,255)
  540. schema.x11.Yellow2 = color(237,237,0,255)
  541. schema.x11.Yellow3 = color(205,205,0,255)
  542. schema.x11.Yellow4 = color(138,138,0,255)
  543. schema.x11.Gray0 = color(189,189,189,255)
  544. schema.x11.Green0 = color(0,255,0,255)
  545. schema.x11.Grey0 = color(189,189,189,255)
  546. schema.x11.Maroon0 = color(175,48,95,255)
  547. schema.x11.Purple0 = color(160,31,239,255)
  548.  
  549. for a, b in pairs(schema.x11) do
  550. colors["x11-" .. string.lower(a)] = b
  551. end
  552.  
  553. -- Generator
  554.  
  555. local domains = {
  556. { -- The default color
  557. d = "", -- Subdomain
  558. w = true, -- Grayscale generate subdomains?
  559. c = function(b) return b end -- Returns color
  560. },
  561. {
  562. d = "slightly-dark-",
  563. w = false,
  564. c = function(b) return b:mix(color(65, 255), 0.5) end
  565. },
  566. {
  567. d = "dark-",
  568. w = false,
  569. c = function(b) return b:mix(color(0, 255), 0.5) end
  570. },
  571. {
  572. d = "slightly-light-",
  573. w = false,
  574. c = function(b) return b:mix(color(190, 255), 0.5) end
  575. },
  576. {
  577. d = "light-",
  578. w = false,
  579. c = function(b) return b:mix(color(255, 255), 0.5) end
  580. },
  581. {
  582. d = "middle-",
  583. w = false,
  584. c = function(b) return b:mix(color(127, 255), 0.5) end
  585. },
  586. {
  587. d = "reddish-",
  588. w = true,
  589. c = function(b) return b:mix(color(255, 0, 0, 255), 0.6) end
  590. },
  591. {
  592. d = "greenish-",
  593. w = true,
  594. c = function(b) return b:mix(color(0, 255, 0, 255), 0.6) end
  595. },
  596. {
  597. d = "blueish-",
  598. w = true,
  599. c = function(b) return b:mix(color(0, 0, 255, 255), 0.6) end
  600. },
  601. {
  602. d = "cyanish-",
  603. w = true,
  604. c = function(b) return b:mix(color(0, 255, 255, 255), 0.6) end
  605. },
  606. {
  607. d = "magentish-",
  608. w = true,
  609. c = function(b) return b:mix(color(255, 0, 255, 255), 0.6) end
  610. },
  611. {
  612. d = "yellowish-",
  613. w = true,
  614. c = function(b) return b:mix(color(255, 255, 0, 255), 0.6) end
  615. },
  616. {
  617. d = "slightly-reddish-",
  618. w = true,
  619. c = function(b) return b:mix(color(255, 0, 0, 255), 0.7) end
  620. },
  621. {
  622. d = "slightly-greenish-",
  623. w = true,
  624. c = function(b) return b:mix(color(0, 255, 0, 255), 0.7) end
  625. },
  626. {
  627. d = "slightly-blueish-",
  628. w = true,
  629. c = function(b) return b:mix(color(0, 0, 255, 255), 0.7) end
  630. },
  631. {
  632. d = "reduced-",
  633. w = false,
  634. c = function(b) return color(math.max(b.r-90,0), math.max(b.g-90,0), math.max(b.b-90,0), 255) end
  635. },
  636. {
  637. d = "saturated-",
  638. w = false,
  639. c = function(b) return color(b.r*b.r/255, b.g*b.g/255, b.b*b.b/255) end
  640. },
  641. {
  642. d = "over-saturated-",
  643. w = false,
  644. c = function(b) return color(b.r*b.r*b.r/65025, b.g*b.g*b.g/65025, b.b*b.b*b.b/65025) end
  645. },
  646. }
  647.  
  648. -- Generate subdomains.
  649. for a, b in pairs(colors1) do
  650. for c, d in ipairs (domains) do
  651. colors[d.d .. a] = d.c(b)
  652. end
  653.  
  654.  
  655. for i = 5, 95, 5 do
  656. colors[a .. "-" .. i] = b:mix(color(0, 255), i/100)
  657. end
  658. end
  659.  
  660. -- Grayscale
  661. for a, b in ipairs (domains) do
  662. if b.w then
  663. colors[b.d .. "white"] = b.c(color(255, 255))
  664. colors[b.d .. "black"] = b.c(color(0, 255))
  665. colors[b.d .. "grey"] = b.c(color(128, 255))
  666. colors[b.d .. "gray"] = b.c(color(128, 255))
  667.  
  668. for i = 5, 95, 5 do
  669. colors[b.d .. "white-" .. i] = b.c(color(2.55 * i, 255))
  670. end
  671. end
  672. end
  673. end
  674.  
  675. -- Initialise
  676.  
  677. --[[
  678.  
  679. Hex() -> Color() -> color()
  680.  
  681. ]]
  682.  
  683. Hex = function(l, alpha)
  684. if not (type(l) == "string") then
  685. assert(false, "bad argument #1 to 'Hex' (string expected, got ".. type(l) ..")")
  686. end
  687.  
  688. if #l == 6 then
  689. return Color(tonumber(l, 16))
  690. elseif #l == 3 then
  691. l = string.rep(string.sub(l, 1, 1), 2) +
  692. string.rep(string.sub(l, 2, 2), 2) +
  693. string.rep(string.sub(l, 3, 3), 2)
  694. elseif #l == 2 then
  695. l = string.rep(l, 3)
  696. elseif #l == 1 then
  697. l = string.rep(l, 6)
  698. end
  699.  
  700. return Color(tonumber(l, 16), alpha)
  701. end
  702.  
  703. --[[
  704.  
  705. Hue() -> color()
  706.  
  707. ]]
  708.  
  709. Hue = function(val, alpha)
  710. local r, g, b = 0, 0, 0
  711.  
  712. if val > 360 then
  713. val = val - math.floor(val / 360) * 360
  714. elseif val < 0 then
  715. val = val + math.floor(val / 360) * 360
  716. end
  717.  
  718. val = math.floor(val)
  719.  
  720. if val <= 60 then
  721. r = 255
  722. g = (val/60)*255
  723. b = 0
  724. elseif val <= 120 then
  725. r = 255 - (val-60)/60 * 255
  726. g = 255
  727. b = 0
  728. elseif val <= 180 then
  729. r = 0
  730. g = 255
  731. b = ((val-120)/60)*255
  732. elseif val <= 240 then
  733. r = 0
  734. g = 255 - (val-180)/60 * 255
  735. b = 255
  736. elseif val <= 300 then
  737. r = ((val-240)/60)*255
  738. g = 0
  739. b = 255
  740. else
  741. r = 255
  742. g = 0
  743. b = 255 - (val-300)/60 * 255
  744. end
  745.  
  746. return color(r, g, b, alpha or 255)
  747. end
  748.  
  749. --[[
  750.  
  751. Hsl() -> color()
  752.  
  753. ]]
  754.  
  755. Hsl = function(h, s, l, a)
  756. return Color{
  757. hue = h,
  758. saturation = s,
  759. lightness = l,
  760. alpha = a
  761. }
  762. end
  763.  
  764. --[[
  765.  
  766. Color(col, alpha) -> ... -> color()
  767.  
  768. ]]
  769.  
  770. Color = function(s, alpha)
  771. local c = color(0, 255)
  772.  
  773. -- Define Color
  774. if type(s) == "string" then
  775. s = string.lower(s)
  776.  
  777. -- RANDOM COLOR
  778. if s == "random" then
  779. return RandomColor()
  780. elseif (s == "random-grey") or (s == "random-gray") then
  781. c = color(math.random(255))
  782. elseif (s == "random-hue") then
  783. c = Hue(math.random(255))
  784.  
  785. -- SPECIAL
  786. elseif s == "transparent" then
  787. return color(0, 0)
  788.  
  789. -- NORMAL
  790. -- Hue
  791. elseif string.sub(s, 1, 4) == "hue-" then
  792. c = Hue(tonumber(string.sub(s, 5, #s)))
  793. -- Name
  794. elseif colors[s] then
  795. c = color(colors[s].r, colors[s].g, colors[s].b)
  796. -- Hex
  797. elseif string.sub(s, 1, 1) == "#" and #s > 1 then
  798. c = Hex(string.sub(s, 2, #s))
  799. end
  800. elseif type(s) == "table" then
  801. local methods = {
  802. -- Generate color by origin or hue
  803. {
  804. name = "origin",
  805. f = function(q)
  806. return Color(q)
  807. end
  808. },
  809. {
  810. name = "hue",
  811. f = function(q)
  812. return Hue(q)
  813. end
  814. },
  815.  
  816. -- Edit the color
  817. {
  818. name = "shade",
  819. f = function(q)
  820. for a, b in pairs{
  821. -- Visibility
  822. ["light"] = function()
  823. return c:mix(color(255, 255), 0.5)
  824. end,
  825. ["dark"] = function()
  826. return c:mix(color(0, 255), 0.5)
  827. end,
  828. ["slightly-dark"] = function()
  829. return c:mix(color(65, 255), 0.5)
  830. end,
  831. ["slightly-light"] = function()
  832. return c:mix(color(190, 255), 0.5)
  833. end,
  834. ["middle"] = function()
  835. return c:mix(color(127, 255), 0.5)
  836. end,
  837. ["saturated"] = function()
  838. return color(c.r*c.r/255, c.g*c.g/255, c.b*c.b/255)
  839. end,
  840.  
  841. -- Shading
  842. ["reddish"] = function()
  843. return c:mix(color(255, 0, 0), 0.6)
  844. end,
  845. ["greenish"] = function()
  846. return c:mix(color(0, 255, 0), 0.6)
  847. end,
  848. ["blueish"] = function()
  849. return c:mix(color(0, 0, 255), 0.6)
  850. end,
  851. ["magentish"] = function()
  852. return c:mix(color(255, 0, 255), 0.6)
  853. end,
  854. ["yellowish"] = function()
  855. return c:mix(color(255, 255, 0), 0.6)
  856. end,
  857. ["cyanish"] = function()
  858. return c:mix(color(0, 255, 255), 0.6)
  859. end,
  860. ["slightly-reddish"] = function()
  861. return c:mix(color(255, 0, 0), 0.7)
  862. end,
  863. ["slightly-greenish"] = function()
  864. return c:mix(color(0, 255, 0), 0.7)
  865. end,
  866. ["slightly-blueish"] = function()
  867. return c:mix(color(0, 0, 255), 0.7)
  868. end,
  869. } do
  870. if q == a then
  871. return b()
  872. end
  873. end
  874.  
  875. end
  876. },
  877. {
  878. name = "saturation",
  879. f = function(q)
  880. local chroma = q
  881. end
  882. },
  883. {
  884. name = "lightness",
  885. f = function(q)
  886. --return Hue(q)
  887. end
  888. },
  889.  
  890. -- Switch color
  891. {
  892. name = "desaturate",
  893. f = function(q)
  894. for a, b in pairs{
  895. ["avg"] = function()
  896. return color((c.r+c.g+c.b)/3, 255)
  897. end,
  898. ["hsv"] = function()
  899. return color(math.max(c.r, c.g, c.b), 255)
  900. end,
  901. ["hsl"] = function()
  902. return color((math.max(c.r, c.g, c.b) + math.min(c.r, c.g, c.b))*.5, 255)
  903. end,
  904. ["min"] = function()
  905. return color(math.min(c.r, c.g, c.b), 255)
  906. end,
  907. ["lum"] = function()
  908. return color(c.r*.22 + c.g*.72 + c.b*.06, 255)
  909. end,
  910. ["red"] = function()
  911. return color(c.r, 255)
  912. end,
  913. ["green"] = function()
  914. return color(c.g, 255)
  915. end,
  916. ["blue"] = function()
  917. return color(c.b, 255)
  918. end,
  919. } do
  920. if q == a then
  921. return b()
  922. end
  923. end
  924. end
  925. },
  926. {
  927. name = "invert",
  928. f = function(q)
  929. if q then
  930. return color(255-c.r, 255-c.g, 255-c.b, 255)
  931. end
  932. end
  933. },
  934. {
  935. name = "filter",
  936. f = function(q)
  937. local m = c
  938. if q.r == false then
  939. m.r = 0
  940. end if q.g == false then
  941. m.g = 0
  942. end if q.b == false then
  943. m.b = 0
  944. end
  945. return m
  946. end
  947. },
  948.  
  949. -- Alpha
  950. {
  951. name = "alpha",
  952. f = function(q)
  953. return color(c.r, c.g, c.b, q)
  954. end
  955. },
  956. }
  957.  
  958. for d, e in ipairs(methods) do
  959. for a, b in pairs(s) do
  960. if a == e.name then
  961. c = e.f(b) or c
  962. end
  963. end
  964. end
  965. elseif type(s) == "number" then
  966. local b = s%256
  967. local g = ((s - b)/256)%256
  968. local r = ((s - g - b)/256^2)
  969.  
  970. c = color(r, g, b)
  971. elseif type(s) == "userdata" then -- s is already a color
  972. c = color(s.r, s.g, s.b, alpha or 255)
  973. elseif type(s) == "nil" then
  974. --if s then
  975. return RandomColor()
  976. --end
  977. else
  978. assert(false, "bad argument #1 to 'Color' (string expected, got ".. type(s) ..")")
  979. end
  980.  
  981. -- Set transparency
  982. if type(alpha) == "number" then
  983. c.a = alpha
  984. elseif type(alpha) == "string" then
  985. local m = {
  986. ["slightly-opaque"] = 225,
  987. ["slightly-visible"] = 50
  988. }
  989. c.a = m[alpha]
  990. elseif type(alpha) == "boolean" then
  991. if alpha then
  992. c.a = 255
  993. else
  994. c.a = 0
  995. end
  996. elseif type(s) == "table" then
  997. elseif alpha == nil then
  998. -- ignore
  999. else
  1000. assert(false, "bad argument #2 to 'Color' (number expected, got ".. type(alpha) ..")")
  1001. end
  1002.  
  1003. return c
  1004. end
  1005.  
  1006. --[[
  1007.  
  1008. Colors(col1, col2, mode) -> color()
  1009.  
  1010. ]]
  1011.  
  1012. Colors = function(c1, c2, mode)
  1013. local modes = {
  1014. ["dif"] = function()
  1015. return color(math.abs(c1.r-c2.r), math.abs(c1.g-c2.g), math.abs(c1.b-c2.b))
  1016. end,
  1017. ["avg"] = function()
  1018. return color((c1.r+c2.r)/2, (c1.g+c2.g)/2, (c1.b+c2.b)/2)
  1019. end,
  1020. ["min"] = function()
  1021. return color(math.min(c1.r, c2.r), math.min(c1.g, c2.g), math.min(c1.b, c2.b))
  1022. end,
  1023. ["max"] = function()
  1024. return color(math.max(c1.r, c2.r), math.max(c1.g, c2.g), math.max(c1.b, c2.b))
  1025. end,
  1026. ["sqrt"] = function()
  1027. return color(math.sqrt(c1.r^2 + c2.r^2)/math.sqrt(2),
  1028. math.sqrt(c1.g^2 + c2.g^2)/math.sqrt(2),
  1029. math.sqrt(c1.b^2 + c2.b^2)/math.sqrt(2)
  1030. )
  1031. end,
  1032. ["multiply"] = function()
  1033. return color(c1.r*c2.r/255, c1.g*c2.g/255, c1.b*c2.b/255)
  1034. end,
  1035. ["screen"] = function()
  1036. return color(255-(255-c1.r)*(255-c2.r)/255,
  1037. 255-(255-c1.g)*(255-c2.g)/255,
  1038. 255-(255-c1.b)*(255-c2.b)/255
  1039. )
  1040. end,
  1041. }
  1042.  
  1043. return modes[string.lower(mode)]()
  1044. end
  1045.  
  1046. -- Fast access implementations
  1047.  
  1048. Fill = function(s, a) fill(Color(s, a)) end
  1049. Stroke = function(s, a) stroke(Color(s, a)) end
  1050. Tint = function(s, a) tint(Color(s, a)) end
  1051. Background = function(s, a) background(Color(s, a)) end
  1052. RandomColor = function(a) return color(math.random(255), math.random(255), math.random(255), a or 255) end
  1053.  
  1054.  
  1055. --# Main
  1056. -- colors1
  1057.  
  1058. function setup()
  1059. displayMode(FULLSCREEN)
  1060. genIcon()
  1061.  
  1062. parameter.action("Clear Data", function() clearLocalData() sizeChanged() end)
  1063.  
  1064. startMessage = "Tap a color to see it's details"
  1065. selectedColor = startMessage
  1066. latestTouch = vec2(WIDTH*.5, HEIGHT*.5)
  1067. sizeChanged()
  1068.  
  1069. --[[parameter.number("HUE", 0, 360)
  1070. parameter.number("SAT", 0, 1)
  1071. parameter.number("LIT", 0, 1)]]
  1072. end
  1073.  
  1074. function sizeChanged(w, h)
  1075. local min = math.min(WIDTH, HEIGHT)
  1076. colorBullets = {}
  1077.  
  1078. local function width(i, radius)
  1079. return WIDTH*.5 + math.cos(i*math.pi/180) * radius
  1080. end
  1081.  
  1082. local function height(i, radius)
  1083. return HEIGHT*.5 + math.sin(i*math.pi/180) * radius
  1084. end
  1085.  
  1086. local function add(degree, radius, col)
  1087. table.insert(colorBullets, ColorBullet(width(degree, radius), height(degree, radius), col))
  1088. end
  1089.  
  1090. -- Hue
  1091. for i = 0, 360 do
  1092. add(i, min*.5-20, "hue-" .. i)
  1093. end
  1094.  
  1095. -- All other colors
  1096. local v = {}
  1097. for a, b in pairs(colors) do
  1098. table.insert(v, {a, b})
  1099. end
  1100.  
  1101. table.sort(v, function(a, b)
  1102. local function getHue(c)
  1103. local max, min = math.max(c.r, c.g, c.b), math.min(c.r, c.g, c.b)
  1104. local i = 1 / ( max - min )
  1105.  
  1106. if c.r == max then
  1107. return (c.g - c.b) * i
  1108. elseif c.g == max then
  1109. return (c.b - c.r) * i
  1110. else -- b
  1111. return (c.r - c.g) * i
  1112. end
  1113. end
  1114.  
  1115. --return a[1] < b[1] -- strings, alphabetically
  1116. --return (a[2].r - b[2].r) > 0 and (a[2].g - b[2].g) > 0 and (a[2].b - b[2].b) > 0
  1117. return a[2].r + a[2].g + a[2].b > b[2].r + b[2].g + b[2].b -- ANAZING
  1118. --return getHue(a[2]) > getHue(b[2])
  1119. end)
  1120.  
  1121. for a, b in ipairs(v) do
  1122. if a > 360 * 3 then
  1123. add(3*a-360*3, min*.5-40 - math.floor((3*a-360*3+1)/360)*15, b[1])
  1124. else
  1125. add(2*a, min*.5-40 - math.floor((2*a+1)/360)*15, b[1])
  1126. end
  1127. end
  1128.  
  1129. placeholders = {}
  1130. for i = 1, 15 do
  1131. table.insert(placeholders, Placeholder(WIDTH-25, HEIGHT-50*i+25, i .. "r"))
  1132. table.insert(placeholders, Placeholder(WIDTH-75, HEIGHT-50*i+25, i .. "l"))
  1133. end
  1134. end
  1135.  
  1136. function genIcon()
  1137. local m = image(320, 320)
  1138. setContext(m)
  1139. -- Background and Circle
  1140. Background(0)
  1141. for i = 1, 360 do
  1142. Fill(Hue(i, 255))
  1143. ellipse(160 + math.cos(i*math.pi/180) * 140, 160 + math.sin(i*math.pi/180) * 140, 15)
  1144. end
  1145.  
  1146. -- Text
  1147. fontSize(80)
  1148. font("MarkerFelt-Thin")
  1149.  
  1150. local w = {
  1151. {
  1152. l = "C",
  1153. c = "darkviolet"
  1154. },
  1155. {
  1156. l = "o",
  1157. c = "red"
  1158. },
  1159. {
  1160. l = "l",
  1161. c = "neon-green"
  1162. },
  1163. {
  1164. l = "o",
  1165. c = "pink"
  1166. },
  1167. {
  1168. l = "r",
  1169. c = "skyblue"
  1170. },
  1171. {
  1172. l = "s",
  1173. c = "forestgreen"
  1174. },
  1175. }
  1176.  
  1177. local p = ""
  1178. for a, b in ipairs(w) do p = p .. b.l end
  1179. local q, _ = textSize(p)
  1180.  
  1181. local n = 0
  1182. for a, b in ipairs(w) do
  1183. local n1, _ = textSize(b.l)
  1184.  
  1185. Fill(b.c)
  1186. text(b.l, 160 - q*.5 + n + n1*.5, 160)
  1187. n = n + n1
  1188. end
  1189.  
  1190. -- Version
  1191. Fill("white-80")
  1192. font("Futura-Medium")
  1193. fontSize(40)
  1194. text("v8", 290, 290)
  1195.  
  1196. -- Exit
  1197. setContext()
  1198. saveImage("Project:Icon", m)
  1199. end
  1200.  
  1201. function draw()
  1202. Background("black")
  1203. resetStyle()
  1204.  
  1205. -- Logo
  1206. sprite("Project:Icon", WIDTH*.5, HEIGHT*.5 + 64, 128)
  1207.  
  1208. -- Selected Color
  1209. Fill("white-80")
  1210. font("ArialRoundedMTBold")
  1211. fontSize(20)
  1212. text(selectedColor, WIDTH*.5, HEIGHT*.5-20)
  1213.  
  1214. resetStyle()
  1215. for a, b in ipairs(colorBullets) do
  1216. b:draw()
  1217. end
  1218. for a, b in ipairs(placeholders) do
  1219. b:draw()
  1220. end
  1221.  
  1222. --[[Fill{
  1223. hue = HUE,
  1224. saturation = SAT,
  1225. lightness = LIT
  1226. }
  1227. ellipse(600, 600, 800)]]
  1228.  
  1229. -- Latest Touch
  1230. resetStyle()
  1231. Fill("transparent")
  1232. strokeWidth(5-((ElapsedTime*60)%70)/70*5)
  1233. Stroke("white", 255-((ElapsedTime*60)%70)/70*255)
  1234. ellipse(latestTouch.x, latestTouch.y, 20+(ElapsedTime*60)%70)
  1235. fill(math.sin(ElapsedTime*6)*255, 255)
  1236. strokeWidth(0)
  1237. ellipse(latestTouch.x, latestTouch.y, 5)
  1238. end
  1239.  
  1240. function touched(t)
  1241. for a, b in ipairs(placeholders) do
  1242. b:touched(t)
  1243. end
  1244.  
  1245. selectedColor = "No Color"
  1246. latestTouch = vec2(t.pos.x, t.pos.y)
  1247. for a, b in ipairs(colorBullets) do
  1248. b:touched(t)
  1249. end
  1250. end
  1251.  
  1252.  
  1253. ColorBullet = class()
  1254.  
  1255. function ColorBullet:init(x, y, col)
  1256. self.pos = vec2(x, y)
  1257. self.color = col
  1258. end
  1259.  
  1260. function ColorBullet:draw()
  1261. strokeWidth(0)
  1262. Fill(self.color)
  1263. if selectedColor == self.color and math.floor(ElapsedTime*4)%2 == 1 then
  1264. Fill("black")
  1265. end
  1266.  
  1267. if selectedColor == self.color then
  1268. ellipse(self.pos.x, self.pos.y, 20)
  1269. else
  1270. ellipse(self.pos.x, self.pos.y, 15)
  1271. end
  1272. end
  1273.  
  1274. function ColorBullet:touched(t)
  1275. if self:isTouched(t) then
  1276. selectedColor = self.color
  1277. end
  1278. end
  1279.  
  1280. function ColorBullet:isTouched(t)
  1281. if (self.pos.x - t.pos.x)^2 + (self.pos.y - t.pos.y)^2 < 7.5^2 then
  1282. return true
  1283. end
  1284. return false
  1285. end
  1286.  
  1287. Placeholder = class()
  1288.  
  1289. function Placeholder:init(x, y, id)
  1290. self.pos = vec2(x, y)
  1291. self.id = id
  1292. self.color = ""
  1293.  
  1294. local c = readLocalData("col_" .. self.id)
  1295.  
  1296. if c then
  1297. self.color = c
  1298. else
  1299. self.color = "white-30"
  1300. end
  1301. end
  1302.  
  1303. function Placeholder:draw()
  1304. strokeWidth(0)
  1305. Fill(self.color)
  1306. ellipse(self.pos.x, self.pos.y, 35)
  1307. end
  1308.  
  1309. function Placeholder:touched(t)
  1310. if t.state ~= BEGAN then
  1311. return
  1312. end
  1313.  
  1314. if self:isTouched(t) and selectedColor ~= "No Color" and selectedColor ~= startMessage then
  1315. local k = Color(selectedColor)
  1316. self.color = selectedColor
  1317. saveLocalData("col_" .. self.id, self.color)
  1318. elseif self:isTouched(t) then
  1319. alert("The color you selected is Color('" .. self.color .. "')", "Color")
  1320. end
  1321. end
  1322.  
  1323. function Placeholder:isTouched(t)
  1324. if (self.pos.x - t.pos.x)^2 + (self.pos.y - t.pos.y)^2 < 30^2 then
  1325. return true
  1326. end
  1327. return false
  1328. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement