It is currently Tue Aug 11, 2026 1:01 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 20 posts ] 
Author Message
 Post subject: Selecting Alternating Diagonals Plug-in
PostPosted: Thu Oct 24, 2024 5:48 am  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
For when you want to make plaid-patterns with solid color diagonals instead of 50% opacity
Alternately, you can do a manual slower method by erasing every other line on a solid layer then rotate 45 degrees but then your solid layer has to be larger than your plaid design area. And it's slower to erase lines and rotate
that's why this plug-in is here.
It simply makes selections of alternating diagonals so that you can use to delete the top layer of your plaid design in one direction to reveal the bottom layer of the other direction of plaid pattern.
bottom layer, plaid design of one direction
Image
top layer, plaid design of 2nd direction
Image
run plug-in to make diagonals selection and delete from top layer to reveal part of 2nd layer. Done
Image

Plug-in code below
#!/usr/bin/env python
# Author: (Tin Tran)
# Created On: 2024.08.03
# My own grunty bot/script that will take select alternating diagonals
# to delete from top layer to reveal lower layer to create plaid-patterns.
# Spawned/Inspired by my http://plaid-patterns.com javascript plaid designer.
#
#
# License: Whatever GIMP's License is.
# Revisions:
# Rel 0.10: Initial Version
from gimpfu import *
import random
import math
import os
def select_diagonals(image,layer,dia_hor_width):
    double_edge = layer.width+layer.height #get sum of width and height
    y1 = 0; y2 = 0; #these don't change because we're going right to the edges
    x3 = 0; x4 = 0;
    pdb.gimp_selection_none(image) #clear selection because we'll be selecting diagonals
    for i in range(0,int(math.ceil(double_edge/dia_hor_width))):
        if (i % 2 == 0): #alternating it
            x1 = i*dia_hor_width
            x2 = (i+1)*dia_hor_width
            y3 = (i+1)*dia_hor_width
            y4 = i*dia_hor_width

            #select each diagonal stripe
            pdb.gimp_image_select_polygon(image,CHANNEL_OP_ADD,8,[x1,y1,x2,y2,x3,y3,x4,y4])

register(
    "python_fu_select_diagonals",
    "description",
    "longer description",
    "author name",
    "copyright name",
    "2024.10.24",
    "A Select Diagonals",
    "RGB*",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    (PF_IMAGE, "image", "Image", None),
    (PF_DRAWABLE,   "layer", "Drawable", None),
    (PF_INT, "dia_hor_width", "Diagonal Horizontal Width:", 4),
    #INPUT ENDS
    ],
    [],
    select_diagonals,
    menu="<Image>/Python-Fu")

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste (found online years back that I didn't want to constantly look up)
# Since GIMP is free anyways, I thought it would be handy here for me to CUT and PASTE, CHANGE, USE.
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.


_________________
TinT


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: Selecting Alternating Diagonals Plug-in
PostPosted: Thu Oct 24, 2024 6:39 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2648
Location: Poland
A very interesting possibility. :hi5


Attachments:
sample_colorful.png
sample_colorful.png [ 337 KiB | Viewed 3318 times ]

_________________
Image
Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Thu Oct 24, 2024 8:15 am  (#3) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16155
Yeah this is going to be an interesting filter to play with. I am thinking along the engrave possibilities. ;)

_________________
Image


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Thu Oct 24, 2024 10:06 am  (#4) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
I don't know much about that engraving stuff. But anything it can be used for is cool. :D

_________________
TinT


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Thu Oct 24, 2024 6:31 pm  (#5) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
This version is slightly faster since it tries to only select within the image and not outside of it
#!/usr/bin/env python
# Author: (Tin Tran)
# Created On: 2024.08.03
# My own grunty bot/script that will take select alternating diagonals
# to delete from top layer to reveal lower layer to create plaid-patterns.
# Spawned/Inspired by my http://plaid-patterns.com javascript plaid designer.
#
#
# License: Whatever GIMP's License is.
# Revisions:
# Rel 0.10: Initial Version
from gimpfu import *
import random
import math
import os
def select_diagonals(image,layer,dia_hor_width):
    double_edge = layer.width+layer.height #get sum of width and height
    y1 = 0; y2 = 0; #these don't change because we're going right to the edges
    x3 = 0; x4 = 0;
    pdb.gimp_selection_none(image) #clear selection because we'll be selecting diagonals
    for i in range(0,int(math.ceil(double_edge/dia_hor_width))):
        if (i % 2 == 0): #alternating it
            x1 = i*dia_hor_width
            x2 = (i+1)*dia_hor_width
            y3 = (i+1)*dia_hor_width
            y4 = i*dia_hor_width

            if x1 > layer.width: #a corner reached for point 1 and 2
                y1 = x1-layer.width
                x1 = layer.width
                y2 = x2-layer.width
                x2 = layer.width

            if y4 > layer.height: #a cornder reached for point 3 and 4
                x3 = y3 - layer.height
                y3 = layer.height
                x4 = y4 - layer.height
                y4 = layer.height
                               
            #select each diagonal stripe
            pdb.gimp_image_select_polygon(image,CHANNEL_OP_ADD,8,[x1,y1,x2,y2,x3,y3,x4,y4])

register(
    "python_fu_select_diagonals",
    "description",
    "longer description",
    "author name",
    "copyright name",
    "2024.10.24",
    "A Select Diagonals",
    "RGB*",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    (PF_IMAGE, "image", "Image", None),
    (PF_DRAWABLE,   "layer", "Drawable", None),
    (PF_INT, "dia_hor_width", "Diagonal Horizontal Width:", 4),
    #INPUT ENDS
    ],
    [],
    select_diagonals,
    menu="<Image>/Python-Fu")

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste (found online years back that I didn't want to constantly look up)
# Since GIMP is free anyways, I thought it would be handy here for me to CUT and PASTE, CHANGE, USE.
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.


_________________
TinT


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Fri Oct 25, 2024 4:24 am  (#6) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16155
trandoductin wrote:
I don't know much about that engraving stuff. But anything it can be used for is cool. :D

What i was thinking was that if you have a bunch of different black and white line layers going different directions you could use a layer mode to effect an engraved look. Especially if you could use paths to create the lines.

_________________
Image


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Mon Oct 28, 2024 10:49 pm  (#7) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
fun with google notebook LM
www.youtube.com Video from : www.youtube.com

_________________
TinT


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Tue Oct 29, 2024 1:49 am  (#8) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16155
Nice job Tran! :)

_________________
Image


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Tue Oct 29, 2024 9:12 am  (#9) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
Rod wrote:
Nice job Tran! :)

I didn't do anything, notebook LM is smart enough to talk about anything.

_________________
TinT


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Thu Oct 31, 2024 3:00 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: Mar 01, 2014
Posts: 14119
Location: Spain, Aragón
Tin, your plug-in is great and very useful to decorate. Thanks a lot. :coolthup

_________________
Image

Gimp 2.10.30(samj) portable _ OS Windows 10 Home_ 64bits
Don’t be afraid to start over. It’s a new chance to rebuild what you want.


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Fri Nov 01, 2024 4:26 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2648
Location: Poland
The plugin is very fast - it takes less time to start than to execute (I even thought for a moment that it didn't work).
I took the liberty of extending Your plugin.

A few small examples:
Image

Image

Image

Image

Image

Edit:In order not to confuse the thread, this version will be continued here:
viewtopic.php?f=9&t=21469


Attachments:
Striped Selection - Gui.jpg
Striped Selection - Gui.jpg [ 56.12 KiB | Viewed 3055 times ]
Having fun with layer mode.png
Having fun with layer mode.png [ 542.83 KiB | Viewed 3055 times ]
Striped Selection.zip [2.02 KiB]
Downloaded 191 times

_________________
Image


Last edited by MareroQ on Mon Dec 23, 2024 4:46 pm, edited 1 time in total.
Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Fri Nov 01, 2024 1:05 pm  (#12) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
Wow, so many options.

_________________
TinT


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Sat Dec 07, 2024 1:22 pm  (#13) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
for kicks I have shared this on mybb forum a brand-spanking new forum that I just created for hopefully plaid-patterns.com related or patterns related stuff https://plaid-patterns.com/myBB/Upload/ ... .php?tid=2

_________________
TinT


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Sat Dec 07, 2024 2:30 pm  (#14) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16155
MareroQ wrote:
The plugin is very fast - it takes less time to start than to execute (I even thought for a moment that it didn't work).
I took the liberty of extending Your plugin.

A few small examples:
[ Image ]

[ Image ]

[ Image ]

[ Image ]

[ Image ]

This is exactly what i was talking about. If you could add wavy lines it would result in a really good engraver effect i think. Like the lines on money.

_________________
Image


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Sat Dec 07, 2024 3:46 pm  (#15) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
wavy line you say.... I wonder..... if it's simple enough to hack out somehow.
Time to do go some money wavy lines research.

_________________
TinT


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Sat Dec 07, 2024 4:26 pm  (#16) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
Ok, research is complete.
Here's the final product "A Select Waves". You can adjust wave-length and wave-height (which is the height from bottom of a wave to top of single wave not including thickness of wave).

Image
Here's the code below (and attached zipped .py file):
#!/usr/bin/env python
# Author: (Tin Tran)
# Created On: 2024.08.03
# My own grunty bot/script that will take select alternating diagonals
# to delete from top layer to reveal lower layer to create plaid-patterns.
# Spawned/Inspired by my http://plaid-patterns.com javascript plaid designer.
#
#
# License: Whatever GIMP's License is.
# Revisions:
# Rel 0.10: Initial Version
from gimpfu import *
import random
import math
import os
def select_waves(image,layer,wavelength,waveheight):
    waveheight = waveheight/2; #only take half because we're dealing with math.sin
    coords1 = [];
    coords2 = [];
    for x in range(0,layer.width):
        y = math.sin((x*1.0/wavelength)*2.0*math.pi)*waveheight - waveheight*3;
        coords1.append(x)
        coords1.append(y)
        coords2.append(x)
        coords2.append(y+waveheight);
    coords2r = []   
    for i in range(len(coords2)-1,-1,-2):
        coords2r.append(coords2[i-1])
        coords2r.append(coords2[i])
    coords = coords1+coords2r;
    pdb.gimp_selection_none(image)
    for i in range(-waveheight*2,layer.height,waveheight*2):
        for j in range(0,len(coords),2):
            coords[j+1] += waveheight*2;
        pdb.gimp_image_select_polygon(image,CHANNEL_OP_ADD,len(coords),coords)


register(
    "python_fu_select_waves",
    "description",
    "longer description",
    "author name",
    "copyright name",
    "2024.10.24",
    "A Select Waves",
    "RGB*",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    (PF_IMAGE, "image", "Image", None),
    (PF_DRAWABLE,   "layer", "Drawable", None),
    (PF_INT, "wavelength", "Wave-Length (pixels):",50),
    (PF_INT, "waveheight", "Wave-Height (pixels):",25),
    #INPUT ENDS
    ],
    [],
    select_waves,
    menu="<Image>/Python-Fu")

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste (found online years back that I didn't want to constantly look up)
# Since GIMP is free anyways, I thought it would be handy here for me to CUT and PASTE, CHANGE, USE.
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.

Shared to https://plaid-patterns.com/myBB/Upload/ ... .php?tid=4


Attachments:
File comment: select waves.py
select-waves.zip [2.02 KiB]
Downloaded 90 times

_________________
TinT


Last edited by trandoductin on Sat Dec 07, 2024 4:51 pm, edited 1 time in total.
Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Sat Dec 07, 2024 4:38 pm  (#17) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16155
Thanks Tran!! I will be playing with this to make some money custom font. :)

_________________
Image


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Sat Dec 07, 2024 4:46 pm  (#18) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
Right on! you're welcome it was was fun building and testing it.

_________________
TinT


Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Sat Dec 07, 2024 5:26 pm  (#19) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
Here's "A Select Zigzag" letting specifying wave-length, wave-height.
Image
Here's the code [attached is zipped .py file]:
#!/usr/bin/env python
# Author: (Tin Tran)
# Created On: 2024.08.03
# My own grunty bot/script that will take select alternating diagonals
# to delete from top layer to reveal lower layer to create plaid-patterns.
# Spawned/Inspired by my http://plaid-patterns.com javascript plaid designer.
#
#
# License: Whatever GIMP's License is.
# Revisions:
# Rel 0.10: Initial Version
from gimpfu import *
import random
import math
import os
def select_zigzag(image,layer,wavelength,waveheight):
    waveheight = waveheight/2; #only take half because we're dealing with math.sin
    coords1 = [];
    coords2 = [];
    count = 0;
    for x in range(0,layer.width+wavelength,wavelength/2):
        if (count % 2 == 0):
            y = -waveheight*4;
        else:
            y = -waveheight*2;
        count += 1; #alternate zig and zag
           
        coords1.append(x)
        coords1.append(y)
        coords2.append(x)
        coords2.append(y+waveheight);
    coords2r = []   
    for i in range(len(coords2)-1,-1,-2):
        coords2r.append(coords2[i-1])
        coords2r.append(coords2[i])
    coords = coords1+coords2r;
    pdb.gimp_selection_none(image)
    for i in range(-waveheight*2,layer.height,waveheight*2):
        for j in range(0,len(coords),2):
            coords[j+1] += waveheight*2;
        pdb.gimp_image_select_polygon(image,CHANNEL_OP_ADD,len(coords),coords)


register(
    "python_fu_select_zigzag",
    "description",
    "longer description",
    "author name",
    "copyright name",
    "2024.10.24",
    "A Select Zigzag",
    "RGB*",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    (PF_IMAGE, "image", "Image", None),
    (PF_DRAWABLE,   "layer", "Drawable", None),
    (PF_INT, "wavelength", "Wave-Length (pixels):",50),
    (PF_INT, "waveheight", "Wave-Height (pixels):",25),
    #INPUT ENDS
    ],
    [],
    select_zigzag,
    menu="<Image>/Python-Fu")

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste (found online years back that I didn't want to constantly look up)
# Since GIMP is free anyways, I thought it would be handy here for me to CUT and PASTE, CHANGE, USE.
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.


Shared to https://plaid-patterns.com/myBB/Upload/ ... .php?tid=5


Attachments:
File comment: zipped .py file of code.
select-zigzag.zip [2.06 KiB]
Downloaded 82 times

_________________
TinT
Top
 Post subject: Re: Selecting Alternating Diagonals Plug-in
PostPosted: Sat Dec 07, 2024 6:39 pm  (#20) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
"A Select Swiggly" aka "curly braces wave select"
Image
Code below (and attached zipped .py file)
#!/usr/bin/env python
# Author: (Tin Tran)
# Created On: 2024.08.03
# My own grunty bot/script that will take select alternating diagonals
# to delete from top layer to reveal lower layer to create plaid-patterns.
# Spawned/Inspired by my http://plaid-patterns.com javascript plaid designer.
#
#
# License: Whatever GIMP's License is.
# Revisions:
# Rel 0.10: Initial Version
from gimpfu import *
import random
import math
import os
def select_swiggly(image,layer,wavelength,waveheight):
    waveheight = waveheight/2; #only take half because we're dealing with math.sin
    coords1 = [];
    coords2 = [];
    count = 0;
    for x in range(0,layer.width+wavelength):
        mod_value = x % (wavelength*2)
        if mod_value <= wavelength:
            ix = mod_value  # 1 to 6
            y = math.sin((x*1.0/wavelength)*2.0*math.pi)*waveheight+ix;
        else:
            ix = wavelength*2 - mod_value  # 5 to 1
            y = -math.sin((x*1.0/wavelength)*2.0*math.pi)*waveheight+ix;
        y -= wavelength;
        coords1.append(x)
        coords1.append(y)
        coords2.append(x)
        coords2.append(y+waveheight);
    coords2r = []   
    for i in range(len(coords2)-1,-1,-2):
        coords2r.append(coords2[i-1])
        coords2r.append(coords2[i])
    coords = coords1+coords2r;
    pdb.gimp_selection_none(image)
    for i in range(-waveheight*2,layer.height,waveheight*2):
        for j in range(0,len(coords),2):
            coords[j+1] += waveheight*2;
        pdb.gimp_image_select_polygon(image,CHANNEL_OP_ADD,len(coords),coords)


register(
    "python_fu_select_swiggly",
    "description",
    "longer description",
    "author name",
    "copyright name",
    "2024.10.24",
    "A Select Swiggly",
    "RGB*",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    (PF_IMAGE, "image", "Image", None),
    (PF_DRAWABLE,   "layer", "Drawable", None),
    (PF_INT, "wavelength", "Wave-Length (pixels):",50),
    (PF_INT, "waveheight", "Wave-Height (pixels):",25),
    #INPUT ENDS
    ],
    [],
    select_swiggly,
    menu="<Image>/Python-Fu")

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste (found online years back that I didn't want to constantly look up)
# Since GIMP is free anyways, I thought it would be handy here for me to CUT and PASTE, CHANGE, USE.
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.

Shared to https://plaid-patterns.com/myBB/Upload/ ... .php?tid=6


Attachments:
select-swiggly.zip [2.11 KiB]
Downloaded 66 times

_________________
TinT
Top
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group