1

there!

Task. I want to change the color stripes on the Commodore64 logo. So that they consist of squares in 4 rows, slightly different in color from each other. But only slightly different. Within the shade of one color, as in the example of the picture with green tiles. (the presence of gaps is not necessary, but it is desirable to have this option)

That is, I want to draw stripes of different colors, so that each consists of squares slightly different in brightness or shade. Probably a universal solution and it is best to operate with pixels, and then scale the image to the desired size.

Examples of images:

green pixels of different shades

C64logo

Last time with Image Magick Mark Setchell helped me a lot, I hope to get his or your help again!

Although I tried to apply the experience gained earlier, and read the documentation, I could not find a solution. I just do not know how to set random similar colors. And so that it would be an elegant one-line script, and not a multi-line monstrosity of a program, taking pre-entered colors in an array.

2 Answers 2

4

I'm loving GeeMack's approach, but here's a slightly different one:

  • create a 10x10 green image
  • convert to HSL colourspace
  • add/subtract random small amounts of hue, saturation and lightness
  • convert back to RGB colourspace
  • scale up

magick -size 10x10 xc:green -colorspace hsl  \
   -fx 'u + (random()-0.5)*0.1'                    \
   -colorspace rgb -scale 500x500 result.png

enter image description here

Increase the 0.1 for greater variance in tones, decrease it for less.


Using 0.3 instead of 0.1:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Hello, Mark! I got several errors with it: magick -size 10x10 xc:green -colorspace hsl \ -fx 'u + (random()-0.5)*0.1' \ -colorspace rgb -scale 500x500 result.png -------------------------------- magick: Not a real operator at '()-0.5)*0.1' @ error/fx.c/GetOperator/2446. magick: Empty expression in parentheses at '()-0.5)*0.1' @ error/fx.c/GetOperand/2100. magick: Expected operand at '()-0.5)*0.1' @ error/fx.c/TranslateExpression/2664.
THNX U! UPD: correct variant rand(): magick -size 10x10 xc:green -colorspace hsl -fx 'u + (rand()-0.2)*0.1' -colorspace rgb -scale 500x500 JPG:- | display
3

There are several ways to generate random colors with ImageMagick. First, here is a simple method with IMv7 in Windows CLI syntax. (I edited this post to show another solution below.)

magick xc:green -duplicate 99 ^
   -modulate "%[fx:rand()*50+50],100,%[fx:70+(rand()*60)]" ^
   +append -crop 10x1@ -append -scale 500x500 greens.png

The command makes a green pixel, duplicates it 99 times, randomly modify the brightness and hue of each pixel within constraints, and assembles the units into a grid.

Modify the values in the "-modulate" operation, the first randomly adjusts the brightness between 50 and 100 percent. The third argument adjusts the hue plus or minus 30 points on a 200 point scale with 100 being the input color.

The above command creates this result...

enter image description here

EDITED TO ADD:

If the selection of colors you want can be described as a range, a gradient between two colors, this simple command will create an image with the results randomly distributed...

magick -size 30x30 xc:gray +noise random ^
   +level-colors "#304818,#588030" -scale 540x result.png

The command creates a grayscale image with random pixels ranging from black to white. Then it uses a "+level-colors" operation to specify the colors to use, and changes all the pixels so they fall within that range. Here is the result...

enter image description here

To make these commands work in a *nix shell, change the continued-line carets "^" to backslashes "\".

5 Comments

Hi! it worked, magick xc:green -duplicate 99 -modulate "%[fx:rand()*50+50],100,%[fx:70+(rand()*60)]" +append -crop 10x1@ -append -scale 500x500 JPG:- | display
but for some reason, after each execution in the terminal, I have to run the reset command to make the glitches disappear. Is it possible to exclude brown, yellow, and blue colors from the result?
"and changes all the pixels so they fall within that range. Here is the result..." -- Thank you, the result in the picture is just wonderful, help me correct the syntax to remove the error. "missing output filename `+level-colors' at CLI arg 6"
This unfortunately not worked properly: magick -size 30x30 xc:gray +noise random +level-colors #304818,#588030 -scale 540x JPG:- | display magick: missing output filename `+level-colors' at CLI arg 6 @ error/magick-cli.c/ProcessCommandOptions/753. UPD: quotes needed: magick -size 30x30 xc:gray +noise random +level-colors "#304818,#588030" -scale 540x JPG:- | display — WORKED!
I added the quotes around the colors. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.