Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

is it a tool to find easily a color
Started by espace3d Nov 17 2014 11:55 AM

- - - - -
9 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

espace3d

[GLOBAL: userInfoPane.html]
espace3d
  • Contributor

  • 377 posts
  • Corona SDK

hi,

 

I would like make a specific color with the fill

object:setFillColor( red, green, blue, alpha )

Is it a special tool for to find the right combination for a specific color (0.25,0.23,0.68) ?

 

or a tool that translate the html annotation ?

 

At first glance I did not see anything in the forum or in the documentation

 

Thanks for your help.

 

 

 



[TOPIC: post.html]
#2

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @espace3d,

I don't understand what you are trying to do. Do you want to convert "HTML" colors for usage with Corona? Like hexadecimal to RGB, or vice-versa? I think there may be a tool in the community code share, but I'm not certain. I seem to recall seeing one somewhere...

 

Brent



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

@espace3d,

 

Yeah, kinda hard to know what you're asking:

 

1. If you need docs for Corona functions, they are here:  http://docs.coronalabs.com/daily/api/

 

2. setFillColor() docs here: http://docs.coronalabs.com/daily/api/type/ShapeObject/setFillColor.html

 

3. Need code to convert hex codes to color codes?

-- ==
--    hexcolor(  ) - converts hex color codes to rgba Graphics 2.0 values
-- ==
local function hexcolor( code )
  code = code and string.gsub( code , "#", "") or "FFFFFFFF"
  code = string.gsub( code , " ", "")
  local colors = {1,1,1,1}
  while code:len() < 8 do
    code = code .. "F"
  end
  local r = tonumber("0X" ..strSub( code, 1, 2 ))
  local g = tonumber("0X" ..strSub( code, 3, 4 ))
  local b = tonumber("0X" ..strSub( code, 5, 6 ))
  local a = tonumber("0X" ..strSub( code, 7, 8 ))
  local colors = { r/255, g/255, b/255, a/255  }
  return colors
end

Example usage:

local myCircle = display.newCircle( 10, 10, 10 )

myCircle:setFillColor( unpack( hexcolor("#FFCCDD") ) 
-- Above fill equates to: < 255, 204, 221, 255 > i.e. < 1.0, 0.8, 0.867, 1.0 >


[TOPIC: post.html]
#4

espace3d

[GLOBAL: userInfoPane.html]
espace3d
  • Contributor

  • 377 posts
  • Corona SDK

this is exactly what i need. thanks

it's a little difficult to me because my native language is not english :P

 

3. Need code to convert hex codes to color codes?

-- ==
-- hexcolor( ) - converts hex color codes to rgba Graphics 2.0 values
-- ==
local function hexcolor( code )
code = code and string.gsub( code , "#", "") or "FFFFFFFF"
code = string.gsub( code , " ", "")
local colors = {1,1,1,1}
while code:len() < 8 do
code = code .. "F"
end
local r = tonumber("0X" ..strSub( code, 1, 2 ))
local g = tonumber("0X" ..strSub( code, 3, 4 ))
local b = tonumber("0X" ..strSub( code, 5, 6 ))
local a = tonumber("0X" ..strSub( code, 7, 8 ))
local colors = { r/255, g/255, b/255, a/255 }
return colors
end

Example usage:

local myCircle = display.newCircle( 10, 10, 10 )

myCircle:setFillColor( unpack( hexcolor("#FFCCDD") )
-- Above fill equates to: < 255, 204, 221, 255 > i.e. < 1.0, 0.8, 0.867, 1.0 >

 



[TOPIC: post.html]
#5

espace3d

[GLOBAL: userInfoPane.html]
espace3d
  • Contributor

  • 377 posts
  • Corona SDK

An another way maybe simpliest :

 

http://www.yellowpipe.com/yis/tools/hex-to-rgb/color-converter.php

 

"don't forget to translate i.e 87 with 0.87"



[TOPIC: post.html]
#6

Quantumwave

[GLOBAL: userInfoPane.html]
Quantumwave
  • Contributor

  • 132 posts
  • Corona SDK

You can also try this: http://qwmobile.com/html/ConvertRGBv2.html (if all you need is pre-converted colors).

 

Dave



[TOPIC: post.html]
#7

aaron.rackley9

[GLOBAL: userInfoPane.html]
aaron.rackley9
  • Observer

  • 18 posts
  • Corona SDK

Hey All.

 

Thanks for that code snippet. I have pulled this into my own color module i use on my projects I hope this is ok. I have just uploaded it to GIT as well incase anyone else wants it. 

 

It also includes a huge list of the x11 color list already predefined. 

This is my first attempt at releasing a mod so please comment and help me make it better :) New to Corona as well

 

The Git is here https://github.com/ageddesi/mod_color



[TOPIC: post.html]
#8

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 842 posts
  • Corona SDK

This is my first attempt at releasing a mod so please comment and help me make it better :) New to Corona as well

 

The Git is here https://github.com/ageddesi/mod_color

 

I would tighten the conditions on your asserts: rather than just asserting the variable (i.e. for nil or false), do assert(type(var) == "string", "Message"), in fromString and fromHex, and assert(type(var) == "number", "MESSAGE") or assert(tonumber(var), "MESSAGE") in fromRGB.

 

In the line

code = code and string.gsub( code , "#", "") or "FFFFFFFF"

the "code and" part is unnecessary since you've already done the assert. Also,

local color = colorString

doesn't seem to get you much (I'd just call the parameter itself color; implicitly, it's already a string according to the function name).

 

The color table itself should probably be local to the module, rather than exported along with the functions. This would let you augment fromString down the road, without having to take into account, say, that the table could be modified behind your back.



[TOPIC: post.html]
#9

aaron.rackley9

[GLOBAL: userInfoPane.html]
aaron.rackley9
  • Observer

  • 18 posts
  • Corona SDK

I would tighten the conditions on your asserts: rather than just asserting the variable (i.e. for nil or false), do assert(type(var) == "string", "Message"), in fromString and fromHex, and assert(type(var) == "number", "MESSAGE") or assert(tonumber(var), "MESSAGE") in fromRGB.

 

In the line

code = code and string.gsub( code , "#", "") or "FFFFFFFF"

the "code and" part is unnecessary since you've already done the assert. Also,

local color = colorString

doesn't seem to get you much (I'd just call the parameter itself color; implicitly, it's already a string according to the function name).

 

The color table itself should probably be local to the module, rather than exported along with the functions. This would let you augment fromString down the road, without having to take into account, say, that the table could be modified behind your back.

 

Thanks for the feedback I will work on this tomorrow and update the repo :) I love the Corona community.



[TOPIC: post.html]
#10

aaron.rackley9

[GLOBAL: userInfoPane.html]
aaron.rackley9
  • Observer

  • 18 posts
  • Corona SDK

I have now updated my color mod code and added a new feature someone asked for via twitter. .random() which will just return you a random color. 

 

If you know of any other ways to make this mod more better please let me know on the git page by raising a ticket :) 

https://github.com/ageddesi/mod_color

 

Thanks again for all the support everyone here at Corona gives. I like how the community is always trying to make everyone better.




[topic_controls]
[/topic_controls]