Color Math: blendColor() vs get()
in
Programming Questions
•
11 months ago
I'm trying to better understand the underlying mechanisms behind blending colors. This discussion
here is informative.
Processing provides the build-in blendColor method. However, when I print the results of blended color values, and then use get() to verify, there are some discrepancies. These tend to be minor, but I'm curious as to their origin. Is it a rounding error, or is my code problematic? I have tried both BLEND and ADD modes.
Here is the test code:
Processing provides the build-in blendColor method. However, when I print the results of blended color values, and then use get() to verify, there are some discrepancies. These tend to be minor, but I'm curious as to their origin. Is it a rounding error, or is my code problematic? I have tried both BLEND and ADD modes.
Here is the test code:
- color colorBG; // Colors must be assigned after colorMode.
- color color1;
- color color2;
- void setup() {
- size(200, 200);
- noStroke();
- // colorMode(HSB); // See if this changes things.
- colorBG = color(0);
- color1 = color(255, 10, 10, 100);
- color2 = color(10, 10, 255, 100);
- // Using the Processing function to get the resulting color (in hex). Parameter order is important.
- println("Click the mouse to confirm these blended color values:\n");
- println("Color1 over BG color: " + hex(blendColor(colorBG, color1, BLEND)));
- println("Color2 over BG color: " + hex(blendColor(colorBG, color2, BLEND)));
- color color3 = blendColor(colorBG, color1, BLEND);
- println("Color2, Color1, BG: " + hex(blendColor(#4E0000, color2, BLEND)));
- println("\n");
- }
- void draw() {
- background(colorBG);
- fill(color1);
- rect(0, 0, 150, 150);
- fill(color2);
- rect(50, 50, width, height);
- }
- void mousePressed() {
- println("Mouse location color: " + hex(get(mouseX, mouseY)));
- }
1