今早打开电脑,发现群里昨晚的留言,是关于如何在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种中的任意一种。

 

相关文章:

  • 2021-12-02
  • 2022-01-15
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2022-02-27
  • 2021-12-04
  • 2021-12-05
  • 2021-12-05
  • 2021-04-28
  • 2021-10-27
相关资源
相似解决方案