The Big Bad G'MIC Thread of Silly Questions

But wouldn’t that draw 2 rectangles of the same color? I want them to have different colors ( well maybe not always since it’s random anyway so there is always a possibility of getting the same color).

No, because you re-evaluate your string for each rectangle drawn.

It would, but not always. There are approaches to always drawing two different color.

I thought of one with rep_ncr_combinations_index2list command, rep_permutation_index2list command, and using map(). Basically, I select 2 colors from a image with ncr_combinations, and change their order with permutation.

There’s other method like keeping in track of what selected and increment until a not-selected index has been found. This is the best way of doing this.

Finally, have a look at this:

foo 8,2
foo:
number_of_colors=$1
selected_colors=$2

+rep_ncr_combinations $number_of_colors,$selected_colors,x
+rep_permutations $selected_colors,x

resize[-2] {w*100}%,100%,100%,100%,1
f[-2] map(I[#-1,x%w#-1],I) rm.

foo 8,2 outputs every possibilities of 2 randomly selected colors out of 8 colors without repeat. This gives us:

(0,1,0,2,0,3,0,4,0,5,0,6,0,7,1,2,1,3,1,4,1,5,1,6,1,7,2,3,2,4,2,5,2,6,2,7,3,4,3,5,3,6,3,7,4,5,4,6,4,7,5,6,5,7,6,7^1,0,2,0,3,0,4,0,5,0,6,0,7,0,2,1,3,1,4,1,5,1,6,1,7,1,3,2,4,2,5,2,6,2,7,2,4,3,5,3,6,3,7,3,5,4,6,4,7,4,6,5,7,5,7,6)

Each pixels represent the colors selected.

Another solution, that defines a temporary command rcol in your custom function:

foo : 
  m "rcol : u {[${1-24}][3*int(u(8)%8),3]}"
  rectangle 20%,80%,60%,90%,{u(.5,1)},0xFFFFFFFF,${-rcol}
  rectangle 10%,50%,40%,70%,{u(.5,1)},0xFFFFFFFF,${-rcol}
  um rcol

I like this one, it is reasonnably short to write.

2 Likes

Yes, and it works fine (had to change the vars to ${11--1} to adapt it to my script).
It’s just a bit hard to understand; at least for me, but who knows, maybe one day it’ll just pop in my brain.

Thank you @David_Tschumperle and @Reptorian. You guys come up with stuff i wouldn’t dare to dream about… It’s really abstract to me. Just like the picture above hehe.

My bad code for the curious :

Feel the Pain

#@gui Seamless Chaotic Pattern:  pr_rndpat,pr_rndpat_gui(1)
#@gui : Margin Left (%)  = float(0,0,100)
#@gui : Margin Right (%)  = float(0,0,100)
#@gui : Margin Top (%) = float(0,0,100)
#@gui : Margin Bottom (%)  = float(0,0,100)
#@gui : Rectangles = int(1,0,10)
#@gui : Triangles = int(1,0,10)
#@gui : Circles = int(1,0,10)
#@gui : Dilate - Erode = int(0,-10,10)
#@gui : Seed = int(0,0,1000000)
#@gui : Tiles = int(0,0,3)
#@gui : Color 1 = color(255,255,255)
#@gui : Color 2 = color(255,255,255)
#@gui : Color 3 = color(255,255,255)
#@gui : Color 4 = color(255,255,255)
#@gui : Color 5 = color(255,255,255)
#@gui : Color 6 = color(255,255,255)
#@gui : Color 7 = color(255,255,255)
#@gui : Color 8 = color(255,255,255)
#@gui : sep = separator()
#@gui : note = note("<small>Author: <i><a href="http://prawnsushi.free.fr">Prawnsushi</i></a>.\
# Latest Update: <i>2024/02/15</i>.</small>")
pr_rndpat_gui :
pr_rndpat $*

# Removed #cli info placeholder here

pr_rndpat :

ML=$1
MR:=100-$2
MT=$3
MB:=100-$4
 m "rcol : u {[${11--1}][3*int(u(8)%8),3]}"

if $9 srand $9 fi
repeat 10 {
  repeat $5 { rectangle {u($ML,$MR)}%,{u($MT,$MB)}%,{u($ML,$MR)}%,{u($MT,$MB)}%,{u(.5,1)},0xFFFFFFFF,${-rcol} }
  repeat $6 { polygon 3,{u($ML,$MR)}%,{u($MT,$MB)}%,{u($ML,$MR)}%,{u($MT,$MB)}%,{u($ML,$MR)}%,{u($MT,$MB)}%,{u(.5,1)},0xFFFFFFFF,${-rcol} }
  repeat $7 {
  CR:=u(1,10)
  CX:=u($ML+$CR*2,$MR-$CR*2)
  CY:=u($MT+$CR*2,$MB-$CR*2)
  circle $CX%,$CY%,$CR%,{u(.5,1)},0xFFFFFFFF,${-rcol}
  }
  shift 50%,50%,0,0,2
}
# shift 50%,50%,0,0,2
if $10 repeat $10 { . a x .  a y } fi
if $8
  if $8>0
    dilate $8
  else
    erode {abs($8)}
  fi
fi
um rcol

Now, i have to make random line “patterns”. Oh joy. how am i gonna do that? Or should i give the user a selector? Not sure, since this version is almost pure chaos.

This could have been simplified to just repeat $10 { . a x . a y } . repeat 0 means the code block does not get executed. The last code bit could have been simplified with elif.

I like your progress anyway.

Yes, i think so too, but i’m alays unsure about this. Repeat 0 sounds kinda bad to me, don’t know why. But if you say it doesn’t hurt, i’ll just remove the if.

I’ve been out of g’mic for a few months actually. Just came back to it. Just me being random.

Added a bunvh of things for now :

  • Ellipses
  • Lines
  • Shift X,Y options

Here are a few test (learned how to gif in the process, but it’s a bit too fast… Also, i can’t really explain why it looks like parallax scrolling lol. )

test

test1

test2

test3

3 Likes

Keep the parallax, it’s actually so cool!

1 Like

Well I woke up this morning and I knew why it happens: it’s because I shift the image after drawing each set of objects. So the next objects are drawn over a shifted version of the previous ones. Made it so there wouldn’t be empty spaces when tiling… Ended up with a parallax lol.

Maybe something that can help :

Simple particle system
# Basic Particle System
foo :
  400,400,1,3 => canvas # Canvas
  100,1,1,8 => particles # Particles : (x,y,r,u,v,R,G,B)

  # Create set of random particles.
  f[particles] "[ u(w#$canvas - 1), u(h#$canvas - 1), u(10,40), u(-3,3), u(-3,0), u([255,255,255]) ]"

  # Render animation.
  do
    f[canvas] 0
    f[particles] "
      P = I;
      ellipse(#$canvas,P[0],P[1],-P[2],-P[2],0,1,0xFFFFFFFF,P[5,3]);
      [ (P[0] + P[3])%w#$canvas, (P[1] + P[4])%h#$canvas, P[2,5] ]"
    w[canvas]
    wait 30
  while {*}
Variation
# Basic Particle System
foo :
  400,400,1,3 => canvas  # Canvas
  300,1,1,10 => particles # Particles = (x0,y0,r,amp,mul,phase,v,R,G,B)

  # Create set of random particles.
  f[particles] "[ u(w#$canvas - 1), u(h#$canvas - 1), u(10,40),
                  u(50), u(0.1), u(2*pi), u(1,3),
                  u([255,255,255]) ]"

  # Render animation.
  t=0
  do
    *[canvas] 0.8
    eval[particles] "
      P = I;
      x = (P[0] + P[3]*sin(P[4]*$t + P[5]))%w#$canvas;
      y = (P[1] - P[6]*$t)%h#$canvas;
      ellipse(#$canvas,x,y,-P[2],-P[2],0,0.5,0xFFFFFFFF,P[7,3]);
      I"
    w[canvas]
    wait 30
    t+=1
  while {*}

2 Likes

Actually, this goes way beyond my goal (and my understanding!) :slight_smile:
I just wanted to make a seamless chaos. The animation was just the icing on the cake, as i just wanted to check if it was really seamless, or not. Looks like i made it?

test5
test5
test5

Now, i think you should continue to develop this particle system on your side, if there’s none in G’mic yet. Some people will like to have it, for sure. And if you can make it seamless too … :slight_smile:

2 Likes

:face_with_spiral_eyes: :+1:

Forgot to mention smoothelate that is added to my folder one or two weeks ago.
It’s a combination of pixelating and smoothing :

(Original dull photographs by me with Lumix TZ5 @ almost 10 years ago, somewhere in Japan,
and examples are quite random but… nwm )


No smoothing here :


Heavy smoothing & sharpening:

Low smoothing, high sharpening:

Oh that one looked funny so i’ll add it here :slight_smile:

2 Likes

Hi, me again,
and I’m trying to draw a rotated square but the size changes in the process :
gmic 800,800,1,3,255 run 'repeat 50 +polygon[0] 4,{50+$>}%,{1+$>}%,{99-$>}%,{50+$>}%,{50-$>}%,{99-$>}%,{1+$>}%,{50-$>}%,{$>*0.01},0xFFFFFFFF,0,0,0 w. done d'
Am i missing some pi stuff in there, or some other maths, to draw each point along a circle’s circumference?

I can get fun stuff that way though:

Another question: I use erode or dilate on images to increase the outline’s width, but sometimes it’s a bit tricky since it depends on the background and outline colors. If there are dark and lighter lines it may erode some and dilate others. I had the case with black to grey outlines: black lines would just disappear over a red background. Is there anything to be done about this or is it just a pit trap? Should i draw each color on a “layer” instead?

Gimp simulation with dilate (blackthinned, white thickened):

image

1 Like

It depends on how generalized you would like your solution to be. While it is a good to start small, could you share a complex image that is more representative of what you plan on working on?

Hello @afre , which question are you replying to?
The rotation or the dilate/erode problem?

Anyway :

  • for the rotation I just want to be able to draw a shape in any angle without calling rotate which i fear would force me to create a new image and paste it in the background, each time. Sounds heavy.
  • For the dilate/erode stuff, I just want to change the outline thickness regardless of color value or luminosity ( or whatever is involved). I probably need to separate colors by value I guess. There is probably a threshold value that could make this work. ( I feel like I’m having a hard time explaining what I want to do lol…)

That’s exactly where the math evaluator comes handy!

foo :
  400,400 => canvas
  repeat 90 {
    angle:=4*$>  # specified in degrees
    coords:="
      R = rot($angle°);
      C = [ w#$canvas/2, h#$canvas/2 ];
      rot_pt(x,y) = ( C + R*([ x,y ] - C) );
      [ rot_pt(100,100), rot_pt(300,100), rot_pt(300,300), rot_pt(100,300) ]"
    polygon[canvas] 4,$coords,0.5,0xFFFFFFFF,255
    w[canvas] wait 30
  }

Beware, dilate and erode are two morphological operations that have a formal definition :

and

It’s maybe not exactly what you are looking for!

You can then add some cool variations, as this one:

foo :
  400,400 => canvas
  repeat 360 {
    angle:=$>  # specified in degrees in [0,359]
    coords:="
      R = 2.3*cos(pi/3+$angle*pi/360)*rot($angle°);
      C = [ w#$canvas/2, h#$canvas/2 ];
      rot_pt(x,y) = ( C + R*([ x,y ] - C) );
      [ rot_pt(100,100), rot_pt(300,100), rot_pt(300,300), rot_pt(100,300) ]"
    +f[canvas] 0 polygon. 4,$coords,1,0xFFFFFFFF,255
    blend[canvas,-1] xor,0.25
    w[canvas] wait 30
  }
  normalize_local , smooth 50,0,1 n 0,255

foo

3 Likes

On erode and dilate:

That is why I asked. Once it is clear, it would just be a matter of implementing. This is true:

Thinking out loud, if you are processing an image with only lines, you may want to consider thinning them first and then reintroducing them and their intersections that disappear after erosion or dilation through something called geodesic erosion or dilation, or something to that effect. At first, I thought of frequency separation such as split_details. That would work for busier images, but you would end up with noise and outlines of lines and shapes rather than the lines and shapes themselves.