It is currently Thu Jul 02, 2026 8:16 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 16 posts ] 
Author Message
 Post subject: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Thu Oct 17, 2024 11:04 am  (#1) 
Offline
GimpChat Member

Joined: Apr 19, 2021
Posts: 138
Location: France
Hi everyone! :)

I intend to propose a new G'MIC filter "Rendering / Equation Plot [Implicit]".

With default parameters, it would give:
Attachment:
equationPlot.png
equationPlot.png [ 15.03 KiB | Viewed 8175 times ]

Here is its code:
#@gui ____<b>Rendering</b>
#------------------
#@gui Equation Plot [Implicit] (prerelease): cl_implicitEqua_prerelease, cl_implicitEqua_prerelease(1)
#@gui : note = note["Plot the equation: f(x,y)=0"]
#@gui : sep = separator()
#@gui : f(x,y) = text{"( x^2 + y^2 - 25 )   *   ( (x-2)^2 + (y-2)^2 - 1 )   *   ( (x+2)^2 + (y-2)^2 - 1 )   *   ( abs(x) + abs(y) - 1 )   *   ( x^2 + (4*y+12-x^2)^2 - 9 )"}
#@gui : Width (pixels) = int(500, 10, 2000)
#@gui : Height (pixels) = int(500, 10, 2000)
#@gui : Min x = float[-6, -10000, 10000]
#@gui : Max x = float[6, -10000, 10000]
#@gui : Min y = float[-6, -10000, 10000]
#@gui : Max y = float[6, -10000, 10000]
#@gui : Axes = bool(0)
#@gui : Grid = bool(0)
#@gui : Grid Cell Size = int(1,1,5)
#@gui : sep = separator()
#@gui : note = note("<small>Author: <i>Claude Lion</i>. Latest Update: <i>2024/10/17</i>.</small>")

cl_implicitEqua_prerelease:
   equ,w,h,minx,maxx,miny,maxy,axes,grid,gridSize=$"*"
   xlong={$maxx-$minx}
   ylong={$maxy-$miny}
   xscale={$w/$xlong}
   yscale={$h/$ylong}
   
   foreach {
      $w,$h,1,1,"x=x/$xscale+$minx;y=-y/$yscale-$miny;$1"
      +gradient_norm.
      fill. "255*   cut(   abs(i#-2),  0,  i   ) / i"
      rm..

      if $axes==1
         $w,$h,1,1,"X=x/$xscale+$minx;Y=-y/$yscale-$miny;X*Y"
         +gradient_norm.
         fill. "255*   cut(   abs(i#-2),  0,  i   ) / i"
         rm..
      else
         $w,$h,1,1,"255"
      fi

      if $grid==1
         $w,$h,1,1,"X=x/$xscale+$minx;Y=-y/$yscale-$miny;sin(pi*X/$gridSize)*sin(pi*Y/$gridSize)"
         +gradient_norm.
         fill. "255*   cut(   abs(i#-2),  0,  i   ) / i"
         rm..
      else
         $w,$h,1,1,"255"
      fi
      move[-1] -3
      append. [-2],c append. [-3],c
      rm.. rm.. move[-1] 0
   }

Installation:
  • Copy and paste the above code into the file "~/.gmic" on Linux or the file "%USERPROFILE%\user.gmic" on Windows.
  • The new filter appears in "Filters -> G'MIC -> Rendering -> Equation Plot [Implicit] (prerelease)".

EDIT: APPDATA has been replaced by USERPROFILE

Have fun! :)

_________________
Photo to cartoon : https://github.com/cl4cnam/gimp_cartoon_plugin


Last edited by cli345 on Fri Oct 18, 2024 4:41 pm, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Thu Oct 17, 2024 11:50 pm  (#2) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 8405
Location: On the other side of your screen
:bigthup

_________________
Image
Free Fun Photo Editing & resources
Poems from the Lord
Gimp Newby
Gimp version 3.2.0 and GMIC-Qt 3.7.5 OS :- Windows 10 Home 64


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Fri Oct 18, 2024 8:19 am  (#3) 
Offline
GimpChat Member

Joined: Apr 19, 2021
Posts: 138
Location: France
Thanks, Sallyanne, for your feedback. :)

Here are a few equation examples (paste them in the 'f(x,y)' field):

sin(cos(x*y)) + cos(atan(x*x+y)) - 1
Attachment:
plant.png
plant.png [ 14.18 KiB | Viewed 8102 times ]


x^2   +   (   y - sqrt(2*abs(x))   )^2   -   4
Attachment:
heart.png
heart.png [ 5.51 KiB | Viewed 8102 times ]


2*sin(x*y)*cos(x+y) - 1
Attachment:
mult.png
mult.png [ 32.34 KiB | Viewed 8102 times ]


Enjoy! :)

_________________
Photo to cartoon : https://github.com/cl4cnam/gimp_cartoon_plugin


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Fri Oct 18, 2024 2:35 pm  (#4) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16075
I can not get this filter to load in the newest GMIC-Qt (3.4.3) install. I placed the copied text (code) into Appdata\Roaming\user.gmic file and it does not appear in Rendering>
Even after Gimp relaunch.

_________________
Image


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Fri Oct 18, 2024 3:38 pm  (#5) 
Offline
GimpChat Member

Joined: Apr 19, 2021
Posts: 138
Location: France
What happens if you put user.gmic into the parent directory of AppData? That's where I've put it.

_________________
Photo to cartoon : https://github.com/cl4cnam/gimp_cartoon_plugin


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Fri Oct 18, 2024 4:00 pm  (#6) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16075
cli345 wrote:
What happens if you put user.gmic into the parent directory of AppData? That's where I've put it.

Same thing.

Image

_________________
Image


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Fri Oct 18, 2024 4:39 pm  (#7) 
Offline
GimpChat Member

Joined: Apr 19, 2021
Posts: 138
Location: France
I've just realized that I've written %APPDATA% which is the old location to be replaced by %USERPROFILE% (But that doesn't solve the problem of Rod).

_________________
Photo to cartoon : https://github.com/cl4cnam/gimp_cartoon_plugin


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Fri Oct 18, 2024 5:03 pm  (#8) 
Offline
GimpChat Member

Joined: Apr 19, 2021
Posts: 138
Location: France
Rod, right now, I can't reproduce the problem. Can you try on another computer? Is the first line of user.gmic '#@gui ____<b>Rendering</b>'? Is the last line of user.gmic '}'?

Do other users have the same problem?

_________________
Photo to cartoon : https://github.com/cl4cnam/gimp_cartoon_plugin


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Fri Oct 18, 2024 11:11 pm  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2644
Location: Poland
For some time now G'MIC has had the option to select "Filter sources" in "Settings...".
You can select any name in any location.
You don't even have to restart G'MIC (when you click OK the filter will be added to the filter menu).


Attachments:
user_gmic.jpg
user_gmic.jpg [ 47.75 KiB | Viewed 8046 times ]
user_gmic_settings.jpg
user_gmic_settings.jpg [ 141.75 KiB | Viewed 8046 times ]

_________________
Image
Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Sat Oct 19, 2024 12:02 am  (#10) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16075
MareroQ wrote:
For some time now G'MIC has had the option to select "Filter sources" in "Settings...".
You can select any name in any location.
You don't even have to restart G'MIC (when you click OK the filter will be added to the filter menu).

WOW! I did not know this was n the settings. Awesome and thank you MareroQ. Thanks to you also cli345.

Worked perfectly. :bigthup

_________________
Image


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Sat Oct 19, 2024 8:52 am  (#11) 
Offline
GimpChat Member

Joined: Apr 19, 2021
Posts: 138
Location: France
Thanks, MareroQ. :)

A few other examples:

abs(-y/2)+abs(x*x/4+sin(-y/2)-1)-1
Attachment:
collar.png
collar.png [ 6.65 KiB | Viewed 7994 times ]


sin(y)+abs(x*x+cos(y)-1)-1
Attachment:
eggs.png
eggs.png [ 11.41 KiB | Viewed 7994 times ]


log(x*x+y*y+1)-sin(x*y+2*x+2*y)-1
Attachment:
four.png
four.png [ 7.18 KiB | Viewed 7994 times ]

_________________
Photo to cartoon : https://github.com/cl4cnam/gimp_cartoon_plugin


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Sat Oct 19, 2024 2:20 pm  (#12) 
Offline
GimpChat Member

Joined: Oct 16, 2017
Posts: 45
If someone can confirm my code revision works the same, I'll push the filter into gmic-community:

#@gui Equation Plot [Implicit]: cl_implicitEqua, cl_implicitEqua(1)
#@gui : note = note["Plot the equation: f(x,y)=0"]
#@gui : sep = separator()
#@gui : f(x,y) = text{"( x^2 + y^2 - 25 )   *   ( (x-2)^2 + (y-2)^2 - 1 )   *   ( (x+2)^2 + (y-2)^2 - 1 )   *   ( abs(x) + abs(y) - 1 )   *   ( x^2 + (4*y+12-x^2)^2 - 9 )"}
#@gui : Width (pixels) = int(500, 10, 2000)
#@gui : Height (pixels) = int(500, 10, 2000)
#@gui : Min x = float[-6, -10000, 10000]
#@gui : Max x = float[6, -10000, 10000]
#@gui : Min y = float[-6, -10000, 10000]
#@gui : Max y = float[6, -10000, 10000]
#@gui : Axes = bool(0)
#@gui : Grid = bool(0)
#@gui : Grid Cell Size = int(1,1,5)
#@gui : sep = separator()
#@gui : url = link("Filter discussed here","http://gimpchat.com/viewtopic.php?f=28&t=21315")
#@gui : note = note("<small>Author: <i>Claude Lion</i>. Latest Update: <i>2024/10/17</i>.</small>")
cl_implicitEqua:
   equ,w,h,minx,maxx,miny,maxy,axes,grid,gridSize=$"*"
   xlong:=$maxx-$minx
   ylong:=$maxy-$miny
   xscale:=$w/$xlong
   yscale:=$h/$ylong

   foreach {
      $w,$h,1,1,"
         x=x/$xscale+$minx;
         y=-y/$yscale-$miny;
         $1"
      +gradient_norm.
      fill. "255 * cut( abs(i#-2), 0, i  ) / i"
      rm..

      if $axes==1
         $w,$h,1,1,"X=x/$xscale+$minx;Y=-y/$yscale-$miny;X*Y"
         +gradient_norm.
         fill. "255 * cut( abs(i#-2), 0, i  ) / i"
         rm..
      else
         $w,$h,1,1,255
      fi

      if $grid==1
         $w,$h,1,1,"
            X=x/$xscale+$minx;
            Y=-y/$yscale-$miny;
            sin(pi*X/$gridSize)*sin(pi*Y/$gridSize);"
         +gradient_norm.
         fill. "255 * cut( abs(i#-2), 0, i  ) / i"
         rm..
      else
         $w,$h,1,1,255
      fi

      move[-1] -3
      append[-3,-2] c
      rm[-2,-1]
      move[-1] 0
   }


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Sat Oct 19, 2024 3:40 pm  (#13) 
Offline
GimpChat Member

Joined: Apr 19, 2021
Posts: 138
Location: France
Thanks, Reptorian, it's a good idea. :)
Unfortunately, it doesn't work for me: it doesn't produce a drawing. :(
I think it's because "append. [-2],c append. [-3],c" wouldn't be equivalent to "append[-3,-2] c" and "rm[-2,-1]" wouldn't be equivalent to "rm.. rm.."

_________________
Photo to cartoon : https://github.com/cl4cnam/gimp_cartoon_plugin


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Sat Oct 19, 2024 5:03 pm  (#14) 
Offline
GimpChat Member

Joined: Oct 16, 2017
Posts: 45
cli345 wrote:
I think it's because "append. [-2],c append. [-3],c" wouldn't be equivalent to "append[-3,-2] c" and "rm[-2,-1]" wouldn't be equivalent to "rm.. rm.."


Yeah, that's why.

However, I do think multiple image inputs is what you should go for, it makes code shorter, easier to read too.


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Sun Oct 20, 2024 11:57 am  (#15) 
Offline
GimpChat Member

Joined: Oct 16, 2017
Posts: 45
Ok, I pushed this filter with the changes cli345 provided to my untested from my end code. So, it's a official gmic-community filter.


Top
 Post subject: Re: New G'MIC filter "Rendering / Equation Plot [Implicit]"
PostPosted: Mon Oct 21, 2024 7:20 am  (#16) 
Offline
GimpChat Member

Joined: Apr 19, 2021
Posts: 138
Location: France
Thanks, Reptorian.

_________________
Photo to cartoon : https://github.com/cl4cnam/gimp_cartoon_plugin


Top
Post new topic Reply to topic  [ 16 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group