ColorTool - Change colors in document, copy and paste etc.

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Nicohk92
Posts: 276
Joined: Sun Apr 13, 2014 4:31 pm

Re: ColorTool - Change colors in document, copy and paste et

Post by Nicohk92 »

Last night I was able to change the skin color of an entire wip by opening an .anme file in a text editor and use some clever "find and replace".

May not be standard practice but it saved me a good half hour. Tho not being a scripter, I also messed up another file later trying to reproduce the technique (a duplicate of course) and so it got me interested in understanding how Moho works and calculates these lm_colorvector values or whatever it's called.
At the end of the day, I concluded i'd be better off just moving on with my project normally.


But could anything similar to that very useful DS_colortool exist for V10?



Thanks
User avatar
hayasidist
Posts: 3523
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: ColorTool - Change colors in document, copy and paste et

Post by hayasidist »

most of what you want can (now) be done with native AS.

in the style window:

>> you can copy and paste colours

>> you can create a "style" with a user-defined name (such as "skinColour") and then create shapes that have that as their fill/stroke attribute so that when/if you want to change all the shapes from (say) green to blue all you have to do is change the style and the job is done... (there's more to styles than just that -- take a look at the "Style Management Drop-Down Menu" section in the manual as a starting point)


and to answer you question about LM_ColorVector: 4 floating point numbers R, G, B, A in the range 0 to 1 (which map to the 8bit - 0 to 255 - range you see in the UI). These floating point numbers are useful when doing arithmetic on colours in (e.g.) blend modes. It also means that the vector is not limited to the 8bit system.
User avatar
Nicohk92
Posts: 276
Joined: Sun Apr 13, 2014 4:31 pm

Re: ColorTool - Change colors in document, copy and paste et

Post by Nicohk92 »

Haha! it keeps working!

If anyone wonders,


I create two test files each containing only a colored square. They're exactly the same but for one small difference:

File A: square color is the one I want to change

File B: A Square color is the one I want to replace with

I drop them both in a text editor I use text wrangler on mac).

I perform a "compare search" so it returns the differences between the two files.

Beside date , name and meta-data, there is one line further down that changes.

It looks something like this

[
keys 1
0 1 0.1 0.5 1 0 0 0 0.960784 0.819608 0.521569 1
]


As I understand it but you guys probably know more, "0.960784 0.819608 0.521569 1" is an RGB coordinate crunched down to decimal values I'm guessing from accounting other properties (I''ve only tried with simple shapes with no effects), and I can't find anywhere any straight forward way to convert back.

Anyway, I just copy that portion of the old color, open the (duplicate) file I want to alter in the text editor, and do a simple find&replace all with the new value.

And Voila!


All aspects othe characters have the new skin color. Yeaaah!

I wonder how far I can go with this little cheat.
User avatar
Nicohk92
Posts: 276
Joined: Sun Apr 13, 2014 4:31 pm

Re: ColorTool - Change colors in document, copy and paste et

Post by Nicohk92 »

hayasidist wrote:most of what you want can (now) be done with native AS.

in the style window:

>> you can copy and paste colours

>> you can create a "style" with a user-defined name (such as "skinColour") and then create shapes that have that as their fill/stroke attribute so that when/if you want to change all the shapes from (say) green to blue all you have to do is change the style and the job is done... (there's more to styles than just that -- take a look at the "Style Management Drop-Down Menu" section in the manual as a starting point)


and to answer you question about LM_ColorVector: 4 floating point numbers R, G, B, A in the range 0 to 1 (which map to the 8bit - 0 to 255 - range you see in the UI). These floating point numbers are useful when doing arithmetic on colours in (e.g.) blend modes. It also means that the vector is not limited to the 8bit system.

Yes I have finally completly understood styles a couple days ago (it used to give me huge headaches), and now use it quite a bit to add shadows quickly, although I still do some false moves from time to time, style are amazing.
However What if I haven't taken the habit of defining my styles from the get go? It means I would have to go through each shapes and layers and assign them right? In that case, which is mine), and for hassles like skin color, i find this trick quite useful.
hayasidist wrote:and to answer you question about LM_ColorVector: 4 floating point numbers R, G, B, A in the range 0 to 1 (which map to the 8bit - 0 to 255 - range you see in the UI). These floating point numbers are useful when doing arithmetic on colours in (e.g.) blend modes. It also means that the vector is not limited to the 8bit system.
Is there a way to convert this values back to standard RGB (and consequently, HEX)?
User avatar
hayasidist
Posts: 3523
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: ColorTool - Change colors in document, copy and paste et

Post by hayasidist »

Nicohk92 wrote:Is there a way to convert this values back to standard RGB (and consequently, HEX)?
yes! (I'm assuming that you're Ok with different number bases -- decimal and hexadecimal (hex) ?? say if not and I'll explain)


in the vector: 0.0 => x00; 1.0 => xFF

so take each floating point number; multiply by 255 (decimal); that will give you the four (8bit) values which you can then convert to hex and concatenate:

(e.g.) {0.33, 0.5, 0.25, 1} (*255) => {84.15, 127.5, 63.75, 255} (round) => {84, 128, 64, 255} (convert to hex) => {54, 80, 40, FF} (concatenate for 24bit colour) => #548040
User avatar
Nicohk92
Posts: 276
Joined: Sun Apr 13, 2014 4:31 pm

Re: ColorTool - Change colors in document, copy and paste et

Post by Nicohk92 »

hayasidist wrote:
yes! (I'm assuming that you're Ok with different number bases -- decimal and hexadecimal (hex) ?? say if not and I'll explain)
I wouldn't mind as I'm more of a dark poking kind of guy at this point.

I'm not sure how you do your first multiplication

for ex, in:

0.87451 0.67451 0.529412 1,

0.87451 x 255 gives 223.00005

so that's 223 correct?



Fascinating stuff
User avatar
Nicohk92
Posts: 276
Joined: Sun Apr 13, 2014 4:31 pm

Re: ColorTool - Change colors in document, copy and paste et

Post by Nicohk92 »

Also to extrapolate on this little practice (not really scripting I believe, more like file molesting right?), imagine this scenario:

I just changed a character from CW to give it a the shape of a V-neck and tie, like a suit, drawn on the torso with the fewest shapes and points possible.

What i if I identify the difference it makes in the file code, and manage to to do find&replace of only these changes in the rest of the file for [name: "torso"]

Would that in effect interpret the V-neck correctly throughout all other aspects? I would guess it's not that simple and of course for this example, i'd be just as quick just drawing it but it'd open some possibilities.
amanandink
Posts: 252
Joined: Wed Feb 13, 2008 10:28 pm
Location: Kilkenny, Ireland
Contact:

Re: ColorTool - Change colors in document, copy and paste et

Post by amanandink »

hey Nicohk92

I'm not sure about your torso question, but we have done alot of work with styles and have come up with an automated process for change the colours in files quiet quickly.

we use it to change our character to night time colour, doing a bunch, maybe 60 scenes in one go.

we colour the characters for day using styles in ASP
then make a second file, colouring the same character for night in asp, changing the styles in the file.

comparing the 2 in our text editor, (sublime text 2 in our case), we get the line and shape colours for both day and night for each style.
we then paste this into a text file, that we use with a programme (texfinderX http://sw.ixoft.com/texfinderx/) which will read one number and replace it with the other. But it can do batches of number replacements using the TFTTables function. a file will look something like this

0 0 0.1 0.5 1 0 0 0 0.760784 0.745098 0.647059 1 0 0 0.1 0.5 1 0 0 0 0.396078 0.568627 0.686275 1
0 0 0.1 0.5 1 0 0 0 0.466667 0.454902 0.380392 1 0 0 0.1 0.5 1 0 0 0 0.266667 0.415686 0.52549 1
0 0 0.1 0.5 1 0 0 0 0.32549 0.317647 0.219608 1 0 0 0.1 0.5 1 0 0 0 0.137255 0.278431 0.337255 1

0 0 0.1 0.5 0 0 0 0 0.466667 0.454902 0.380392 1 0 0 0.1 0.5 0 0 0 0 0.258824 0.411765 0.482353 1
0 0 0.1 0.5 1 0 0 0 0.478431 0.337255 0.25098 1 0 0 0.1 0.5 1 0 0 0 0.176471 0.25098 0.301961 1
0 0 0.1 0.5 1 0 0 0 0.631373 0.454902 0.364706 1 0 0 0.1 0.5 1 0 0 0 0.333333 0.4 0.454902 1

0 0 0.1 0.5 1 0 0 0 0.513726 0.364706 0.27451 1 0 0 0.1 0.5 1 0 0 0 0.211765 0.286275 0.337255 1
0 0 0.1 0.5 1 0 0 0 0.529412 0.364706 0.270588 1 0 0 0.1 0.5 1 0 0 0 0.223529 0.286275 0.337255 1
0 0 0.1 0.5 1 0 0 0 0.419608 0.294118 0.203922 1 0 0 0.1 0.5 1 0 0 0 0.121569 0.192157 0.231373 1

a tab between the two numbers shows it what to convert to what. we split the paragraphs into rows of 3 to make it readable.
it works great for batch changes, as we are working on a series and we might have to change up to 100 files in one go.

J
User avatar
Nicohk92
Posts: 276
Joined: Sun Apr 13, 2014 4:31 pm

Re: ColorTool - Change colors in document, copy and paste et

Post by Nicohk92 »

Hey Amanan, Thanks for sharing these insights. A a small barely intermediate craftsman, it's nice to find these experiments implemented at production level.

It certainly sounds like a very useful extension of styles capabilities for long projects.

I'm only working on a small 2mn piece so using styles is not as crucial as it must be for you. Anyway I started without them, lots of shapes don't have them defined and now too far ahead to bother much (I might take an afternoon after delivering first draft to set all that up but no time right now).

However the next experiment I'll do, (before even the longer shot of the v-neck example), is to see if I can set line width globally. Indeed, I'm having second thoughts about my choice of width and some are uneven. I'm interested to find out if, not in script but in shape settings themselves, all widths can be found and replaced in one click in the file as are the colors (there's scale compensation to watch out for I'm sure)

Anyway, I will post the results here.

I had never heard of text finder. Pretty cool how it can treat whole folders at once.
User avatar
hayasidist
Posts: 3523
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: ColorTool - Change colors in document, copy and paste et

Post by hayasidist »

Nicohk92 wrote:
0.87451 0.67451 0.529412 1,

0.87451 x 255 gives 223.00005

so that's 223 correct?
yes! for completeness (and rounded): (0.87451, 0.67451, 0.529412, 1} * 255 = {223, 172, 135, 255} = {DF, AC, 87, FF} => #DFAC87

========================================================
Nicohk92 wrote:
hayasidist wrote:
(I'm assuming that you're Ok with different number bases -- decimal and hexadecimal (hex) ?? say if not and I'll explain)
I wouldn't mind as I'm more of a dark poking kind of guy at this point.
decimal means "count in tens"; hexadecimal means "count in sixteens"... and counting in sixteens means counting up until you get to fifteen before you roll it over.

Counting in tens is relatively new idea: English numbers have special words up to 12 before recognizing the decimal at "three and ten" (thirteen). Italian goes straight to "one and ten" (undici); but in French numbers up to sixteen have special words before they recognise the decimal and swap to "ten and seven".

Back in pre-decimal British currency, money WAS counted in 12s .. 15 [old] pence was generally said as "one and three" [one shilling and three pence]

And imagine that the French language kept that counting system, so what we'd all now say as 17, Francophones would write and say as (e.g.) un et seize .. and so on until quinze et seize then deuxSeizes and so on ... with (e.g.) quatre et deuxSeizes written as (say) 2s4

imperial weights still use 16 ounces to a pound e.g. 2lb 4oz; as do US fluid measures 2pints 4 ounces.


so take a number such as 24

In common usage we'd say twenty four (two tens and four)
But in hexadecimal (usually said simply as "hex") we'd say "two four" -- that's two SIXTEENs and four = 2*16 + 4 = 32+4 (decimal) = 36 (decimal)

now those clever Arabs who gave us our (decimal) number system hadn't given us special symbols for the numbers after 9, so we improvise with letters: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F; and stick a small x (or 0x or ...) in front so we know that we're using hex: e.g. 0x24 to differentiate from 24 (decimal)

converting from decimal to hex is pretty easy for numbers up to 255: divide the decimal number by 16: the remainder is the last digit; the "answer" (the quotient) is the first digit. so taking 223 from the above: 223/16 = 13 remainder 15; 13 is written as "D" and 15 as "F" => xDF. 172/16 = 10 rem 12 => xAC I'll leave you to do the last one (135.).

Convention for colours is we stick a # sign in front of the RGB (hex) values ... so from the opening example: #DFAC87


Hope that makes sense! Shout if not.
User avatar
hayasidist
Posts: 3523
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: ColorTool - Change colors in document, copy and paste et

Post by hayasidist »

amanandink wrote: ... we have done alot of work with styles and have come up with an automated process for change the colours in files quite quickly.

we use it to change our character to night time colour , doing a bunch, maybe 60 scenes in one go.

we colour the characters for day using styles in ASP
then make a second file, colouring the same character for night in asp, changing the styles in the file...
J
Hey Jeremy, maybe a totally dumb question, but do blend modes (e.g. de-saturating colours?) and/or (e.g.) low-alpha blue-grey overlays not do the day to night colour transition for you?
amanandink
Posts: 252
Joined: Wed Feb 13, 2008 10:28 pm
Location: Kilkenny, Ireland
Contact:

Re: ColorTool - Change colors in document, copy and paste et

Post by amanandink »

Emm it might but to be honest we never tried. All our compositing is done in after effects and applying a filter over the whole character there can sometimes leave us with stuff that's just nit quite what the art director wants so we found we have more control of the characters colours to just change them in asp. Our art director works in photoshop and we colour pick from the final image.
We also use the same process to change the colours of characters to create others. For example we have 5 shrew characters and the only difference is the colour so we can take a complicated model switching animation from one shrew and convert it to the colours of the others quickly. It is faster than coping and pasting multiple layers sometimes.
J
User avatar
hayasidist
Posts: 3523
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: ColorTool - Change colors in document, copy and paste et

Post by hayasidist »

Thanks Jeremy. makes perfect sense in your workflow. (BTW, I had a great laugh when I found the line on your website about "we animate when it's raining".. I guess you get a lot of very productive days!! :D )
User avatar
Nicohk92
Posts: 276
Joined: Sun Apr 13, 2014 4:31 pm

Re: ColorTool - Change colors in document, copy and paste et

Post by Nicohk92 »

Very instructive read Sidist, thanks for taking the time, I'm that much less ignorant. I have been copying and pasting these Hex values for ages without knowing at all the logic behind. You also pointed out oddities of my native tongue (French) which I had never wondered about (as is often the case when you grow up in it). We do switch to decimal for 17,18, 19 (dix-sept, dix-huit, dix-neuf). But it's even a bigger mess as we also count in twenties (Which I read is called a vigesimal system). So the French call 80: Quatre-vingt (four 20s), and then it gets weirder with for example 97 which is a mix of both system it seems: quatre vingt dix sept ((four 20s) 10s) 7).

Taking this into consideration is in a way understanding how everything we now take for granted, all the way to basic logic, had to be invented from scratch by pure practical necessity, as shows the vestiges of our human endeavor throughout different civilizations. Didn't expect to get philosophical on this forum...:)
User avatar
hayasidist
Posts: 3523
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: ColorTool - Change colors in document, copy and paste et

Post by hayasidist »

:D I held off talking about human use of the "twenty" number base.. in English that's known as a "score" - and it was in very common usage [e.g. Abraham Lincoln in the opening sentence of his 1863 Gettysburg Address: "Four score and seven years ago..." (=87) and the old UK coinage: 20 shillings in a pound] and it remains in use in imperial weights: 20 "hundredweight" (112 pounds -- and to explain that opens up a long discussion on our use of 8 and 14 as number bases :roll: ) in a ton.

The Belgian (and Swiss) variant of French has dumped the "four-score and ten" construct and they use "septante" for seventy and "nonante" for ninety. The Swiss also use "huitante" for 80.

(sudden thought - is that 92 Hauts-de-Seine??)

whatever -- as you say - it's great fun to lift the lid on what we just take for granted! Glad to have been able to share!
Post Reply