[SOLVED] create multi-colour chequer pattern

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

[SOLVED] create multi-colour chequer pattern

Post 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.
Last edited by Draoidh on 2012-10-05T02:23:03-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: create multi-colour chequer pattern

Post 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
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: create multi-colour chequer pattern

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: create multi-colour chequer pattern

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: create multi-colour chequer pattern

Post 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!)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: create multi-colour chequer pattern

Post 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?!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: create multi-colour chequer pattern

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
Draoidh
Posts: 69
Joined: 2012-07-03T11:29:44-07:00
Authentication code: 13
Location: soon to be independent Scotland

Re: create multi-colour chequer pattern

Post by Draoidh »

Many thanks.
Post Reply