@@ -214,4 +214,76 @@ suite('color/Setting', function() {
214214 assert . deepEqual ( myp5 . _colorMaxes [ myp5 . HSB ] , [ 360 , 100 , 100 , 1 ] ) ;
215215 } ) ;
216216 } ) ;
217+
218+ suite ( 'p5.Color components' , function ( ) {
219+ test ( 'setRed() correctly sets red component' , function ( ) {
220+ myp5 . colorMode ( myp5 . RGB , 255 ) ;
221+ const c = myp5 . color ( 0 , 162 , 205 , 255 ) ;
222+ c . setRed ( 100 ) ;
223+ assert . equal ( myp5 . red ( c ) , 100 ) ;
224+ assert . equal ( myp5 . green ( c ) , 162 ) ;
225+ assert . equal ( myp5 . blue ( c ) , 205 ) ;
226+ assert . equal ( myp5 . alpha ( c ) , 255 ) ;
227+ } ) ;
228+
229+ test ( 'setGreen() correctly sets green component' , function ( ) {
230+ myp5 . colorMode ( myp5 . RGB , 255 ) ;
231+ const c = myp5 . color ( 0 , 162 , 205 , 255 ) ;
232+ c . setGreen ( 100 ) ;
233+ assert . equal ( myp5 . red ( c ) , 0 ) ;
234+ assert . equal ( myp5 . green ( c ) , 100 ) ;
235+ assert . equal ( myp5 . blue ( c ) , 205 ) ;
236+ assert . equal ( myp5 . alpha ( c ) , 255 ) ;
237+ } ) ;
238+
239+ test ( 'setBlue() correctly sets blue component' , function ( ) {
240+ myp5 . colorMode ( myp5 . RGB , 255 ) ;
241+ const c = myp5 . color ( 0 , 162 , 205 , 255 ) ;
242+ c . setBlue ( 100 ) ;
243+ assert . equal ( myp5 . red ( c ) , 0 ) ;
244+ assert . equal ( myp5 . green ( c ) , 162 ) ;
245+ assert . equal ( myp5 . blue ( c ) , 100 ) ;
246+ assert . equal ( myp5 . alpha ( c ) , 255 ) ;
247+ } ) ;
248+
249+ test ( 'setAlpha correctly sets alpha component' , function ( ) {
250+ myp5 . colorMode ( myp5 . RGB , 255 ) ;
251+ const c = myp5 . color ( 0 , 162 , 205 , 255 ) ;
252+ c . setAlpha ( 100 ) ;
253+ assert . equal ( myp5 . red ( c ) , 0 ) ;
254+ assert . equal ( myp5 . green ( c ) , 162 ) ;
255+ assert . equal ( myp5 . blue ( c ) , 205 ) ;
256+ assert . equal ( myp5 . alpha ( c ) , 100 ) ;
257+ } ) ;
258+
259+ test ( 'changing the red/green/blue/alpha components should clear the cached HSL/HSB values' , function ( ) {
260+ myp5 . colorMode ( myp5 . RGB , 255 ) ;
261+ const c = myp5 . color ( 0 , 162 , 205 , 255 ) ;
262+
263+ // create HSL/HSB values
264+ myp5 . lightness ( c ) ;
265+ myp5 . brightness ( c ) ;
266+ c . setRed ( 100 ) ;
267+ assert ( ! c . hsba ) ;
268+ assert ( ! c . hsla ) ;
269+
270+ myp5 . lightness ( c ) ;
271+ myp5 . brightness ( c ) ;
272+ c . setGreen ( 100 ) ;
273+ assert ( ! c . hsba ) ;
274+ assert ( ! c . hsla ) ;
275+
276+ myp5 . lightness ( c ) ;
277+ myp5 . brightness ( c ) ;
278+ c . setBlue ( 100 ) ;
279+ assert ( ! c . hsba ) ;
280+ assert ( ! c . hsla ) ;
281+
282+ myp5 . lightness ( c ) ;
283+ myp5 . brightness ( c ) ;
284+ c . setAlpha ( 100 ) ;
285+ assert ( ! c . hsba ) ;
286+ assert ( ! c . hsla ) ;
287+ } ) ;
288+ } ) ;
217289} ) ;
0 commit comments