|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Fri Jul 30, 2021 12:32 pm Post subject: Calculate the opposite of color! |
|
|
The title can be a little complicated.
I will ask with code below.
When a panel color is dark, the panel text must be light,
or when the panel color is light, the panel text should be dark.
How to calculate this, I am puzzled.
here is the code i use:
Code: | if form then form.destroy() form = nil end
form = createForm()
form.Position=poDesktopCenter
Pnl2=createPanel(form)
Pnl2.Caption="+" Pnl2.Font.Size=40
local clr1=65407 --16776960 --16711680 --
Pnl2.Color=clr1
if Pnl2.Color > 0xFFF000 or Pnl2.Color > 8388607 then
Pnl2.Font.Color=16777215
else
Pnl2.Font.Color=0
end
|
|
|
Back to top |
|
|
DanyDollaro Master Cheater Reputation: 3
Joined: 01 Aug 2019 Posts: 334
|
Posted: Fri Jul 30, 2021 1:15 pm Post subject: |
|
|
To get the complementar color you can just use the "complementar to one" operator:
Code: | clr = 0x00FF00FF
print(~clr) |
The output will be -16711936, in hexadecimal 0xFF00FF00.
EDIT: I did some tests with the lua engine, and I noticed that using that operator the color will not be applied as the most significant bytes will be set to 0xFF making the color invalid (i think), and given the absence of the bitwise operators you should do something like this:
Code: | clr = 0xFFFFFF
print(~clr - 0xFFFFFFFFFF000000) |
In this case the output will be 0.
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Fri Jul 30, 2021 3:37 pm Post subject: |
|
|
Here is a little something to invert RGB
Code: |
function invertRGB(r,g,b)
r = r * -1 + 255
g = g * -1 + 255
b = b * -1 + 255
print('Hex : ' .. string.format('0x%X%X%X',r,g,b))
print('RGB : ' ..b..','..g..','..r)
return r,g,b
end
invertRGB(100,255,25)
|
I hope this puts you in the right direction.
Last edited by LeFiXER on Fri Jul 30, 2021 5:49 pm; edited 1 time in total |
|
Back to top |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Fri Jul 30, 2021 4:42 pm Post subject: |
|
|
I have a color code that I am currently using.
It can be used straight or reversed.
Code: | function BGRToHex(blue, green, red)
if(red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) then
return nil
end
return string.format("0x%.2X%.2X%.2X", blue,green,red)
end
---------------------------------------------------
clr=16477777
b,g,r = clr >> 16 & 0xff, clr >> 8 & 0xff, clr & 0xff
col = BGRToHex(b,g,r)
print("Color: "..tostring(col))
col1 = BGRToHex(r,g,b)
print("Color1: "..tostring(col1))
|
As I wrote in the statement; Don't get hung up on the title, the question is in the description!
Code: | if form then form.destroy() form = nil end
form = createForm()
form.Position=poDesktopCenter
Pnl2=createPanel(form)
Pnl2.Caption="+" Pnl2.Font.Size=40
local clr1=65407 --16776960 --16711680 --
Pnl2.Color=clr1
if Pnl2.Color > 0xFFF000 or Pnl2.Color > 8388607 then
Pnl2.Font.Color=16777215
else
Pnl2.Font.Color=0
end |
3 color samples are given above.
Question: If the panel color is dark, the Panel description (Font) must be light.
Or, if the panel color is light, the panel description should be dark.
How can I provide this color contrast?
Sample; In this color font "16776960" should be dark (black), but the code makes the font white.
EDIT: Extended.
Note the yellow box. The "+" is too dark to be visible.
The test code I created is incomplete.
How can I provide all the opposite?
Code: | if form then form.destroy() form = nil end
form = createForm()
form.Position=poDesktopCenter
Pnl2=createPanel(form)
Pnl2.Caption="+" Pnl2.Font.Size=40
Pnl1=createPanel(form)
Pnl1.Caption="+" Pnl1.Font.Size=40 Pnl1.Top=60
Pnl3=createPanel(form)
Pnl3.Caption="+" Pnl3.Font.Size=40 Pnl3.Top=120
Pnl4=createPanel(form)
Pnl4.Caption="+" Pnl4.Font.Size=40 Pnl4.Top=180
Pnl2.Color=0xFFFFFF
Pnl1.Color=0xFFFF00
Pnl3.Color=0x00FFFF
Pnl4.Color=0x000000
if Pnl2.Color < 0xFFF000 or Pnl2.Color < 8388607 then
Pnl2.Font.Color=16777215
else
Pnl2.Font.Color=0
end
if Pnl1.Color < 0xFFF000 or Pnl1.Color < 8388607 then
Pnl1.Font.Color=16777215
else
Pnl1.Font.Color=0
end
if Pnl3.Color < 0xFFF000 or Pnl3.Color < 8388607 then
Pnl3.Font.Color=16777215
else
Pnl3.Font.Color=0
end
if Pnl4.Color < 0xFFF000 or Pnl4.Color < 8388607 then
Pnl4.Font.Color=16777215
else
Pnl4.Font.Color=0
end |
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Fri Jul 30, 2021 5:39 pm Post subject: |
|
|
LeFiXER wrote: | Here is a little something to invert RGB
Code: |
function invertRGB(r,g,b)
r = r * -1 + 255
g = g * -1 + 255
b = b * -1 + 255
print('Hex : ' .. string.format('0x%X%X%X',r,g,b))
print('RGB : ' ..b..','..g..','..r)
return r,g,b
end
invertRGB(100,255,25)
|
I hope this puts you in the right direction. |
I think you misunderstand the purpose of this code. It inverts the colour and returns a hex code value which is what CE prefers when using Lua.
Format: 0xXXXXXX
Quote: |
Sample; In this color font "16776960" should be dark (black), but the code makes the font white.
|
That's because "16776960" isn't a colour code. Use my function to convert RGB to the correct colours that you need.
|
|
Back to top |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Fri Jul 30, 2021 7:24 pm Post subject: |
|
|
I don't need an inverse of the color.
I'm just trying to do this;
If the panel color is dark; Panel font color should be light color.
If the panel color is light; Panel font color should be dark.
Check out the code below;
In the yellow panel, the font color changed to light color.
Other panel colors responded correctly.
Code: | if form then form.destroy() form = nil end
form = createForm()
form.Position=poDesktopCenter
Pnl2=createPanel(form)
Pnl2.Caption="+" Pnl2.Font.Size=40
Pnl1=createPanel(form)
Pnl1.Caption="+" Pnl1.Font.Size=40 Pnl1.Top=60
Pnl3=createPanel(form)
Pnl3.Caption="+" Pnl3.Font.Size=40 Pnl3.Top=120
Pnl4=createPanel(form)
Pnl4.Caption="+" Pnl4.Font.Size=40 Pnl4.Top=180
Pnl2.Color=0xFFFFFF
Pnl1.Color=0xFFFF00
Pnl3.Color=0x00FFFF
Pnl4.Color=0x000000
if Pnl2.Color < 0xFFF000 or Pnl2.Color < 8388607 then
Pnl2.Font.Color=16777215
else
Pnl2.Font.Color=0
end
if Pnl1.Color < 0xFFF000 or Pnl1.Color < 8388607 then
Pnl1.Font.Color=16777215
else
Pnl1.Font.Color=0
end
if Pnl3.Color < 0xFFF000 or Pnl3.Color < 8388607 then
Pnl3.Font.Color=16777215
else
Pnl3.Font.Color=0
end
if Pnl4.Color < 0xFFF000 or Pnl4.Color < 8388607 then
Pnl4.Font.Color=16777215
else
Pnl4.Font.Color=0
end |
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25287 Location: The netherlands
|
Posted: Sat Jul 31, 2021 1:28 am Post subject: |
|
|
newcolor=oldcolor ^ 0xffffff
i find mask 0x555555 giving a nice result most of the time
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Sat Jul 31, 2021 6:28 am Post subject: |
|
|
Dark Byte wrote: | newcolor=oldcolor ^ 0xffffff
i find mask 0x555555 giving a nice result most of the time |
Thanks DB, that "^" sign led me to Lua math.
The code below will generate a random color close to the opposite color.
Even if the panel color changes, the panel text will be legible.
PS: Thanks DB for understanding what I mean.
Code: | function newRandomClr(rsclr1,rsclr2)
rstClr1=math.random(math.min(rsclr1,rsclr2),math.max(rsclr1,rsclr2))
--print(rstClr1)
return rstClr1
end
Pnl2.Font.Color=newRandomClr(Pnl2.Font.Color,Pnl2.Color)
Pnl1.Font.Color=newRandomClr(Pnl1.Color,Pnl1.Font.Color)
Pnl3.Font.Color=newRandomClr(Pnl3.Color,Pnl3.Font.Color)
Pnl4.Font.Color=newRandomClr(Pnl4.Color,Pnl4.Font.Color) |
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Sat Jul 31, 2021 10:44 am Post subject: |
|
|
ByTransient wrote: | I don't need an inverse of the color.
I'm just trying to do this;
If the panel color is dark; Panel font color should be light color.
If the panel color is light; Panel font color should be dark.
|
That Is exactly what you're asking. You want a light colour based on the colour of the panel therfore you can take the panel colour and inverse it based on whether it's light or dark.
|
|
Back to top |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|