11using System . Text . RegularExpressions ;
22using Wacton . Unicolour ;
33using Wacton . Unicolour . Datasets ;
4+ using Wacton . Unicolour . Experimental ;
45using Wacton . Unicolour . Icc ;
56
67const string repoReadme = "README.md" ;
@@ -39,19 +40,30 @@ void ProcessDocsReadme(string readmePath)
3940 textForDocs = Regex . Replace ( textForDocs , @"<details>(.|\n)*?<\/details>" , string . Empty ) ;
4041
4142 var ukText = textForDocs ;
42- var usText = textForDocs ;
43-
4443 ukText += Environment . NewLine ;
4544 ukText += $ "Also available in [American]({ readmeAmericanFilename } ) \ud83c \uddfa \ud83c \uddf8 .";
4645 File . WriteAllText ( Path . Combine ( sourceRoot , Path . GetFileName ( readmePath ) ) , ukText ) ;
46+
47+ // substitute parts of the readme text that shouldn't change
48+ var guidSubstitutes = new ( string original , string guid ) [ ]
49+ {
50+ ( "https://unicolour.wacton.xyz/wxy-colour-space" , Guid . NewGuid ( ) . ToString ( ) ) ,
51+ ( "https://play.unity.com/en/games/6826f61f-3806-4155-b824-7866b1edaed7/3d-colour-space-visualisation-unicolour-demo" , Guid . NewGuid ( ) . ToString ( ) ) ,
52+ ( "Unicolour" , Guid . NewGuid ( ) . ToString ( ) ) ,
53+ ( "unicolour" , Guid . NewGuid ( ) . ToString ( ) ) ,
54+ ( "ColourSpace" , Guid . NewGuid ( ) . ToString ( ) )
55+ } ;
56+
57+ var guidText = guidSubstitutes . Aggregate ( textForDocs , ( current , substitute ) => current . Replace ( substitute . original , substitute . guid ) ) ;
4758
48- // could use regex but why bother? also want to be careful not to change spelling of "unicolour", "ColourSpace", etc.
49- usText = usText
59+ // could use regex but why bother?
60+ var usText = guidText
5061 . Replace ( "Colour " , "Color " )
5162 . Replace ( "Colours " , "Colors " )
5263 . Replace ( "Colour&" , "Color&" )
5364 . Replace ( "colour&" , "color&" )
5465 . Replace ( " colour" , " color" )
66+ . Replace ( "colour." , "color." )
5567 . Replace ( "-colour" , "-color" )
5668 . Replace ( "colourful" , "colorful" )
5769 . Replace ( " grey " , " gray " )
@@ -62,6 +74,8 @@ void ProcessDocsReadme(string readmePath)
6274 . Replace ( "isation " , "ization " )
6375 . Replace ( "isations " , "izations " )
6476 . Replace ( "metre" , "meter" ) ;
77+
78+ usText = guidSubstitutes . Aggregate ( usText , ( current , substitute ) => current . Replace ( substitute . guid , substitute . original ) ) ;
6579 usText += Environment . NewLine ;
6680 usText += $ "Also available in [British]({ readmeFilename } ) \ud83c \uddec \ud83c \udde7 .";
6781 File . WriteAllText ( Path . Combine ( sourceRoot , Path . GetFileName ( readmeAmericanPath ) ) , usText ) ;
@@ -128,17 +142,21 @@ void Quickstart()
128142 var magenta = red . Mix ( blue , ColourSpace . Hsl ) ;
129143 Console . WriteLine ( magenta . Rgb ) ; // 1.00 0.00 1.00
130144 Console . WriteLine ( magenta . Hex ) ; // #FF00FF
145+
146+ // #FF0000, #FF0080, #FF00FF, #8000FF, #0000FF
147+ var palette = red . Palette ( blue , ColourSpace . Hsl , 5 ) ;
148+ Console . WriteLine ( palette . Select ( colour => colour . Hex ) ) ;
131149
132150 var white = new Unicolour ( ColourSpace . Oklab , 1.0 , 0.0 , 0.0 ) ;
133151 var black = new Unicolour ( ColourSpace . Oklab , 0.0 , 0.0 , 0.0 ) ;
134152 var difference = white . Difference ( black , DeltaE . Ciede2000 ) ;
135153 Console . WriteLine ( difference ) ; // 100.0000
136154
137- var equalTristimulus = new Unicolour ( ColourSpace . Xyz , 0.5 , 0.5 , 0.5 ) ;
138- Console . WriteLine ( equalTristimulus . Chromaticity . Xy ) ; // (0.3333, 0.3333)
139- Console . WriteLine ( equalTristimulus . Chromaticity . Uv ) ; // (0.2105, 0.3158)
140- Console . WriteLine ( equalTristimulus . Temperature ) ; // 5455.5 K (Δuv -0.00442)
141- Console . WriteLine ( equalTristimulus . DominantWavelength ) ; // 596.1
155+ var equalEnergy = new Unicolour ( ColourSpace . Xyz , 0.5 , 0.5 , 0.5 ) ;
156+ Console . WriteLine ( equalEnergy . Chromaticity . Xy ) ; // (0.3333, 0.3333)
157+ Console . WriteLine ( equalEnergy . Chromaticity . Uv ) ; // (0.2105, 0.3158)
158+ Console . WriteLine ( equalEnergy . Temperature ) ; // 5455.5 K (Δuv -0.00442)
159+ Console . WriteLine ( equalEnergy . DominantWavelength ) ; // 596.1
142160}
143161
144162void FeatureConvert ( )
@@ -153,6 +171,7 @@ void FeatureMix()
153171 var blue = new Unicolour ( ColourSpace . Hsb , 240 , 1.0 , 1.0 ) ;
154172 var magenta = red . Mix ( blue , ColourSpace . Hsl , 0.5 , HueSpan . Decreasing ) ;
155173 var green = red . Mix ( blue , ColourSpace . Hsl , 0.5 , HueSpan . Increasing ) ;
174+ var palette = red . Palette ( blue , ColourSpace . Hsl , 10 , HueSpan . Longer ) ;
156175}
157176
158177void FeatureCompare ( )
@@ -169,6 +188,12 @@ void FeatureGamutMap()
169188 var inGamut = outOfGamut . MapToRgbGamut ( ) ;
170189}
171190
191+ void FeatureCvd ( )
192+ {
193+ var colour = new Unicolour ( ColourSpace . Rgb255 , 192 , 255 , 238 ) ;
194+ var noRed = colour . Simulate ( Cvd . Protanopia ) ;
195+ }
196+
172197void FeatureTemperature ( )
173198{
174199 var chromaticity = new Chromaticity ( 0.3457 , 0.3585 ) ;
@@ -180,13 +205,6 @@ void FeatureTemperature()
180205 var ( x , y ) = d65 . Chromaticity ;
181206}
182207
183- void FeatureSpd ( )
184- {
185- // [575 nm] -> 0.5 · [580 nm] -> 1.0 · [585 nm] -> 0.5
186- var spd = new Spd ( start : 575 , interval : 5 , [ 0.5 , 1.0 , 0.5 ] ) ;
187- var intenseYellow = new Unicolour ( spd ) ;
188- }
189-
190208void FeatureWavelength ( )
191209{
192210 var chromaticity = new Chromaticity ( 0.1 , 0.8 ) ;
@@ -202,10 +220,19 @@ void FeatureImaginary()
202220 var isImaginary = impossibleBlue . IsImaginary ;
203221}
204222
205- void FeatureCvd ( )
223+ void FeatureSpd ( )
206224{
207- var colour = new Unicolour ( ColourSpace . Rgb255 , 192 , 255 , 238 ) ;
208- var noRed = colour . Simulate ( Cvd . Protanopia ) ;
225+ /* [575 nm] -> 0.5 · [580 nm] -> 1.0 · [585 nm] -> 0.5 */
226+ var spd = new Spd ( start : 575 , interval : 5 , coefficients : [ 0.5 , 1.0 , 0.5 ] ) ;
227+ var intenseYellow = new Unicolour ( spd ) ;
228+ }
229+
230+ void FeaturePigment ( )
231+ {
232+ /* populate k and s with measurement data */
233+ var phthaloBlue = new Pigment ( startWavelength : 380 , wavelengthInterval : 10 , k : [ ] , s : [ ] ) ;
234+ var hansaYellow = new Pigment ( startWavelength : 380 , wavelengthInterval : 10 , k : [ ] , s : [ ] ) ;
235+ var green = new Unicolour ( pigments : [ phthaloBlue , hansaYellow ] , weights : [ 0.5 , 0.5 ] ) ;
209236}
210237
211238void FeatureIcc ( )
@@ -279,4 +306,20 @@ void Datasets()
279306 var pink = Css . DeepPink ;
280307 var green = Xkcd . NastyGreen ;
281308 var mapped = Colourmaps . Viridis . Map ( 0.5 ) ;
309+ var palette = Colourmaps . Turbo . Palette ( 10 ) ;
310+ }
311+
312+ void ExperimentalPigmentGenerator ( )
313+ {
314+ var redPigment = PigmentGenerator . From ( new Unicolour ( "#FF0000" ) ) ;
315+ var bluePigment = PigmentGenerator . From ( new Unicolour ( "#0000FF" ) ) ;
316+ var magenta = new Unicolour ( [ redPigment , bluePigment ] , [ 0.5 , 0.5 ] ) ;
317+ }
318+
319+ void ExperimentalSpectralJs ( )
320+ {
321+ var blue = new Unicolour ( "#0000FF" ) ;
322+ var yellow = new Unicolour ( "#FFFF00" ) ;
323+ var green = SpectralJs . Mix ( [ blue , yellow ] , [ 0.5 , 0.5 ] ) ;
324+ var palette = SpectralJs . Palette ( blue , yellow , 9 ) ;
282325}
0 commit comments