 |
| Script Coder |
 |
Joined: May 07, 2014 Posts: 4527 Location: Canada
|
You're welcome, if you scale the pattern, then we gotta change the plug-in too so that the coloring aligned with the texture mapping. What did you scale the pattern down by, what fraction or percentage? 1/2? Here ya go Bella, this will allow you to tell plug-in what fraction/scale you scaled down pattern by, you can choose between half,third,forth,...all the way to a tenth of pattern size. #!/usr/bin/env python
from gimpfu import * import math def knit(image,layer,scale): pdb.gimp_image_undo_group_start(image) scale = int(scale) scale = 1.0/(scale+2) #if it's 0 scale becomes half, if it's option 8 it becomes 1/10th. #104 x 65 is the pattern dimension p_width = 104/4*scale p_height = 65/4*scale for y in range(0,int(math.ceil(layer.height/p_height+1))): pdb.gimp_progress_update(1.0*y*p_height/layer.height) for x in range(0,int(math.ceil(layer.width/p_width+1))): x1 = x * p_width y1 = y * p_height points = [x1+10/4*scale,y1,x1+48/4*scale,y1+46/4*scale,x1+78/4*scale,y1,x1+104/4*scale,y1-39/4*scale,x1+104/4*scale,y1+26/4*scale,x1+48/4*scale,y1+111/4*scale,x1,y1+53/4*scale,x1+0,y1-12/4*scale] pdb.gimp_image_select_polygon(image,CHANNEL_OP_REPLACE,16,points) if (pdb.gimp_selection_is_empty(image)==TRUE): pass else: R,std_dev,median,pixels,count,percent = pdb.gimp_drawable_histogram(layer,HISTOGRAM_RED,0,1) G,std_dev,median,pixels,count,percent = pdb.gimp_drawable_histogram(layer,HISTOGRAM_GREEN,0,1) B,std_dev,median,pixels,count,percent = pdb.gimp_drawable_histogram(layer,HISTOGRAM_BLUE,0,1) pdb.gimp_context_set_foreground((int(R),int(G),int(B))) pdb.gimp_edit_fill(layer,FILL_FOREGROUND) pdb.gimp_image_undo_group_end(image) pdb.gimp_selection_none(image)
register( "python_fu_tt_knit_colors", "Colors the image like as if it's knitted", "Colors the image like as if it's knitted", "author name", "copyright name", "2024.11.09", "A Knit Colors", "RGB*", # Alternately use RGB, RGB*, GRAY*, INDEXED etc. [ #INPUT BEGINS (PF_IMAGE, "image", "IMAGE:", None), (PF_DRAWABLE, "layer", "DRAWABLE:", None), (PF_OPTION,"scale", "Scaling Pattern:", 0, ["1 half","1 third","1 quarter","1 fifth","1 sixth","1 seventh","1 eighth","1 nineth","1 tenth"]), # initially 0th is choice #INPUT ENDS ], [], knit, 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
|
|