Skip to content

Commit

Permalink
Add a couple more color spaces for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
limzykenneth committed Dec 8, 2024
1 parent 8cc09a0 commit 364813d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
10 changes: 8 additions & 2 deletions src/color/creating_reading.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
import { Color } from './p5.Color';

export const RGB = 'rgb';
export const RGBHDR = 'rgbhdr';
export const HSB = 'hsb';
export const HSL = 'hsl';
export const RGBHDR = 'rgbhdr';
export const LCH = 'lch';
export const OKLCH = 'oklch';
export const RGBA = 'rgba';

function creatingReading(p5, fn){
fn.RGB = RGB;
fn.HSB = HSB;
fn.HSL = HSL;
fn.LCH = LCH;
fn.OKLCH = OKLCH;
fn.RGBA = RGBA;

// Set color related defaults
Expand All @@ -27,7 +31,9 @@ function creatingReading(p5, fn){
[RGB]: [255, 255, 255, 255],
[RGBHDR]: [255, 255, 255, 255],
[HSB]: [360, 100, 100, 1],
[HSL]: [360, 100, 100, 1]
[HSL]: [360, 100, 100, 1],
[LCH]: [100, 150, 360, 1],
[OKLCH]: [100, 150, 360, 1]
};

/**
Expand Down
24 changes: 5 additions & 19 deletions src/color/p5.Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @requires color_conversion
*/

import { RGB, RGBHDR, HSL, HSB } from './creating_reading';
import { RGB, RGBHDR, HSL, HSB, LCH, OKLCH } from './creating_reading';

import {
ColorSpace,
Expand All @@ -21,10 +21,10 @@ import {
HSV,

Lab,
LCH,
LCH as LCHSpace,

OKLab,
OKLCH,
OKLCH as OKLCHSpace,

P3,

Expand Down Expand Up @@ -532,27 +532,13 @@ function color(p5, fn){
*/
p5.Color = Color;

// ColorSpace.register(sRGB);
// ColorSpace.register(HSLSpace);
// ColorSpace.register(HSV);
// ColorSpace.register(HSBSpace);

// ColorSpace.register(Lab);
// ColorSpace.register(LCH);

// ColorSpace.register(OKLab);
// ColorSpace.register(OKLCH);

// ColorSpace.register(P3);

// ColorSpace.register(A98RGB_Linear);
// ColorSpace.register(A98RGB);

// Register color modes and initialize Color maxes to what p5 has set for itself
p5.Color.addColorMode(RGB, sRGB, fn._colorMaxes?.[RGB]);
p5.Color.addColorMode(RGBHDR, P3, fn._colorMaxes?.[RGBHDR]);
p5.Color.addColorMode(HSB, HSBSpace, fn._colorMaxes?.[HSB]);
p5.Color.addColorMode(HSL, HSLSpace, fn._colorMaxes?.[HSL]);
p5.Color.addColorMode(LCH, LCHSpace, fn._colorMaxes?.[LCH]);
p5.Color.addColorMode(OKLCH, OKLCHSpace, fn._colorMaxes?.[OKLCH]);
}

export default color;
Expand Down
6 changes: 2 additions & 4 deletions src/color/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import * as constants from '../core/constants';
import { RGB, HSB, HSL } from './creating_reading';
import { RGB, RGBHDR, HSL, HSB, LCH, OKLCH } from './creating_reading';

function setting(p5, fn){
/**
Expand Down Expand Up @@ -951,9 +951,7 @@ function setting(p5, fn){
fn.colorMode = function(mode, max1, max2, max3, maxA) {
p5._validateParameters('colorMode', arguments);
if (
mode === RGB ||
mode === HSB ||
mode === HSL
[RGB, RGBHDR, HSB, HSL, LCH, OKLCH].includes(mode)
) {
// Set color mode.
this._colorMode = mode;
Expand Down

0 comments on commit 364813d

Please sign in to comment.