我遇到过屏幕保护程序的一些开源代码,想了解如何修改颜色副本的颜色数组以生成 RED 色调而不是 GREEN < / strong>帐篷
以下是作者用于设置绿色的代码:
// 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;
}
}
}
答案 0 :(得分:1)
从代码中可以看出:
colorArray[... + 1] = green
colorArray[... + 0] = red
colorArray[... + 2] = blue
colorArray[... + 3] = alpha
(因为......部分总是4的倍数)
因此,只需在任何地方交换colorArray[... + 1]
和colorArray[... + 0]
,您就可以将其更改为红色。将变量名称g
更改为r
将有助于未来的理智。