Tetrachromat wrote: ↑Tue Nov 22, 2022 9:23 pm
LUA 5.3 Reference Manual is your friend. Actually it calls that 'floor division'.
Floor division (//) is a division that rounds the quotient towards minus infinity, that is, the floor of the division of its operands.
Paul,
I did some playing around with what you say. I think there is a bit more formatting required.
The goal is to get 4 two digit hex codes pairs. 00 -> FF from a variable input of 0 to 1. Each pair is to represent RBGA (Red,Blue,Green,Opacity) channels in the color hex code.
I found your // division does not round hex values. If you run this code you will see that the string does not round per RGBA Chanel. You get more than the 8 digit string length.
#FFFF1FE1FE
A good suggestion but not quite the answer
Basic Indications ...
hex color #00000000 is transparent
hex color #000000ff is black.
hex color #0000007f is 50% black. GREY.
When running this code you will note that the _fill() #0000007F is a fixed 8 character, hex color code format. The last pair determines the opacity. What the OP wants is to change the 0 to 1 value to a valid hex value. Like 7F or 66 or some other hex value .
Oh I changed the last two characters in the OP string from FF to %02x else FF will be fixed.
Code: Select all
brightness_lines =1
brightness_lines2 =1
gColorPrint = string.format("#%02X%02X%02X%02X", 255*brightness_lines // 1, 255*brightness_lines // 1,255*brightness_lines // 0.5, 255*brightness_lines2 //0.5)
print(gColorPrint)
canvas_add(10,10,400,400,function()
_rect(10,10,200,200)
_fill("#0000007f")
end)
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card