Browse Source

col/palette

Inderjit Gill 2 months ago
parent
commit
db77bb8f42

+ 20
- 8
core/src/colour.rs View File

@@ -28,6 +28,8 @@ use crate::mathutil;
28 28
 use crate::packable::{Mule, Packable};
29 29
 use crate::result::Result;
30 30
 
31
+use crate::colour_palettes::COLOUR_PALETTES;
32
+
31 33
 use std;
32 34
 use std::fmt;
33 35
 
@@ -206,7 +208,6 @@ impl fmt::Display for Colour {
206 208
     }
207 209
 }
208 210
 
209
-
210 211
 fn normalised_colour_from_hex_string(hex_component: &str) -> Result<f32> {
211 212
     let value = i32::from_str_radix(hex_component, 16)?;
212 213
     Ok(value as f32 / 255.0)
@@ -223,17 +224,28 @@ impl Colour {
223 224
         }
224 225
     }
225 226
 
227
+    // return the 5 colour palette at the given index
228
+    pub fn palette(index: usize) -> Result<Vec<Colour>> {
229
+        Ok(vec![
230
+            Colour::from_rgb_hex(COLOUR_PALETTES[index][0])?,
231
+            Colour::from_rgb_hex(COLOUR_PALETTES[index][1])?,
232
+            Colour::from_rgb_hex(COLOUR_PALETTES[index][2])?,
233
+            Colour::from_rgb_hex(COLOUR_PALETTES[index][3])?,
234
+            Colour::from_rgb_hex(COLOUR_PALETTES[index][4])?,
235
+        ])
236
+    }
237
+
238
+    // hex in the form: "ff00ff"
226 239
     pub fn from_rgb_hex(hex: &str) -> Result<Self> {
227
-        // hex in the form: "#ff00ff"
228
-        if hex.len() != 7 {
229
-            error!("Colour::from_rgb_hex expects hex in form #rrggbb, actual: {}", hex);
240
+        if hex.len() != 6 {
241
+            error!("Colour::from_rgb_hex expects input as 6 hex digits, actual: {}", hex);
230 242
             return Err(Error::Colour)
231 243
         }
232 244
 
233 245
         Ok(Colour::new(ColourFormat::Rgb,
234
-                       normalised_colour_from_hex_string(&hex[1..3])?,
235
-                       normalised_colour_from_hex_string(&hex[3..5])?,
236
-                       normalised_colour_from_hex_string(&hex[5..])?,
246
+                       normalised_colour_from_hex_string(&hex[0..2])?,
247
+                       normalised_colour_from_hex_string(&hex[2..4])?,
248
+                       normalised_colour_from_hex_string(&hex[4..])?,
237 249
                        1.0))
238 250
     }
239 251
 
@@ -1289,7 +1301,7 @@ mod tests {
1289 1301
 
1290 1302
     #[test]
1291 1303
     fn test_hex_colour_parsing() {
1292
-        assert_hex_colour("#ff00ff", ColourFormat::Rgb, 1.0, 0.0, 1.0, 1.0);
1304
+        assert_hex_colour("ff00ff", ColourFormat::Rgb, 1.0, 0.0, 1.0, 1.0);
1293 1305
     }
1294 1306
 
1295 1307
 }

+ 219
- 0
core/src/colour_palettes.rs View File

@@ -0,0 +1,219 @@
1
+// Copyright (C) 2019 Inderjit Gill
2
+
3
+// This program is free software: you can redistribute it and/or modify
4
+// it under the terms of the GNU General Public License as published by
5
+// the Free Software Foundation, either version 3 of the License, or
6
+// (at your option) any later version.
7
+
8
+// This program is distributed in the hope that it will be useful,
9
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+// GNU General Public License for more details.
12
+
13
+// You should have received a copy of the GNU General Public License
14
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
+
16
+// top colour palettes from http://colourlovers.com/
17
+//
18
+pub const COLOUR_PALETTES: &[&[&'static str]] = &[
19
+    &["69d2e7","a7dbd8","e0e4cc","f38630","fa6900"],
20
+    &["fe4365","fc9d9a","f9cdad","c8c8a9","83af9b"],
21
+    &["ecd078","d95b43","c02942","542437","53777a"],
22
+    &["556270","4ecdc4","c7f464","ff6b6b","c44d58"],
23
+    &["774f38","e08e79","f1d4af","ece5ce","c5e0dc"],
24
+    &["e8ddcb","cdb380","036564","033649","031634"],
25
+    &["490a3d","bd1550","e97f02","f8ca00","8a9b0f"],
26
+    &["594f4f","547980","45ada8","9de0ad","e5fcc2"],
27
+    &["00a0b0","6a4a3c","cc333f","eb6841","edc951"],
28
+    &["e94e77","d68189","c6a49a","c6e5d9","f4ead5"],
29
+    &["3fb8af","7fc7af","dad8a7","ff9e9d","ff3d7f"],
30
+    &["d9ceb2","948c75","d5ded9","7a6a53","99b2b7"],
31
+    &["ffffff","cbe86b","f2e9e1","1c140d","cbe86b"],
32
+    &["efffcd","dce9be","555152","2e2633","99173c"],
33
+    &["343838","005f6b","008c9e","00b4cc","00dffc"],
34
+    &["413e4a","73626e","b38184","f0b49e","f7e4be"],
35
+    &["ff4e50","fc913a","f9d423","ede574","e1f5c4"],
36
+    &["99b898","fecea8","ff847c","e84a5f","2a363b"],
37
+    &["655643","80bca3","f6f7bd","e6ac27","bf4d28"],
38
+    &["00a8c6","40c0cb","f9f2e7","aee239","8fbe00"],
39
+    &["351330","424254","64908a","e8caa4","cc2a41"],
40
+    &["554236","f77825","d3ce3d","f1efa5","60b99a"],
41
+    &["5d4157","838689","a8caba","cad7b2","ebe3aa"],
42
+    &["8c2318","5e8c6a","88a65e","bfb35a","f2c45a"],
43
+    &["fad089","ff9c5b","f5634a","ed303c","3b8183"],
44
+    &["ff4242","f4fad2","d4ee5e","e1edb9","f0f2eb"],
45
+    &["f8b195","f67280","c06c84","6c5b7b","355c7d"],
46
+    &["d1e751","ffffff","000000","4dbce9","26ade4"],
47
+    &["1b676b","519548","88c425","bef202","eafde6"],
48
+    &["5e412f","fcebb6","78c0a8","f07818","f0a830"],
49
+    &["bcbdac","cfbe27","f27435","f02475","3b2d38"],
50
+    &["452632","91204d","e4844a","e8bf56","e2f7ce"],
51
+    &["eee6ab","c5bc8e","696758","45484b","36393b"],
52
+    &["f0d8a8","3d1c00","86b8b1","f2d694","fa2a00"],
53
+    &["2a044a","0b2e59","0d6759","7ab317","a0c55f"],
54
+    &["f04155","ff823a","f2f26f","fff7bd","95cfb7"],
55
+    &["b9d7d9","668284","2a2829","493736","7b3b3b"],
56
+    &["bbbb88","ccc68d","eedd99","eec290","eeaa88"],
57
+    &["b3cc57","ecf081","ffbe40","ef746f","ab3e5b"],
58
+    &["a3a948","edb92e","f85931","ce1836","009989"],
59
+    &["300030","480048","601848","c04848","f07241"],
60
+    &["67917a","170409","b8af03","ccbf82","e33258"],
61
+    &["aab3ab","c4cbb7","ebefc9","eee0b7","e8caaf"],
62
+    &["e8d5b7","0e2430","fc3a51","f5b349","e8d5b9"],
63
+    &["ab526b","bca297","c5ceae","f0e2a4","f4ebc3"],
64
+    &["607848","789048","c0d860","f0f0d8","604848"],
65
+    &["b6d8c0","c8d9bf","dadabd","ecdbbc","fedcba"],
66
+    &["a8e6ce","dcedc2","ffd3b5","ffaaa6","ff8c94"],
67
+    &["3e4147","fffedf","dfba69","5a2e2e","2a2c31"],
68
+    &["fc354c","29221f","13747d","0abfbc","fcf7c5"],
69
+    &["cc0c39","e6781e","c8cf02","f8fcc1","1693a7"],
70
+    &["1c2130","028f76","b3e099","ffeaad","d14334"],
71
+    &["a7c5bd","e5ddcb","eb7b59","cf4647","524656"],
72
+    &["dad6ca","1bb0ce","4f8699","6a5e72","563444"],
73
+    &["5c323e","a82743","e15e32","c0d23e","e5f04c"],
74
+    &["edebe6","d6e1c7","94c7b6","403b33","d3643b"],
75
+    &["fdf1cc","c6d6b8","987f69","e3ad40","fcd036"],
76
+    &["230f2b","f21d41","ebebbc","bce3c5","82b3ae"],
77
+    &["b9d3b0","81bda4","b28774","f88f79","f6aa93"],
78
+    &["3a111c","574951","83988e","bcdea5","e6f9bc"],
79
+    &["5e3929","cd8c52","b7d1a3","dee8be","fcf7d3"],
80
+    &["1c0113","6b0103","a30006","c21a01","f03c02"],
81
+    &["000000","9f111b","b11623","292c37","cccccc"],
82
+    &["382f32","ffeaf2","fcd9e5","fbc5d8","f1396d"],
83
+    &["e3dfba","c8d6bf","93ccc6","6cbdb5","1a1f1e"],
84
+    &["f6f6f6","e8e8e8","333333","990100","b90504"],
85
+    &["1b325f","9cc4e4","e9f2f9","3a89c9","f26c4f"],
86
+    &["a1dbb2","fee5ad","faca66","f7a541","f45d4c"],
87
+    &["c1b398","605951","fbeec2","61a6ab","accec0"],
88
+    &["5e9fa3","dcd1b4","fab87f","f87e7b","b05574"],
89
+    &["951f2b","f5f4d7","e0dfb1","a5a36c","535233"],
90
+    &["8dccad","988864","fea6a2","f9d6ac","ffe9af"],
91
+    &["2d2d29","215a6d","3ca2a2","92c7a3","dfece6"],
92
+    &["413d3d","040004","c8ff00","fa023c","4b000f"],
93
+    &["eff3cd","b2d5ba","61ada0","248f8d","605063"],
94
+    &["ffefd3","fffee4","d0ecea","9fd6d2","8b7a5e"],
95
+    &["cfffdd","b4dec1","5c5863","a85163","ff1f4c"],
96
+    &["9dc9ac","fffec7","f56218","ff9d2e","919167"],
97
+    &["4e395d","827085","8ebe94","ccfc8e","dc5b3e"],
98
+    &["a8a7a7","cc527a","e8175d","474747","363636"],
99
+    &["f8edd1","d88a8a","474843","9d9d93","c5cfc6"],
100
+    &["046d8b","309292","2fb8ac","93a42a","ecbe13"],
101
+    &["f38a8a","55443d","a0cab5","cde9ca","f1edd0"],
102
+    &["a70267","f10c49","fb6b41","f6d86b","339194"],
103
+    &["ff003c","ff8a00","fabe28","88c100","00c176"],
104
+    &["ffedbf","f7803c","f54828","2e0d23","f8e4c1"],
105
+    &["4e4d4a","353432","94ba65","2790b0","2b4e72"],
106
+    &["0ca5b0","4e3f30","fefeeb","f8f4e4","a5b3aa"],
107
+    &["4d3b3b","de6262","ffb88c","ffd0b3","f5e0d3"],
108
+    &["fffbb7","a6f6af","66b6ab","5b7c8d","4f2958"],
109
+    &["edf6ee","d1c089","b3204d","412e28","151101"],
110
+    &["9d7e79","ccac95","9a947c","748b83","5b756c"],
111
+    &["fcfef5","e9ffe1","cdcfb7","d6e6c3","fafbe3"],
112
+    &["9cddc8","bfd8ad","ddd9ab","f7af63","633d2e"],
113
+    &["30261c","403831","36544f","1f5f61","0b8185"],
114
+    &["aaff00","ffaa00","ff00aa","aa00ff","00aaff"],
115
+    &["d1313d","e5625c","f9bf76","8eb2c5","615375"],
116
+    &["ffe181","eee9e5","fad3b2","ffba7f","ff9c97"],
117
+    &["73c8a9","dee1b6","e1b866","bd5532","373b44"],
118
+    &["805841","dcf7f3","fffcdd","ffd8d8","f5a2a2"],
119
+    &["379f7a","78ae62","bbb749","e0fbac","1f1c0d"],
120
+    &["caff42","ebf7f8","d0e0eb","88abc2","49708a"],
121
+    &["c2412d","d1aa34","a7a844","a46583","5a1e4a"],
122
+    &["75616b","bfcff7","dce4f7","f8f3bf","d34017"],
123
+    &["111625","341931","571b3c","7a1e48","9d2053"],
124
+    &["82837e","94b053","bdeb07","bffa37","e0e0e0"],
125
+    &["7e5686","a5aad9","e8f9a2","f8a13f","ba3c3d"],
126
+    &["312736","d4838f","d6abb1","d9d9d9","c4ffeb"],
127
+    &["395a4f","432330","853c43","f25c5e","ffa566"],
128
+    &["fde6bd","a1c5ab","f4dd51","d11e48","632f53"],
129
+    &["84b295","eccf8d","bb8138","ac2005","2c1507"],
130
+    &["058789","503d2e","d54b1a","e3a72f","f0ecc9"],
131
+    &["6da67a","77b885","86c28b","859987","4a4857"],
132
+    &["bed6c7","adc0b4","8a7e66","a79b83","bbb2a1"],
133
+    &["261c21","6e1e62","b0254f","de4126","eb9605"],
134
+    &["efd9b4","d6a692","a39081","4d6160","292522"],
135
+    &["e21b5a","9e0c39","333333","fbffe3","83a300"],
136
+    &["f2e3c6","ffc6a5","e6324b","2b2b2b","353634"],
137
+    &["c75233","c78933","d6ceaa","79b5ac","5e2f46"],
138
+    &["793a57","4d3339","8c873e","d1c5a5","a38a5f"],
139
+    &["512b52","635274","7bb0a8","a7dbab","e4f5b1"],
140
+    &["11644d","a0b046","f2c94e","f78145","f24e4e"],
141
+    &["59b390","f0ddaa","e47c5d","e32d40","152b3c"],
142
+    &["fdffd9","fff0b8","ffd6a3","faad8e","142f30"],
143
+    &["b5ac01","ecba09","e86e1c","d41e45","1b1521"],
144
+    &["c7fcd7","d9d5a7","d9ab91","e6867a","ed4a6a"],
145
+    &["11766d","410936","a40b54","e46f0a","f0b300"],
146
+    &["595643","4e6b66","ed834e","ebcc6e","ebe1c5"],
147
+    &["f1396d","fd6081","f3ffeb","acc95f","8f9924"],
148
+    &["331327","991766","d90f5a","f34739","ff6e27"],
149
+    &["efeecc","fe8b05","fe0557","400403","0aabba"],
150
+    &["bf496a","b39c82","b8c99d","f0d399","595151"],
151
+    &["b7cbbf","8c886f","f9a799","f4bfad","f5dabd"],
152
+    &["ffb884","f5df98","fff8d4","c0d1c2","2e4347"],
153
+    &["e5eaa4","a8c4a2","69a5a4","616382","66245b"],
154
+    &["e0eff1","7db4b5","ffffff","680148","000000"],
155
+    &["b1e6d1","77b1a9","3d7b80","270a33","451a3e"],
156
+    &["e4ded0","abccbd","7dbeb8","181619","e32f21"],
157
+    &["e9e0d1","91a398","33605a","070001","68462b"],
158
+    &["fc284f","ff824a","fea887","f6e7f7","d1d0d7"],
159
+    &["ffab07","e9d558","72ad75","0e8d94","434d53"],
160
+    &["6da67a","99a66d","a9bd68","b5cc6a","c0de5d"],
161
+    &["311d39","67434f","9b8e7e","c3ccaf","a51a41"],
162
+    &["cfb590","9e9a41","758918","564334","49281f"],
163
+    &["5cacc4","8cd19d","cee879","fcb653","ff5254"],
164
+    &["44749d","c6d4e1","ffffff","ebe7e0","bdb8ad"],
165
+    &["807462","a69785","b8faff","e8fdff","665c49"],
166
+    &["e7edea","ffc52c","fb0c06","030d4f","ceecef"],
167
+    &["ccf390","e0e05a","f7c41f","fc930a","ff003d"],
168
+    &["2b222c","5e4352","965d62","c7956d","f2d974"],
169
+    &["cc5d4c","fffec6","c7d1af","96b49c","5b5847"],
170
+    &["e4e4c5","b9d48b","8d2036","ce0a31","d3e4c5"],
171
+    &["e3e8cd","bcd8bf","d3b9a3","ee9c92","fe857e"],
172
+    &["360745","d61c59","e7d84b","efeac5","1b8798"],
173
+    &["ec4401","cc9b25","13cd4a","7b6ed6","5e525c"],
174
+    &["eb9c4d","f2d680","f3ffcf","bac9a9","697060"],
175
+    &["f2e8c4","98d9b6","3ec9a7","2b879e","616668"],
176
+    &["f5dd9d","bcc499","92a68a","7b8f8a","506266"],
177
+    &["fff3db","e7e4d5","d3c8b4","c84648","703e3b"],
178
+    &["041122","259073","7fda89","c8e98e","e6f99d"],
179
+    &["8d7966","a8a39d","d8c8b8","e2ddd9","f8f1e9"],
180
+    &["c6cca5","8ab8a8","6b9997","54787d","615145"],
181
+    &["1d1313","24b694","d22042","a3b808","30c4c9"],
182
+    &["4b1139","3b4058","2a6e78","7a907c","c9b180"],
183
+    &["2d1b33","f36a71","ee887a","e4e391","9abc8a"],
184
+    &["f0ffc9","a9da88","62997a","72243d","3b0819"],
185
+    &["429398","6b5d4d","b0a18f","dfcdb4","fbeed3"],
186
+    &["9d9e94","c99e93","f59d92","e5b8ad","d5d2c8"],
187
+    &["95a131","c8cd3b","f6f1de","f5b9ae","ee0b5b"],
188
+    &["322938","89a194","cfc89a","cc883a","a14016"],
189
+    &["540045","c60052","ff714b","eaff87","acffe9"],
190
+    &["79254a","795c64","79927d","aeb18e","e3cf9e"],
191
+    &["452e3c","ff3d5a","ffb969","eaf27e","3b8c88"],
192
+    &["2b2726","0a516d","018790","7dad93","bacca4"],
193
+    &["027b7f","ffa588","d62957","bf1e62","572e4f"],
194
+    &["fa6a64","7a4e48","4a4031","f6e2bb","9ec6b8"],
195
+    &["fb6900","f63700","004853","007e80","00b9bd"],
196
+    &["f06d61","da825f","c4975c","a8ab7b","8cbf99"],
197
+    &["23192d","fd0a54","f57576","febf97","f5ecb7"],
198
+    &["f6d76b","ff9036","d6254d","ff5475","fdeba9"],
199
+    &["a3c68c","879676","6e6662","4f364a","340735"],
200
+    &["a32c28","1c090b","384030","7b8055","bca875"],
201
+    &["80a8a8","909d9e","a88c8c","ff0d51","7a8c89"],
202
+    &["6d9788","1e2528","7e1c13","bf0a0d","e6e1c2"],
203
+    &["373737","8db986","acce91","badb73","efeae4"],
204
+    &["e6b39a","e6cba5","ede3b4","8b9e9b","6d7578"],
205
+    &["280904","680e34","9a151a","c21b12","fc4b2a"],
206
+    &["4b3e4d","1e8c93","dbd8a2","c4ac30","d74f33"],
207
+    &["161616","c94d65","e7c049","92b35a","1f6764"],
208
+    &["234d20","36802d","77ab59","c9df8a","f0f7da"],
209
+    &["a69e80","e0ba9b","e7a97e","d28574","3b1922"],
210
+    &["641f5e","676077","65ac92","c2c092","edd48e"],
211
+    &["e6eba9","abbb9f","6f8b94","706482","703d6f"],
212
+    &["26251c","eb0a44","f2643d","f2a73d","a0e8b7"],
213
+    &["fdcfbf","feb89f","e23d75","5f0d3b","742365"],
214
+    &["ff7474","f59b71","c7c77f","e0e0a8","f1f1c1"],
215
+    &["4f364c","5e405f","6b6b6b","8f9e6f","b1cf72"],
216
+    &["230b00","a29d7f","d4cfa5","f8ecd4","aabe9b"],
217
+    &["d4f7dc","dbe7b4","dbc092","e0846d","f51441"],
218
+    &["62a07b","4f8b89","536c8d","5c4f79","613860"],
219
+];

+ 3
- 1
core/src/keywords.rs View File

@@ -322,6 +322,8 @@ pub enum Keyword {
322 322
     Height,
323 323
     #[strum(serialize = "inc")]
324 324
     Inc,
325
+    #[strum(serialize = "index")]
326
+    Index,
325 327
     #[strum(serialize = "inner-height")]
326 328
     InnerHeight,
327 329
     #[strum(serialize = "inner-width")]
@@ -441,7 +443,7 @@ mod tests {
441 443
     fn test_keyword_enums() {
442 444
         assert_eq!(Keyword::False as i32, 128);
443 445
         assert_eq!(Keyword::True as i32, 129);
444
-        assert_eq!(Keyword::Width as i32, 300);
446
+        assert_eq!(Keyword::Width as i32, 301);
445 447
     }
446 448
 
447 449
     #[test]

+ 1
- 0
core/src/lib.rs View File

@@ -31,6 +31,7 @@ pub mod seni_language;
31 31
 mod bitmap;
32 32
 mod bitmap_cache;
33 33
 mod colour;
34
+mod colour_palettes;
34 35
 mod compiler;
35 36
 mod context;
36 37
 mod ease;

+ 34
- 0
core/src/native.rs View File

@@ -172,6 +172,8 @@ pub enum Native {
172 172
     // ColBuildBezier,
173 173
     #[strum(serialize = "col/value")]
174 174
     ColValue,
175
+    #[strum(serialize = "col/palette")]
176
+    ColPalette,
175 177
 
176 178
     // math
177 179
     //
@@ -373,6 +375,7 @@ pub fn parameter_info(native: Native) -> Result<(Vec<(Keyword, Var)>, i32)> {
373 375
         Native::ColGetV => common_colour_only_parameter_info(),
374 376
         Native::ColBuildProcedural => col_build_procedural_parameter_info(),
375 377
         Native::ColValue => col_value_parameter_info(),
378
+        Native::ColPalette => col_palette_parameter_info(),
376 379
         // math
377 380
         Native::MathDistance => math_distance_parameter_info(),
378 381
         Native::MathNormal => math_normal_parameter_info(),
@@ -499,6 +502,7 @@ pub fn execute_native(
499 502
         Native::ColGetV => col_get_elem_execute(vm, 2),
500 503
         Native::ColBuildProcedural => col_build_procedural_execute(vm),
501 504
         Native::ColValue => col_value_execute(vm),
505
+        Native::ColPalette => col_palette_execute(vm),
502 506
         // math
503 507
         Native::MathDistance => math_distance_execute(vm),
504 508
         Native::MathNormal => math_normal_execute(vm),
@@ -1982,6 +1986,36 @@ fn col_value_execute(vm: &mut Vm) -> Result<Option<Var>> {
1982 1986
     Ok(Some(Var::Colour(res)))
1983 1987
 }
1984 1988
 
1989
+fn col_palette_parameter_info() -> Result<(Vec<(Keyword, Var)>, i32)> {
1990
+    Ok((
1991
+        // input arguments
1992
+        vec![
1993
+            (Keyword::Index, Var::Float(0.0)),
1994
+        ],
1995
+        // stack offset
1996
+        1,
1997
+    ))
1998
+}
1999
+
2000
+fn col_palette_execute(vm: &mut Vm) -> Result<Option<Var>> {
2001
+    let default_mask: i32 = vm.stack_peek(2)?;
2002
+
2003
+    if !is_arg_given(default_mask, 1) {
2004
+        error!("col_palette_execute requires index parameter");
2005
+        return Err(Error::Native);
2006
+    }
2007
+
2008
+    let index: f32 = vm.stack_peek(1)?;
2009
+    let palette = Colour::palette(index as usize)?;
2010
+
2011
+    let mut vs: Vec<Var> = Vec::new();
2012
+    for colour in palette {
2013
+        vs.push(Var::Colour(colour));
2014
+    }
2015
+
2016
+    Ok(Some(Var::Vector(vs)))
2017
+}
2018
+
1985 2019
 fn math_distance_parameter_info() -> Result<(Vec<(Keyword, Var)>, i32)> {
1986 2020
     Ok((
1987 2021
         // input arguments

+ 127
- 0
server/static/seni/sketch/1926-hand-palette.seni View File

@@ -0,0 +1,127 @@
1
+(define
2
+
3
+  [col1 col2 col3 col4 col5] (col/palette index: {0 (gen/scalar min: 0 max: 200)})
4
+
5
+  hslcol1 (col/convert colour: col1 format: HSLuv)
6
+  hslcol2 (col/convert colour: col2 format: HSLuv)
7
+  hslcol3 (col/convert colour: col3 format: HSLuv)
8
+  hslcol4 (col/convert colour: col4 format: HSLuv)
9
+  hslcol5 (col/convert colour: col5 format: HSLuv)
10
+  hslrng (prng/build seed: 42
11
+                     min: -10
12
+                     max: 10)
13
+
14
+  texture "hand.png"
15
+  bmx (interp/build from: [0 canvas/width] to: [0 (bitmap/width from: texture)])
16
+  bmy (interp/build from: [0 canvas/height] to: [0 (bitmap/height from: texture)]))
17
+
18
+(on-matrix-stack
19
+  (scale scalar: 1.1)
20
+  (rotate angle: 3)
21
+  (wash colour: col1))
22
+
23
+(on-matrix-stack
24
+  (scale scalar: 1.05)
25
+  (tri-hsl alpha: {0.118 (gen/scalar)})
26
+  (tri-lab alpha: {0.062 (gen/scalar)}))
27
+
28
+(define
29
+  ra (prng/build seed: 42
30
+                 min: {-5.472 (gen/stray from: -4 by: 4)}
31
+                 max: {3.869 (gen/stray from: 4 by: 4)})
32
+  sc {0.801 (gen/scalar min: 0.8 max: 1.1)}
33
+  wh {5 (gen/int min: 5 max: 20)}
34
+  w wh
35
+  h wh)
36
+
37
+(fn (left x: 0 y: 0 w: 0 h: 0 colour: red)
38
+  (poly coords: [[(- x w) (+ y h h)]
39
+                 [(+ x w) (+ y h)]
40
+                 [(- x w) (+ y 0)]
41
+                 [(+ x w) (- y h)]]
42
+        colours: [colour colour colour colour]))
43
+
44
+(fn (right x: 0 y: 0 w: 0 h: 0 colour: red)
45
+  (poly coords: [[(+ x w) (+ y h h)]
46
+                 [(- x w) (+ y h)]
47
+                 [(+ x w) (+ y 0)]
48
+                 [(- x w) (- y h)]]
49
+        colours: [colour colour colour colour]))
50
+
51
+(fn (left-side x: 0 y: 0 w: 0 h: 0 colour: red strength: 1)
52
+  (define col (col/set-alpha value: strength
53
+                             colour: (col/set-s value: (* 100 strength)
54
+                                                colour: (col/convert format: HSLuv colour: colour))))
55
+  (on-matrix-stack
56
+    (translate vector: [x y])
57
+    (rotate angle: (prng/value from: ra))
58
+    (left x: 0 y: 0 w: w h: h colour: col)
59
+    (loop (i to: 3)
60
+      (scale scalar: sc)
61
+      (rotate angle: (prng/value from: ra))
62
+      (left x: 0 y: 0 w: w h: h colour: col))))
63
+
64
+(fn (right-side x: 0 y: 0 w: 0 h: 0 colour: red strength: 1)
65
+  (define col (col/set-alpha value: strength
66
+                             colour: (col/set-s value: (* 100 strength)
67
+                                                colour: (col/convert format: HSLuv colour: colour))))
68
+  (on-matrix-stack
69
+    (translate vector: [x y])
70
+    (rotate angle: (prng/value from: ra))
71
+    (right x: 0 y: 0 w: w h: h colour: col)
72
+    (loop (i to: 3)
73
+      (scale scalar: sc)
74
+      (rotate angle: (prng/value from: ra))
75
+      (right x: 0 y: 0 w: w h: h colour: col))))
76
+
77
+(fn (tri-lab alpha: 1)
78
+  (loop (y from: 0 to: canvas/height inc: (* 2 h))
79
+    (loop (x from: 0 to: canvas/width inc: (* 4 w))
80
+      (define
81
+        c2 (col/set-l colour: hslcol2 value: (+ (col/get-l colour: hslcol2) (prng/value from: hslrng)))
82
+        c3 (col/set-l colour: hslcol3 value: (+ (col/get-l colour: hslcol3) (prng/value from: hslrng)))
83
+        col-bm (bitmap/value from: texture position: [(interp/value from: bmx t: x)
84
+                                                      (interp/value from: bmy t: y)]))
85
+      (left-side  x: x         y: y w: w h: h colour: c2 strength: (col/get-r colour: col-bm))
86
+      (right-side x: (+ x w w) y: y w: w h: h colour: c3 strength: (col/get-r colour: col-bm)))))
87
+
88
+(fn (tri-hsl alpha: 1)
89
+  (loop (y from: 0 to: canvas/height inc: (* 2 h))
90
+    (loop (x from: 0 to: canvas/width inc: (* 4 w))
91
+      (define
92
+        c4 (col/set-l colour: hslcol4 value: (+ (col/get-l colour: hslcol4) (prng/value from: hslrng)))
93
+        c5 (col/set-l colour: hslcol5 value: (+ (col/get-l colour: hslcol5) (prng/value from: hslrng)))
94
+
95
+        col-bm (bitmap/value from: texture position: [(interp/value from: bmx t: x)
96
+                                                      (interp/value from: bmy t: y)]))
97
+      (left-side  x: x         y: y w: w h: h colour: c4 strength: (col/get-r colour: col-bm))
98
+      (right-side x: (+ x w w) y: y w: w h: h colour: c5 strength: (col/get-r colour: col-bm)))))
99
+
100
+
101
+(fn (wash vol: 200
102
+          line-width: 70
103
+          line-segments: 5
104
+          colour: (col/rgb r: 0.627 g: 0.627 b: 0.627 alpha: 0.4)
105
+          seed: 272)
106
+  (define
107
+    w/3 (/ canvas/width 3)
108
+    h/3 (/ canvas/height 3))
109
+  (loop (d from: -20 to: 1020 inc: 20)
110
+    (bezier tessellation: line-segments
111
+            line-width: line-width
112
+            coords: [[0            (wash-n x: 0            d: d seed: seed vol: vol)]
113
+                     [w/3          (wash-n x: w/3          d: d seed: seed vol: vol)]
114
+                     [(* w/3 2)    (wash-n x: (* w/3 2)    d: d seed: seed vol: vol)]
115
+                     [canvas/width (wash-n x: canvas/width d: d seed: seed vol: vol)]]
116
+            colour: colour)
117
+
118
+    (bezier tessellation: line-segments
119
+            line-width: line-width
120
+            coords: [[(wash-n x: 0             d: d seed: seed vol: vol) 0]
121
+                     [(wash-n x: h/3           d: d seed: seed vol: vol) h/3]
122
+                     [(wash-n x: (* h/3 2)     d: d seed: seed vol: vol) (* h/3 2)]
123
+                     [(wash-n x: canvas/height d: d seed: seed vol: vol) canvas/height]]
124
+            colour: colour)))
125
+
126
+(fn (wash-n x: 0 d: 0 seed: 0 vol: 1)
127
+  (+ d (* vol (prng/perlin x: x y: d z: seed))))

Loading…
Cancel
Save