“TexelColor+p5 Dead Simple” by Golan Levin
https://openprocessing.org/sketch/2384613
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Forks of this sketch will no longer be attributed to this sketch.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution NonCommercial ShareAlike
TexelColor+p5 Dead Simple
Levin
xxxxxxxxxx
// @mattdesl's Texel/Color in p5.js
// See: https://github.com/texel-org/color
// Example color conversion with Texel/color:
// output = Colors.convert(coords, fromSpace, toSpace, output = [0, 0, 0])
//--------------------
// Don't touch this, it loads the Texel/Color library as a module.
let myTexel;
async function preload() {
myTexel = await import('https://unpkg.com/@texel/color@1.0.6/src/index.js');
}
//--------------------
function setup() {
createCanvas(400, 200);
}
function draw() {
background(0);
noStroke();
if (myTexel){ // Make sure it has been loaded
// Start with an HSL color, (0-360,0-1,0-1)
let srcH = map(noise(123 + millis()/3000.0), 0,1, 0,360);
let srcS = 0.9;
let srcL = noise(234 + millis()/3000.0);
// Convert it to RGB for display
let srcHSL = [srcH,srcS,srcL];
let srcRGB = [0,0,0]; // yet to be calculated
myTexel.convert(srcHSL, myTexel.OKHSL, myTexel.sRGB, srcRGB);
// Display the RGB color
let srcR = 255 * srcRGB[0];
let srcG = 255 * srcRGB[1];
let srcB = 255 * srcRGB[2];
fill(srcR,srcG,srcB);
rect(0,0, 200,200);
// Compute a complementary color, 180° away and with inverse luminance
let dstH = (360 + srcH + 180)%360;
let dstS = srcS;
let dstL = 1.0 - srcL;
let dstHSL = [dstH,dstS,dstL];
let dstRGB = [0,0,0]; // yet to be calculated
myTexel.convert(dstHSL, myTexel.OKHSL, myTexel.sRGB, dstRGB);
// Display the complementary RGB color
let dstR = 255 * dstRGB[0];
let dstG = 255 * dstRGB[1];
let dstB = 255 * dstRGB[2];
fill(dstR,dstG,dstB);
rect(200,0, 200,200);
}
}
See More Shortcuts
Please verify your email to comment
Verify Email