Talk:Color Theory/Color gradient

GiveRainbowColor
Unfortunately each of the GiveRainbowColor function implementations contains a theoretical "bug".

The issue is relating to calculating of the remainder portion of the variable color. The original delphi version of the GiveRainbowColor function looks good, gives an acceptable value, because of the application of the round function, which one rounds up the value to the next integer. But this is just a workaround of the original bug.

The c and c++ versions are using int which one truncates the value to the base integer value. Therefore variable mt (or t) never gets the top or bottom limits of the valid interval [0..255]. Because of the interval [0..q] contains q+1 values, we have to use the element counts of the valid values as multiplier rather. So, rounding function is not necessary, and 0xFF value is wrong. Right value is 0x100 or 256. (the series will convergate to 256 but reach only 255, because fraction[m] part will never gets 1, this is the nature of the fraction itself).

Typo: "direct outoput" -o

Bfarago (discuss • contribs) 04:22, 30 July 2015 (UTC)

OK. You are wellcome to improve this.

Here is Pascal version :

and output :

a@zalman:~/pascal/first$ fpc f.pas Free Pascal Compiler version 2.6.4 [2014/03/03] for x86_64 Copyright (c) 1993-2014 by Florian Klaempfl and others Target OS: Linux for x86-64 Compiling f.pas Linking f /usr/bin/ld: warning: link.res contains output sections; did you forget -T? 79 lines compiled, 0.0 sec a@zalman:~/pascal/first$ ./f i = 0, R = 255 , G = 0 , B = 0 i = 1, R = 255 , G = 6 , B = 0 i = 2, R = 255 , G = 12 , B = 0 i = 3, R = 255 , G = 18 , B = 0 i = 4, R = 255 , G = 24 , B = 0 i = 5, R = 255 , G = 30 , B = 0 i = 6, R = 255 , G = 36 , B = 0 i = 7, R = 255 , G = 42 , B = 0 i = 8, R = 255 , G = 48 , B = 0 i = 9, R = 255 , G = 54 , B = 0 i = 10, R = 255 , G = 60 , B = 0 i = 11, R = 255 , G = 66 , B = 0 i = 12, R = 255 , G = 72 , B = 0 i = 13, R = 255 , G = 78 , B = 0 i = 14, R = 255 , G = 84 , B = 0 i = 15, R = 255 , G = 90 , B = 0 i = 16, R = 255 , G = 96 , B = 0 i = 17, R = 255 , G = 102 , B = 0 i = 18, R = 255 , G = 108 , B = 0 i = 19, R = 255 , G = 114 , B = 0 i = 20, R = 255 , G = 120 , B = 0 i = 21, R = 255 , G = 126 , B = 0 i = 22, R = 255 , G = 131 , B = 0 i = 23, R = 255 , G = 137 , B = 0 i = 24, R = 255 , G = 143 , B = 0 i = 25, R = 255 , G = 149 , B = 0 i = 26, R = 255 , G = 155 , B = 0 i = 27, R = 255 , G = 161 , B = 0 i = 28, R = 255 , G = 167 , B = 0 i = 29, R = 255 , G = 173 , B = 0 i = 30, R = 255 , G = 179 , B = 0 i = 31, R = 255 , G = 185 , B = 0 i = 32, R = 255 , G = 191 , B = 0 i = 33, R = 255 , G = 197 , B = 0 i = 34, R = 255 , G = 203 , B = 0 i = 35, R = 255 , G = 209 , B = 0 i = 36, R = 255 , G = 215 , B = 0 i = 37, R = 255 , G = 221 , B = 0 i = 38, R = 255 , G = 227 , B = 0 i = 39, R = 255 , G = 233 , B = 0 i = 40, R = 255 , G = 239 , B = 0 i = 41, R = 255 , G = 245 , B = 0 i = 42, R = 255 , G = 251 , B = 0 i = 43, R = 253 , G = 255 , B = 0 i = 44, R = 247 , G = 255 , B = 0 i = 45, R = 241 , G = 255 , B = 0 i = 46, R = 235 , G = 255 , B = 0 i = 47, R = 229 , G = 255 , B = 0 i = 48, R = 223 , G = 255 , B = 0 i = 49, R = 217 , G = 255 , B = 0 i = 50, R = 211 , G = 255 , B = 0 i = 51, R = 205 , G = 255 , B = 0 i = 52, R = 199 , G = 255 , B = 0 i = 53, R = 193 , G = 255 , B = 0 i = 54, R = 187 , G = 255 , B = 0 i = 55, R = 181 , G = 255 , B = 0 i = 56, R = 175 , G = 255 , B = 0 i = 57, R = 169 , G = 255 , B = 0 i = 58, R = 163 , G = 255 , B = 0 i = 59, R = 157 , G = 255 , B = 0 i = 60, R = 151 , G = 255 , B = 0 i = 61, R = 145 , G = 255 , B = 0 i = 62, R = 139 , G = 255 , B = 0 i = 63, R = 133 , G = 255 , B = 0 i = 64, R = 127 , G = 255 , B = 0 i = 65, R = 122 , G = 255 , B = 0 i = 66, R = 116 , G = 255 , B = 0 i = 67, R = 110 , G = 255 , B = 0 i = 68, R = 104 , G = 255 , B = 0 i = 69, R = 98 , G = 255 , B = 0 i = 70, R = 92 , G = 255 , B = 0 i = 71, R = 86 , G = 255 , B = 0 i = 72, R = 80 , G = 255 , B = 0 i = 73, R = 74 , G = 255 , B = 0 i = 74, R = 68 , G = 255 , B = 0 i = 75, R = 62 , G = 255 , B = 0 i = 76, R = 56 , G = 255 , B = 0 i = 77, R = 50 , G = 255 , B = 0 i = 78, R = 44 , G = 255 , B = 0 i = 79, R = 38 , G = 255 , B = 0 i = 80, R = 32 , G = 255 , B = 0 i = 81, R = 26 , G = 255 , B = 0 i = 82, R = 20 , G = 255 , B = 0 i = 83, R = 14 , G = 255 , B = 0 i = 84, R = 8 , G = 255 , B = 0 i = 85, R = 2 , G = 255 , B = 0 i = 86, R = 0 , G = 255 , B = 4 i = 87, R = 0 , G = 255 , B = 10 i = 88, R = 0 , G = 255 , B = 16 i = 89, R = 0 , G = 255 , B = 22 i = 90, R = 0 , G = 255 , B = 28 i = 91, R = 0 , G = 255 , B = 34 i = 92, R = 0 , G = 255 , B = 40 i = 93, R = 0 , G = 255 , B = 46 i = 94, R = 0 , G = 255 , B = 52 i = 95, R = 0 , G = 255 , B = 58 i = 96, R = 0 , G = 255 , B = 64 i = 97, R = 0 , G = 255 , B = 70 i = 98, R = 0 , G = 255 , B = 76 i = 99, R = 0 , G = 255 , B = 82 i = 100, R = 0 , G = 255 , B = 88 i = 101, R = 0 , G = 255 , B = 94 i = 102, R = 0 , G = 255 , B = 100 i = 103, R = 0 , G = 255 , B = 106 i = 104, R = 0 , G = 255 , B = 112 i = 105, R = 0 , G = 255 , B = 118 i = 106, R = 0 , G = 255 , B = 124 i = 107, R = 0 , G = 255 , B = 129 i = 108, R = 0 , G = 255 , B = 135 i = 109, R = 0 , G = 255 , B = 141 i = 110, R = 0 , G = 255 , B = 147 i = 111, R = 0 , G = 255 , B = 153 i = 112, R = 0 , G = 255 , B = 159 i = 113, R = 0 , G = 255 , B = 165 i = 114, R = 0 , G = 255 , B = 171 i = 115, R = 0 , G = 255 , B = 177 i = 116, R = 0 , G = 255 , B = 183 i = 117, R = 0 , G = 255 , B = 189 i = 118, R = 0 , G = 255 , B = 195 i = 119, R = 0 , G = 255 , B = 201 i = 120, R = 0 , G = 255 , B = 207 i = 121, R = 0 , G = 255 , B = 213 i = 122, R = 0 , G = 255 , B = 219 i = 123, R = 0 , G = 255 , B = 225 i = 124, R = 0 , G = 255 , B = 231 i = 125, R = 0 , G = 255 , B = 237 i = 126, R = 0 , G = 255 , B = 243 i = 127, R = 0 , G = 255 , B = 249 i = 128, R = 0 , G = 255 , B = 255 i = 129, R = 0 , G = 249 , B = 255 i = 130, R = 0 , G = 243 , B = 255 i = 131, R = 0 , G = 237 , B = 255 i = 132, R = 0 , G = 231 , B = 255 i = 133, R = 0 , G = 225 , B = 255 i = 134, R = 0 , G = 219 , B = 255 i = 135, R = 0 , G = 213 , B = 255 i = 136, R = 0 , G = 207 , B = 255 i = 137, R = 0 , G = 201 , B = 255 i = 138, R = 0 , G = 195 , B = 255 i = 139, R = 0 , G = 189 , B = 255 i = 140, R = 0 , G = 183 , B = 255 i = 141, R = 0 , G = 177 , B = 255 i = 142, R = 0 , G = 171 , B = 255 i = 143, R = 0 , G = 165 , B = 255 i = 144, R = 0 , G = 159 , B = 255 i = 145, R = 0 , G = 153 , B = 255 i = 146, R = 0 , G = 147 , B = 255 i = 147, R = 0 , G = 141 , B = 255 i = 148, R = 0 , G = 135 , B = 255 i = 149, R = 0 , G = 129 , B = 255 i = 150, R = 0 , G = 124 , B = 255 i = 151, R = 0 , G = 118 , B = 255 i = 152, R = 0 , G = 112 , B = 255 i = 153, R = 0 , G = 106 , B = 255 i = 154, R = 0 , G = 100 , B = 255 i = 155, R = 0 , G = 94 , B = 255 i = 156, R = 0 , G = 88 , B = 255 i = 157, R = 0 , G = 82 , B = 255 i = 158, R = 0 , G = 76 , B = 255 i = 159, R = 0 , G = 70 , B = 255 i = 160, R = 0 , G = 64 , B = 255 i = 161, R = 0 , G = 58 , B = 255 i = 162, R = 0 , G = 52 , B = 255 i = 163, R = 0 , G = 46 , B = 255 i = 164, R = 0 , G = 40 , B = 255 i = 165, R = 0 , G = 34 , B = 255 i = 166, R = 0 , G = 28 , B = 255 i = 167, R = 0 , G = 22 , B = 255 i = 168, R = 0 , G = 16 , B = 255 i = 169, R = 0 , G = 10 , B = 255 i = 170, R = 0 , G = 4 , B = 255 i = 171, R = 2 , G = 0 , B = 255 i = 172, R = 8 , G = 0 , B = 255 i = 173, R = 14 , G = 0 , B = 255 i = 174, R = 20 , G = 0 , B = 255 i = 175, R = 26 , G = 0 , B = 255 i = 176, R = 32 , G = 0 , B = 255 i = 177, R = 38 , G = 0 , B = 255 i = 178, R = 44 , G = 0 , B = 255 i = 179, R = 50 , G = 0 , B = 255 i = 180, R = 56 , G = 0 , B = 255 i = 181, R = 62 , G = 0 , B = 255 i = 182, R = 68 , G = 0 , B = 255 i = 183, R = 74 , G = 0 , B = 255 i = 184, R = 80 , G = 0 , B = 255 i = 185, R = 86 , G = 0 , B = 255 i = 186, R = 92 , G = 0 , B = 255 i = 187, R = 98 , G = 0 , B = 255 i = 188, R = 104 , G = 0 , B = 255 i = 189, R = 110 , G = 0 , B = 255 i = 190, R = 116 , G = 0 , B = 255 i = 191, R = 122 , G = 0 , B = 255 i = 192, R = 128 , G = 0 , B = 255 i = 193, R = 133 , G = 0 , B = 255 i = 194, R = 139 , G = 0 , B = 255 i = 195, R = 145 , G = 0 , B = 255 i = 196, R = 151 , G = 0 , B = 255 i = 197, R = 157 , G = 0 , B = 255 i = 198, R = 163 , G = 0 , B = 255 i = 199, R = 169 , G = 0 , B = 255 i = 200, R = 175 , G = 0 , B = 255 i = 201, R = 181 , G = 0 , B = 255 i = 202, R = 187 , G = 0 , B = 255 i = 203, R = 193 , G = 0 , B = 255 i = 204, R = 199 , G = 0 , B = 255 i = 205, R = 205 , G = 0 , B = 255 i = 206, R = 211 , G = 0 , B = 255 i = 207, R = 217 , G = 0 , B = 255 i = 208, R = 223 , G = 0 , B = 255 i = 209, R = 229 , G = 0 , B = 255 i = 210, R = 235 , G = 0 , B = 255 i = 211, R = 241 , G = 0 , B = 255 i = 212, R = 247 , G = 0 , B = 255 i = 213, R = 253 , G = 0 , B = 255 i = 214, R = 255 , G = 0 , B = 251 i = 215, R = 255 , G = 0 , B = 245 i = 216, R = 255 , G = 0 , B = 239 i = 217, R = 255 , G = 0 , B = 233 i = 218, R = 255 , G = 0 , B = 227 i = 219, R = 255 , G = 0 , B = 221 i = 220, R = 255 , G = 0 , B = 215 i = 221, R = 255 , G = 0 , B = 209 i = 222, R = 255 , G = 0 , B = 203 i = 223, R = 255 , G = 0 , B = 197 i = 224, R = 255 , G = 0 , B = 191 i = 225, R = 255 , G = 0 , B = 185 i = 226, R = 255 , G = 0 , B = 179 i = 227, R = 255 , G = 0 , B = 173 i = 228, R = 255 , G = 0 , B = 167 i = 229, R = 255 , G = 0 , B = 161 i = 230, R = 255 , G = 0 , B = 155 i = 231, R = 255 , G = 0 , B = 149 i = 232, R = 255 , G = 0 , B = 143 i = 233, R = 255 , G = 0 , B = 137 i = 234, R = 255 , G = 0 , B = 131 i = 235, R = 255 , G = 0 , B = 126 i = 236, R = 255 , G = 0 , B = 120 i = 237, R = 255 , G = 0 , B = 114 i = 238, R = 255 , G = 0 , B = 108 i = 239, R = 255 , G = 0 , B = 102 i = 240, R = 255 , G = 0 , B = 96 i = 241, R = 255 , G = 0 , B = 90 i = 242, R = 255 , G = 0 , B = 84 i = 243, R = 255 , G = 0 , B = 78 i = 244, R = 255 , G = 0 , B = 72 i = 245, R = 255 , G = 0 , B = 66 i = 246, R = 255 , G = 0 , B = 60 i = 247, R = 255 , G = 0 , B = 54 i = 248, R = 255 , G = 0 , B = 48 i = 249, R = 255 , G = 0 , B = 42 i = 250, R = 255 , G = 0 , B = 36 i = 251, R = 255 , G = 0 , B = 30 i = 252, R = 255 , G = 0 , B = 24 i = 253, R = 255 , G = 0 , B = 18 i = 254, R = 255 , G = 0 , B = 12 i = 255, R = 255 , G = 0 , B = 6 a@zalman:~/pascal/first$

Here is c program :

Here is C++ program. Output is not good also ) :

--Adam majewski (discuss • contribs) 18:08, 30 July 2015 (UTC)