|
| 1 | +// CLEO5 example script |
| 2 | +// Sanny Builder 4 |
| 3 | +// mode: GTA SA (v1.0 - SBL) |
| 4 | +{$CLEO .cs} |
| 5 | + |
| 6 | +script_name {name} 'colgrad' |
| 7 | + |
| 8 | +const Panel_Count = 120 // limit is 128 per script |
| 9 | +const Panel_Width = 5.2 |
| 10 | + |
| 11 | +int lastPanelIdx = Panel_Count - 1 |
| 12 | +int middleKeyIdx |
| 13 | +int colorStart[3] // red, green, blue |
| 14 | +int colormiddle[3] // red, green, blue |
| 15 | +int colorEnd[3] // red, green, blue |
| 16 | + |
| 17 | +int iTmp |
| 18 | +float fTmp |
| 19 | + |
| 20 | +TimerA = 3000 |
| 21 | +while true |
| 22 | + wait {time} 0 |
| 23 | + |
| 24 | + // randomize colors every 3 seconds |
| 25 | + if |
| 26 | + TimerA > 3000 |
| 27 | + then |
| 28 | + colorStart[0] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 29 | + colorStart[1] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 30 | + colorStart[2] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 31 | + |
| 32 | + colormiddle[0] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 33 | + colormiddle[1] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 34 | + colormiddle[2] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 35 | + |
| 36 | + colorEnd[0] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 37 | + colorEnd[1] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 38 | + colorEnd[2] = generate_random_int_in_range {min} 0x00 {max} 0xFF |
| 39 | + |
| 40 | + middleKeyIdx = generate_random_int_in_range {min} 0 {max} lastPanelIdx |
| 41 | + |
| 42 | + TimerA = 0 |
| 43 | + end |
| 44 | + |
| 45 | + // draw on screen |
| 46 | + use_text_commands {state} true |
| 47 | + |
| 48 | + float posX = 10.0 // start pos |
| 49 | + int i = 0 |
| 50 | + while i < Panel_Count |
| 51 | + // select color |
| 52 | + int color[3] |
| 53 | + switch i |
| 54 | + case 0 // start panel |
| 55 | + color[0] = colorStart[0] |
| 56 | + color[1] = colorStart[1] |
| 57 | + color[2] = colorStart[2] |
| 58 | + |
| 59 | + case middleKeyIdx // middle color |
| 60 | + color[0] = colormiddle[0] |
| 61 | + color[1] = colormiddle[1] |
| 62 | + color[2] = colormiddle[2] |
| 63 | + |
| 64 | + case lastPanelIdx |
| 65 | + color[0] = colorEnd[0] |
| 66 | + color[1] = colorEnd[1] |
| 67 | + color[2] = colorEnd[2] |
| 68 | + |
| 69 | + default // for other panels we have to calculate blend color |
| 70 | + float progress |
| 71 | + if |
| 72 | + i < middleKeyIdx |
| 73 | + then |
| 74 | + // blending start to middle |
| 75 | + progress =# i // current |
| 76 | + fTmp =# middleKeyIdx // total |
| 77 | + progress /= fTmp // 0.0 - 1.0 range |
| 78 | + |
| 79 | + color[0] = LERP_INT(colorStart[0], colormiddle[0], progress) // red |
| 80 | + color[1] = LERP_INT(colorStart[1], colormiddle[1], progress) // green |
| 81 | + color[2] = LERP_INT(colorStart[2], colormiddle[2], progress) // blue |
| 82 | + else |
| 83 | + // blending middle to end |
| 84 | + iTmp = i - middleKeyIdx |
| 85 | + progress =# iTmp // current |
| 86 | + |
| 87 | + iTmp = lastPanelIdx - middleKeyIdx |
| 88 | + fTmp =# iTmp // total |
| 89 | + |
| 90 | + progress /= fTmp // 0.0 - 1.0 range |
| 91 | + |
| 92 | + color[0] = LERP_INT(colormiddle[0], colorEnd[0], progress) // red |
| 93 | + color[1] = LERP_INT(colormiddle[1], colorEnd[1], progress) // green |
| 94 | + color[2] = LERP_INT(colormiddle[2], colorEnd[2], progress) // blue |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + // draw |
| 99 | + if or |
| 100 | + i == 0 // start panel |
| 101 | + i == middleKeyIdx |
| 102 | + i == lastPanelIdx |
| 103 | + then |
| 104 | + draw_rect {pos} posX 240.0 {size} Panel_Width 80.0 {rgb} color[0] color[1] color[2] {alpha} 240 // tall panel |
| 105 | + else |
| 106 | + draw_rect {pos} posX 240.0 {size} Panel_Width 40.0 {rgb} color[0] color[1] color[2] {alpha} 240 // regular panel |
| 107 | + end |
| 108 | + |
| 109 | + // prepare next |
| 110 | + i += 1 |
| 111 | + posX += Panel_Width |
| 112 | + end |
| 113 | + |
| 114 | +end |
| 115 | +terminate_this_custom_script |
| 116 | + |
| 117 | + |
| 118 | +// linear interpolation (or extrapolation) of two float values |
| 119 | +function LERP_FLOAT(valueA :float, valueB :float, progress :float): float |
| 120 | + float invProgress = 1.0 |
| 121 | + invProgress -= progress |
| 122 | + |
| 123 | + valueA *= invProgress |
| 124 | + valueB *= progress |
| 125 | + |
| 126 | + float result |
| 127 | + result += valueA |
| 128 | + result += valueB |
| 129 | + |
| 130 | + return result |
| 131 | +end |
| 132 | + |
| 133 | + |
| 134 | +// linear interpolation (or extrapolation) of two integer values |
| 135 | +function LERP_INT(valueA: int, valueB: int, progress: float): int |
| 136 | + float aF =# valueA // to float |
| 137 | + float bF =# valueB // to float |
| 138 | + |
| 139 | + float fResult = LERP_FLOAT(aF, bF, progress) |
| 140 | + |
| 141 | + int result =# fResult // to integer |
| 142 | + |
| 143 | + return result |
| 144 | +end |
0 commit comments