Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

My fullest first python script "Heart"

Thu May 07, 2020 7:03 pm

Hi again everyone! This is my first complete python script. I'so happy I'm learning some of this stuff! Well, this is the heart that I created out of my script-fu script "Create a heart". Be safe!

The only thing I got stuck is on the color. Some how I could not make change the colors.

Image

Re: My fullest first python script "Heart"

Fri May 08, 2020 9:12 am

Pocholo wrote:Hi again everyone! This is my first complete python script. I'so happy I'm learning some of this stuff! Well, this is the heart that I created out of my script-fu script "Create a heart". Be safe!

The only thing I got stuck is on the color. Some how I could not make change the colors.


You define bgcolor/fgcolor input variables but you don't use them anywhere in your code... Try changing:
Code:
pdb.gimp_context_set_foreground ((191, 35, 57))
to
Code:
pdb.gimp_context_set_foreground (fgColor)


Likewise you define a "size" input variable but it appears nowhere, instead you use SIZE which is a fixed size(*). In things like
Code:
pdb.gimp_image_select_ellipse(img, 2, 60, 105, 385, 285)
, all the numbers should be computed from "size" (and also some other implicit data such as a margin width and an aspect ratio). If you determined these numbers by computing them it is easy since you just write the formulas in python. If you obtained them by tinkering with values until it worked(**) then you are stuck, and you have to wonder how you can determine these values algorithmically instead (ie, how should they change when you change the size and other factors).

By rewriting you thing in Python you have discovered that knowing a prorgramming language is necessary but not sufficient. What really counts is the logical mind, and if you deal with images, some proficiency in math.

(*) and is a capital sin... Using defined constants is nice, but one expects to be able to change only SIZE and get everything else in the code to change accordingly, but you still have plenty of hardcoded numbers elsewhere, so using SIZE is misleading and does more harm than good at this point.

(**) This 44.75 angle, for instance.

Re: My fullest first python script "Heart"

Fri May 08, 2020 11:55 am

Thanks a lot, Onuts. I 'm working in the script as I respond! :coolthup
Post a reply