Page 1 of 1

[SOLVED] create multi-colour chequer pattern

Posted: 2012-09-30T09:43:08-07:00
by Draoidh
I currently have four threads in the top ten of this forum! Here's number five!

I would like to create a chequer pattern from two are more colours. The colours are handed down as a parameter in the following format:

Code: Select all

xc:blue xc:yellow xc:red
Another parameter specifies the overall dimension of the rectangle that is to be created, for example

Code: Select all

dim=400x50
Furthermore, I'll need to get the size of each individual box.

I need something along the lines:

Code: Select all

row1: repeat pattern
row2: shift one unit, repeat pattern
row3: shift two units, repeat pattern
...
The problem I see is that the number of rows depends on the number of colours.

I use IM 6.7.9.

Re: create multi-colour chequer pattern

Posted: 2012-09-30T10:58:43-07:00
by fmw42
create a small image of the unit size for each color using +append, -use -roll to shift/wrap the color squares by a square amount, repeat for each row that you want, then use +append to combine them into one small image say 3x3

blue yellow red
red, blue, yellow
yellow, red, blue

Now you have a tile. Then use tile to repeat them out to the final image size.

see
http://www.imagemagick.org/Usage/canvas/#tile
http://www.imagemagick.org/Usage/layers/#append
http://www.imagemagick.org/script/comma ... s.php#roll
http://www.imagemagick.org/Usage/warping/#roll

Re: create multi-colour chequer pattern

Posted: 2012-10-02T15:45:26-07:00
by Draoidh
I have created the tile:

Code: Select all

convert \( \( +size   xc:red xc:yellow xc:green  +append \)  \) \( +clone  -roll +1+0 \)  \( +clone  -roll +1+0 \) -append  tile.png
My script gets the colours as parameter: xc:red xc:yellow xc:green. Depending on the number of colours I need to repeat the clone and roll x times.

Is there any way I can script this via IM or do I need to generate the IM code via bash?

Re: create multi-colour chequer pattern

Posted: 2012-10-02T16:04:49-07:00
by fmw42
You would have to use bash shell script to do the looping to then control the IM convert commands, if you do not have the same number of colors each time.

If you want to have some specific cell size for each color then you should add -size to your command and then -roll by that size. Otherwise, you will have to scale the result by the factor you want each cell to be and then tile that.

Re: create multi-colour chequer pattern

Posted: 2012-10-02T22:12:41-07:00
by anthony
If you like to roll N images without pre-knowning what N is then you would probably roll using distort and a tiled virtual canvas.

And example of this is a rolling animation (you would just do a single row of pixels, and append rather than animate...

Animated Distorts - distorting multiple image based on image index
http://www.imagemagick.org/Usage/anim_mods/#distort

At the moment the only shell script use would be handling the 'N' for the duplication step. IMv7 can do it without the external wrapper, but Imv7 is still in alpha. (I really need to get into it!)

Re: create multi-colour chequer pattern

Posted: 2012-10-04T16:48:01-07:00
by Draoidh
anthony wrote:Animated Distorts - distorting multiple image based on image index
http://www.imagemagick.org/Usage/anim_mods/#distort
This is ingenious but I am struggling with this expression:

Code: Select all

%[fx:w*t/n],%[fx:h*t/n]
Looking at ImageMagick Escapes, what is t? Surely not the filename?!

Re: create multi-colour chequer pattern

Posted: 2012-10-04T17:45:16-07:00
by anthony
Draoidh wrote:
anthony wrote:Animated Distorts - distorting multiple image based on image index
http://www.imagemagick.org/Usage/anim_mods/#distort
This is ingenious but I am struggling with this expression:

Code: Select all

%[fx:w*t/n],%[fx:h*t/n]
Looking at ImageMagick Escapes, what is t? Surely not the filename?!
The percent escape is %[fx:...] the '...' is an FX expression... See
FX the DIY operator
http://www.imagemagick.org/Usage/transform/#fx
and more specifically
http://www.imagemagick.org/script/fx.php

't' is the 'index' of the image in the current image list (starting at 0), 'n' is the total number of images in the list.
As such "t/n" will be a floating point number between 0.0 and just short of 1.0
Each image will thus get different distortion arguments, and in this case, different translation amounts.

Note that IMv7 will not just allow percent escapes in just the distort argument, but in any operator argument, and soon all image settings too.

Re: create multi-colour chequer pattern

Posted: 2012-10-05T02:22:37-07:00
by Draoidh
Many thanks.