1

我遇到了一些用于屏幕保护程序的开源代码,并想了解如何修改 Color Verticies 的颜色数组以生成红色色调而不是绿色帐篷

这是作者用来设置绿色的代码:

 // Compute the new state of the color vertices
- (void) computeColorVertices
{
   int i,maxi,c;
   GLfloat g, gstep, cursorglow;

   c = 0; // To suppress spurious warning
   gstep = stripParams.colorCycleSpeed;
   // First, run down the strip cycling colors to bright then back to dark
   g = startColor;
   maxi = cursorDrawing ? cursorPos : stripSize;
   for (i=0; i < maxi; i++) {
      for (c = 0; c < 4; c++) {
         // Some shade of green if cell is not empty
         colorArray[16*i + 4*c + 1] = (cellState[i] == 0) ? 0.0 : g;
         // Cells which are very bright are slightly whitened
         colorArray[16*i + 4*c + 0] = ((g > 0.7) && (cellState[i] != 0)) ? (g - 0.6) : 0.0;
         colorArray[16*i + 4*c + 2] = ((g > 0.7) && (cellState[i] != 0)) ? (g - 0.6) : 0.0;
         // Transparent if cell is empty, otherwise opaque
         colorArray[16*i + 4*c + 3] = (cellState[i] == 0) ? 0.0 : 1.0;
      }
      g += gstep;
      if (g > 1.0) {
         g = 0.2;
      }
   }
   // Cycle the start color used above, to make the colors appear to fall
   startColor -= stripParams.colorFallSpeed;
   if (startColor < 0.2) {
      startColor = 1.0;
   }

   // If the cursor's drawing, work up from its position making sure the cells aren't too dark
   if (cursorDrawing) {
      maxi = cursorPos - 1;
      cursorglow = 0.8;
      for (i = maxi; i >= 0 && cursorglow > 0.2; i--) {
      // If there's some cursor-imparted glow left, use it
         if (colorArray[16*i + 4*c + 1] < cursorglow) {
            for (c = 0; c < 4; c++) {
               // Some shade of green if cell is not empty
               colorArray[16*i + 4*c + 1] = (cellState[i] == 0) ? 0.0 : cursorglow;
               // Cells which are very bright are slightly whitened
               colorArray[16*i + 4*c + 0] = ((cursorglow > 0.7) && (cellState[i] != 0)) ? (cursorglow - 0.6) : 0.0;
               colorArray[16*i + 4*c + 2] = ((cursorglow > 0.7) && (cellState[i] != 0)) ? (cursorglow - 0.6) : 0.0;
               // Transparent if cell is empty, otherwise opaque
               colorArray[16*i + 4*c + 3] = (cellState[i] == 0) ? 0.0 : 1.0;
            }
         }
         cursorglow -= gstep;
      }
   }
}
4

1 回答 1

2

从代码看来:

colorArray[... + 1] = green
colorArray[... + 0] = red
colorArray[... + 2] = blue
colorArray[... + 3] = alpha

(因为 ... 部分始终是 4 的倍数)

因此,您应该能够通过简单地交换colorArray[... + 1]colorArray[... + 0]到处将其更改为红色。将变量名称更改gr将有助于未来的理智。

于 2013-08-28T16:29:21.510 回答