Unexpected behavour using hex color codes.
in
Programming Questions
•
2 years ago
I am playing with some of the example code from the progaming handbook and noticed something strange someone may be able to help with. I am seeing differing behavour in a sketch when I use the hex representaion of a color rather than the rgb representation. This is based of of example 37-04 in the typogrophy II section.
This code works fine:
PFont font;
int opacity = 0;
int direction = 1;
void setup() {
size(100, 100);
font = loadFont("EurekaSmallCaps-36.vlw");
textFont(font);
}
void draw() {
background(204);
opacity += 2 * direction;
if ((opacity < 0) || (opacity > 255)) {
direction = -direction;
}
fill(148, 73, 232, opacity);
text("fade", 4, 60);
}
background(204);
opacity += 2 * direction;
if ((opacity < 0) || (opacity > 255)) {
direction = -direction;
}
fill(148, 73, 232, opacity);
text("fade", 4, 60);
}
But when I change the representation of the color from RGB (148,73,232) to the hex representation (#944BED) I get a choppy result. Specificly I am seeing the text “fade” fade to zero opacity and then briefly flash with full opacity before fading back up again. I am seeing a another minor fash as well as the opacity increases. Anyone able to repeat and confirm this behaviour? Anyone see anything I am doing incorrectly? Following is the code I am seeing this in:
PFont font;
int opacity = 0;
int direction = 1;
int opacity = 0;
int direction = 1;
void setup() {
size(100, 100);
font = loadFont("EurekaSmallCaps-36.vlw");
textFont(font);
}
size(100, 100);
font = loadFont("EurekaSmallCaps-36.vlw");
textFont(font);
}
void draw() {
background(204);
opacity += 2 * direction;
if ((opacity < 0) || (opacity > 255)) {
direction = -direction;
}
fill(#944BED, opacity);
text("fade", 4, 60);
}
background(204);
opacity += 2 * direction;
if ((opacity < 0) || (opacity > 255)) {
direction = -direction;
}
fill(#944BED, opacity);
text("fade", 4, 60);
}
1