Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LOG helps find a power
#1
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)
    Case 2: bg& = _RGB(239, 229, 218)
    Case 4: bg& = _RGB(236, 224, 198)
    Case 8: bg& = _RGB(241, 177, 121)
    Case 16: bg& = _RGB(236, 141, 84)
    Case 32: bg& = _RGB(247, 124, 95)
    Case 64: bg& = _RGB(233, 89, 55)
    Case 128: bg& = _RGB(242, 217, 107)
    Case 256: bg& = _RGB(238, 205, 96)
    Case 512: bg& = _RGB(238, 205, 96)
    Case 1024: bg& = _RGB(238, 205, 96)
    Case 2048: bg& = _RGB(238, 205, 96)
    Case 4096: bg& = _RGB(121, 184, 226)
    Case 8192: bg& = _RGB(121, 184, 226)
    Case 16384: bg& = _RGB(121, 184, 226)
    Case 32768: bg& = _RGB(60, 64, 64)
    Case Else: bg& = _RGB(204, 192, 180)
End Select

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
bg& = _RGB32(255 - 17 * power) ' =set to shade of grey, the higher the value the darker

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.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
LOG helps find a power - by bplus - 10-19-2024, 03:30 PM
RE: LOG helps find a power - by grymmjack - 10-24-2024, 08:10 AM
RE: LOG helps find a power - by bplus - 10-24-2024, 01:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  DAY 008: LOG SMcNeill 9 2,135 11-19-2022, 06:36 AM
Last Post: luke

Forum Jump:


Users browsing this thread: 1 Guest(s)