Last active
September 24, 2018 03:32
-
-
Save Morpholux/264b8d5fa673c5316f47fd0c0bfef956 to your computer and use it in GitHub Desktop.
Manière de créer des recettes de couleurs apparentées à une référence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// renaud.jean-francois(arobas)uqam(point)ca | |
// Syntaxe Processing version 3.4 | |
// dimanche, 23 septembre 2018 | |
// Pour réaliser une conversion du mode couleur avec la classe Java | |
// http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/Color.html | |
import java.awt.Color; | |
float shiftHue = 0.1; | |
float shiftSat = 0.1; | |
float shiftBright = 0.1; | |
color cRgb; | |
void setup() { | |
size(600, 600); | |
background(0); | |
noStroke(); | |
//noLoop(); | |
} | |
void draw() { | |
//background(0); | |
colorMode(RGB, 255, 255, 255); | |
cRgb = color(#FF3B74); | |
for (int i = 0; i < 200; i++) { | |
// Conversion to HSB | |
float[] colConverted = new float[3]; | |
colConverted = rgbToHsbFloat(cRgb); | |
colorMode(HSB, 1, 1, 1); | |
color cHsb = color(colConverted[0], colConverted[1], colConverted[2]); | |
// altération de la teinte (hue) | |
colConverted[0] = (colConverted[0]+random(-shiftHue, shiftHue))%1.0; | |
// altération de la saturation (saturation) | |
colConverted[1] = constrain(colConverted[1]+random(-shiftSat, shiftSat), 0, 1); | |
// altération de la luminosité (brightness) | |
colConverted[2] = constrain(colConverted[2]+random(-shiftBright, shiftBright), 0, 1); | |
// Reconversion to RGB | |
colorMode(RGB, 1, 1, 1); | |
color cRgb2 = hsbToRgbColor(colConverted); | |
fill(cRgb2); | |
float diam = 5+random(15); | |
ellipse(width/2+random(-300, 300), height/2+random(-300, 300), diam, diam); | |
} | |
fill(cRgb); | |
ellipse(width/2, height/2, 200, 200); | |
} | |
void mousePressed() { | |
noLoop(); | |
} | |
void mouseReleased() { | |
loop(); | |
} | |
// _ _ _ _ _ _ _ _ _ _ _ _ | |
// Type Float array, avec valeurs HSB normalisées, de 0.0 à 1.0 | |
float [] rgbToHsbFloat(color cRgb) { | |
int r = (cRgb >> 16) & 0xFF; | |
int g = (cRgb >> 8) & 0xFF; | |
int b = cRgb & 0xFF; | |
float[] hsb = new float[3]; | |
Color.RGBtoHSB(r, g, b, hsb); | |
return hsb; | |
} | |
// Type color avec valeurs RGB normalisées, de 0.0 à 1.0 | |
color hsbToRgbColor(float [] cHsb) { | |
color rgb = Color.HSBtoRGB(cHsb[0], cHsb[1], cHsb[2]); | |
return rgb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Capture d’un rendu. Le cercle au centre contient la couleur de référence (#FF3B74). Les points environnants sont colorés avec une teinte, une saturation et un clarté plus ou moins similaires. Au plus, 20% d’écart avec la couleur source.