LOG helps find a power - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16) +--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13) +---- Forum: Keyword of the Day! (https://qb64phoenix.com/forum/forumdisplay.php?fid=49) +---- Thread: LOG helps find a power (/showthread.php?tid=3141) |
LOG helps find a power - bplus - 10-19-2024 LOG came in handy for me recently when I was reducing LOC (Lines Of Code) for Classic 2048 Game from Dav's version. He had all these lines to create a shaded Backcolor for a tile, to get darker as value gets higher: Code: (Select All) Select Case board(x, y) I said to myself if I didn't mind going color blind a bit, I could shade tiles darker by finding the power of 2 that the Board(x, y) value and do bg& in shades of grey: _RGB32(OneValue0to255) = shade of grey Code: (Select All) If Board(x, y) Then power = Log(Board(x, y)) / Log(2) Else power = 0 Mission accomplished! Here is a little formula for getting Power in X of Y. In example above, what power of 2 is Board(x, y) value? PowerX = Log(Y)/Log(X) Check if Y is 0 first though to avoid error. RE: LOG helps find a power - grymmjack - 10-24-2024 Thanks for sharing @bplus this is great stuff. https://mathinsight.org/logarithm_basics helped explain more about LOG Going to re-review your code after grokking all of this. Also, the 17 * power - this is shade of gray how? _RGB32 with one argument makes a gray? or I guess uses the 1 arg for all places in the R G B ? RE: LOG helps find a power - bplus - 10-24-2024 Yes, one argument for _RGB32(X) makes a shade of gray, just like _RGB32(X, X, X) would be. |