MOD Documentation

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

MOD Documentation

Post by Snickers » Sat Sep 15, 2007 9:27 pm

Where can I find more info on the MOD command?

More specifically, I am trying to reverse this process:
GetPixelColor>%xpos%,%ypos%,px
Let>px2={%px% MOD 16}
Let>px3={(%px%-%px2%)/16}
Let>px4={%px3% MOD 16}
Let>red={%px2%+(%px4%*16)}
Let>px5={(%px3%-%px4%)/16}
Let>px6={%px5% MOD 16}
Let>px7={(%px5%-%px6%)/16}
Let>px8={%px7% MOD 16}
Let>green={%px6%+(%px8%*16)}
Let>px9={(%px7%-%px8%)/16}
Let>px10={%px9% MOD 16}
Let>px11={(%px9%-%px10%)/16}
Let>px12={%px11% MOD 16}
Let>blue={%px10%+(%px12%*16)}

I'll be able to write it if I understood what MOD 16 was doing.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Sep 15, 2007 11:56 pm

MOD = modulo and returns the remainder after a division.

So in simple terms

Let>px2={%px% MOD 16}

Means divide px by 16 and assign the remainder to px2

suppose px is 35

16 goes into 35 twice (16*2=32) and the remainder is 3 so px2=3

Is that my RGB code? What exactly are you trying to do?

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Sun Sep 16, 2007 12:08 am

Me_again wrote:Is that my RGB code? What exactly are you trying to do?
Yes, it certainly is your code. Great find! I found it here: http://www.mjtnet.com/usergroup/viewtop ... hlight=mod

I need to convert a MScheduler color into BGR code and then using this value make some changes to the BGR code and convert that BGR code back into a MScheduler color.

Since you have provided the first part of the code (converting the MScheduler color into a BGR color) I need to find out how to convert that BGR color back into a MScheduler color.

I don't quite understand the logic behind looking at the remainders, however, once I take a closer look at your code, I may be able to figure it out....maybe. If you happen to have a snippet saved of the conversion code, I would be grateful if you could provide it.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Sep 16, 2007 12:35 am

Look up decimal to hexadecimal conversion, that's what it is doing. Not sure I have that code with me, I'll see what I can find later. Basically you just want to go from an RGB three number code to a macroscheduler color value - right?

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Sun Sep 16, 2007 1:21 am

Me_again wrote:Basically you just want to go from an RGB three number code to a macroscheduler color value - right?
Right. Basically the reverse of what you did before. I want to convert the RGB to a Macroscheduler color value.

Keeping in mind what Marcus said:
Just remember that Macro Scheduler returns the values in BGR sequence (not RGB).

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Sun Sep 16, 2007 1:19 pm

Tougher than I thought!

I have run the math on paper a few times and I'm a down. I might not be out, but I sure as heck am down.

I have tried using the combinations on this page:
http://www.permadi.com/tutorial/numHexToDec/index.html

The math isn't working out for me.

So, if I understand this right, the way to convert the BGR (Macroscheduler sequence of RGB) to MScheduler code would be to convert each three digit value into a hexadecimal number and combine them somehow to form the MScheduler number. Once I can figure this out on paper, I'm sure I'll have some questions about a few functions in MScheduler. Such as taking a variable of a number (for example: 123) and finding a way of only using the first, second, or third digit of that number for the calculation.

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Sun Sep 16, 2007 1:51 pm

I think got it! It needs more testing though. It seems too simple.

I noticed that if you multiply 256*256*256, you'll get 16777216. The color white for RBG = 255, 255, 255. MacroScheduler uses 16777215 to represent the RBG color white.

This means the formula for converting a RGB back to MScheduler code might be as follows:

Code: Select all

Let>red=%red%+1
Let>green=%green%+1
Let>blue=%blue%+1

Let>MScolor={(%red%*%green%*%blue%)-1}
Let>red=%red%-1
Let>green=%green%-1
Let>blue=%blue%-1
MDL>MScolor=%MScolor% for %red%-%green%-%blue%
Last edited by Snickers on Sun Sep 16, 2007 2:30 pm, edited 2 times in total.

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Sun Sep 16, 2007 1:52 pm

Rats! That isn't correct. I believe if I can arrange the numbers in highest to lowest and apply a multiplier, I can convert the numbers according to this multiplier.

Ok. steps to doing the conversion are as follows:

Convert, IN THIS ORDER, the BGR codes into hexadecimal. Then convert those back to decimal.

Code: Select all

For example: MS color 10711308 is converted into BGR color is 163-113-12 using the code you provided.

converted to hex = A3-71-0C <--in this order (BGR)

A3710C converted back to MScheduler color is done this way:
(0-f is hex numbering) working from right to left.

12(16^0) + 0(16^1) + 1(16^2) + 7(16^3) + 3(16^4) + 10(16^5) = 10711308 

Now the question is....how do we do this with the Macro Scheduler's functions?
Last edited by Snickers on Sun Sep 16, 2007 3:19 pm, edited 1 time in total.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Sep 16, 2007 2:58 pm

Snickers wrote:I think got it! It needs more testing though. It seems too simple.

I noticed that if you multiply 256*256*256, you'll get 16777216. The color white for RBG = 255, 255, 255. MacroScheduler uses 16777215 to represent the RBG color white.
Close :wink: It's

255 + (255*256) + (255 *(256*256))

Now you have to figure out the order :)

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Sun Sep 16, 2007 3:54 pm

Thank you for putting me back on track. As Barney would say, on How I Met Your Mother, "Your math skills are LEGENDARY." Here is the code for a color converter.

Code: Select all


//INPUT MSCHEDULER COLOR
Input>px,What is the MScheduler color?

//Convert MScheduler color to RGB
Let>px2={%px% MOD 16}
Let>px3={(%px%-%px2%)/16}
Let>px4={%px3% MOD 16}
Let>red={%px2%+(%px4%*16)}
Let>px5={(%px3%-%px4%)/16}
Let>px6={%px5% MOD 16}
Let>px7={(%px5%-%px6%)/16}
Let>px8={%px7% MOD 16}
Let>green={%px6%+(%px8%*16)}
Let>px9={(%px7%-%px8%)/16}
Let>px10={%px9% MOD 16}
Let>px11={(%px9%-%px10%)/16}
Let>px12={%px11% MOD 16}
Let>blue={%px10%+(%px12%*16)}

//Display message modal with all calculations
MDL>%red%-%green%-%blue% = %px%%CRLF%px2=%px2%%CRLF%px3=%px3%%CRLF%px4=%px4%%CRLF%red=%red%%CRLF%px5=%px5%%CRLF%px6=%px6%%CRLF%px7=%px7%%CRLF%px8=%px8%%CRLF%green=%green%%CRLF%px9=%px9%%CRLF%px11=%px10%%CRLF%px12=%px12%%CRLF%blue=%blue%

//convert RGB to MScheduler color
Let>MScolor={%red%+(%green%*256)+(%blue%*(256*256))}

//Display message modal confirming color conversion
MDL>MScolor=%MScolor% for %red%-%green%-%blue%

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Sep 16, 2007 4:56 pm

Good job there Snickers :D

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Sep 17, 2007 2:03 am

Now we've figured that out it's easy to simplify the MS to RGB code :)

Code: Select all

//Convert MScheduler color to RGB
GetPixelColor>xpos,ypos,px
Let>red={%px% MOD 256}
Let>green={((%px%-%red%) MOD (256*256))/256}
Let>blue={(((%px%-%red%)/256)-%green%)/256}
MDL>%red%-%green%-%blue%

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Mon Sep 17, 2007 3:27 pm

Very nice, Me_again! It never dawned on me to re-examine your first code.

Code: Select all

//INPUT MSCHEDULER COLOR
LET>INPUT_BROWSE=0
Input>px,What is the MScheduler color?%CRLF%Click CANCEL if color is unknown. Color will be chosen depending on mouse position.

If>px=
 MDL>Place your cursor above the color you would like to Color Converter to analyze. When in place, Press ENTER.
 Wait>.25
 //get current mouse position
 GetCursorPos>Xpos,Ypos
 //determine mouse move position (move mouse 100 pixels to the right)
 Let>Xpos2=%Xpos%+20
 MouseMove>%Xpos2%,%Ypos%
 //get pixel color of previous mouse position
 GetPixelColor>Xpos,Ypos,px
endif

//Convert MScheduler color to RGB
Let>red={%px% MOD 256}
Let>green={((%px%-%red%) MOD (256*256))/256}
Let>blue={(((%px%-%red%)/256)-%green%)/256}

//Display message modal post calculations
MDL>%red%-%green%-%blue%

//convert RGB to MScheduler color
Let>MScolor={%red%+(%green%*256)+(%blue%*(256*256))}

//Display message modal confirming color conversion
MDL>MScolor=%MScolor% for %red%-%green%-%blue%

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts