The Big Bad G'MIC Thread of Silly Questions

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.

Thanks, that’s quite nice indeed!
But i’m a wanderer, i have to explore this a bit more.
Found out i can fix the “tilted” look with even numbers here:

   R = 2*cos(pi/4+$angle*pi/360)*rot($angle°);

Which makes this tileable:

Adding points to the polygon makes it look weird but what i want is really just draw the shape once, but in a random or chosen angle. It’s just so i can switch rectangle to polygon in the previous code i posted (the bubbly chaos stuff). rectangle is cool but i can’t (can i?) use it to draw tilted rectangles/squares.
In your example the square still grows from tiny to oversized. What mod would make it keep it’s defined/original size? Like rotate would do, but without the added borders? I don’t want it to go outside the image, it would break the seamless tiling. (at least AFAIK).


Then if erode/dilate are out, maybe i could cheat by drawing the shape a few times (warning, brainless one-liner below, i hardly ever use vars in commandline mode, it’s just for testing):

gmic 800,800,1,3,255 run 'repeat 100 polygon[0] 4,{50+$>}%,{1+$>}%,{99-$>}%,{50+$>}%,{50-$>}%,{99-$>}%,{1+$>}%,{50-$>}%,1,0xFFFFFFFF,0,0,0  polygon[0] 4,{50.05+$>}%,{1.05+$>}%,{99.05-$>}%,{50.05+$>}%,{50.05-$>}%,{99.05-$>}%,{1.05+$>}%,{50.05-$>}%,1,0xFFFFFFFF,0,0,0 polygon[0] 4,{49.95+$>}%,{0.95+$>}%,{98.95-$>}%,{49.95+$>}%,{49.95-$>}%,{98.95-$>}%,{0.95+$>}%,{49.95-$>}%,1,0xFFFFFFFF,0,0,0 w. wait 25 done d'

It’s in % so it’s a bit trickier than adding/substracting one pixel to/from coords to get some thickness. As you can see, there are some gaps in between lines:
EDIT: wrong image :frowning:
BTW it seems some lines still appear thinner than others (bottom left, top right). Don’t know what causes this.

Or go crazy and simulate everything with thickline? After all, back when i was still drawing by hand (that’s so 1950 now :P) i was only using lines, not squares…

Anyway, thank you guys :slight_smile:

2 Likes

Hi, question-man here again. :person_raising_hand:

Would this be a good right way to add an alpha channel to an existing colored outline drawing ? I don’t want to lose information in the process. The ideal would be to get a binary image to append as an alpha channel.
EDIT: But then if i use black for the outline, these lines disappear in the process…

+f 0 # <<< add a black layer at the start of the script

# ...
# A bunch of drawing stuff here
# ...

+compose_channels. add to_gray.
# cut. {ia},{iM} << seen this in a tutorial by Gary, not sure if relevant here
cut. 0,1 n. 0,255
a[-2,-1] c rv # << append channel then reverse to put new layer on top

Result :

Thanks

  1. Create a four channel canvas image: blahx,blahy,1,4,0 so that all channels are zeroed out, including the alpha channel.
  2. Then draw with polygon (or whatever else of that ilk) using a four channel color argument with alpha set. To draw the problematical black color, feed polygon with color argument 0,0,0,255
  3. Canvas is now ready to be composed on top of whatever background image you may have in mind.

Hope this helps. BTW, love the color ambience of your work-in-progress. Keep on having fun…

1 Like

You just saved my day, i was getting some headache now lol.
I didn’t add an alpha layer at the start because for some reason drawing on that image would make some lines transparent instead of the background.
So in the end :

+to_a f. 0 # << changed this
ML=$1
MR:=100-$2
MT=$3
MB:=100-$4
m "rcol : u {[${17--1}][3*int(u(8)%8),3]},255" # << added ",255" to David's subcommand
if ${"is_pattern \"$12\""} pat=$12 else pat=0xFFFFFFFF badpat=1 fi

# ...
# A bunch of drawing stuff here:
repeat $5 { rectangle. {u($ML,$MR)}%,{u($MT,$MB)}%,{u($ML,$MR)}%,{u($MT,$MB)}%,1,$pat,${-rcol} } 
# ...
rv #  << still need to reverse in the end but that's ok

Result… looks like everyone’s here! Phew!:

Thanks :slight_smile:
EDIT : This also kinda solves my dilate/erode problem since dilate over alpha also thickens black lines: :sunglasses:

That looks like a math book cover. Still though, keep it up.