今早打開電腦,發現群里昨晚的留言,是關於如何在Processing中使顏色漸變的,我總結了一下,無非是以下3種:
1、用HSB色系
colorMode(HSB,360,255,100);
fill(x,255,100);
x++;
2、用lerpColor()
color a = color(255, 0, 0);
color b = color(0, 255, 0);
color c = lerpColor(a, b, map(mouseX, 0, width, 0, 1));
fill(c);
rect(0, 0, width, height);
3、位運算 bit operation
int a = (argb >> 24) & 0xFF;
int r = (argb >> 16) & 0xFF; // Faster way of getting red(argb)
int g = (argb >> 8) & 0xFF; // Faster way of getting green(argb)
int b = argb & 0xFF; // Faster way of getting blue(argb)
fill(r, g, b, a);
rect(30, 20, 55, 55);
總的來說,Processing中做顏色漸變還是比較好做的,大家可以根據作品需要自行選用以上3種中的任意一種。