ベジェ曲線を描くGIMPプラグイン

gimp-python-bezier-curve-sample.png
gimp-python-bezier-curve-sample.png
時間で光を切り替えるコードを書くための、彩度の関数を作るのに必要であった。
制御点への距離は20pxがちょうど良さそう。これって3時間=日の出日の入りの時刻よね、よく考えたら。
from gimpfu import *
def plugin_bezier(_img, _drawable,_ctrl_distance):
    pdb.gimp_image_flip(_img, ORIENTATION_VERTICAL)# upside down
    vectors=pdb.gimp_vectors_new(_img,"miffy_path"+str(_ctrl_distance))#make miffy_path
    pdb.gimp_image_add_vectors(_img,vectors,0)
    points=[]
    x=[0,60,120,180,240]#x position of anchor points
    y=[150,100,200,28,150]#y position of anchor points
    for i in range(0,len(x)):
               points.append(x[i]-_ctrl_distance)
               points.append(y[i])
               points.append(x[i])
               points.append(y[i])
               points.append(x[i]+_ctrl_distance)
               points.append(y[i])
    stroke_id=pdb.gimp_vectors_stroke_new_from_points(vectors,0,len(points),points,FALSE)
    pdb.gimp_vectors_set_visible(vectors, TRUE)
    pdb.gimp_image_flip(_img, ORIENTATION_VERTICAL)# upside down
register(
        "plugin_bezier",
        "dots",
        "dots",
        "Miffy Sora",
        "Miffy Sora",
        "2013",
        "<Image>/Image/Bezier...",
        "RGB*, GRAY*",
        [
            (PF_INT,"_ctrl_distance","control point distance(px)",10)
        ],
        [],
        plugin_bezier)
 
main()

ベジェ関数を使わずにfor文でベジェ曲線を描く

bez.png
本当は配列に入れてから実行したほうが早いんだろうけど、C++で組むための実験だからね
from gimpfu import *
def plugin_handmade_bezier(_img, _drawable):
    ctrl_distance=30;
    pdb.gimp_image_flip(_img, ORIENTATION_VERTICAL)# upside down
    pdb.gimp_context_set_foreground((255,255,0))
    points=[]
    x=[0,60,120,180,240]#x position of anchor points
    y=[150,100,200,28,150]#y position of anchor points
    pdb.gimp_message("begin")
    for i in range(0,len(x)):
               points.append([(x[i]-ctrl_distance),(y[i])])
               points.append([(x[i]),(y[i])])
               points.append([(x[i]+ctrl_distance),(y[i])])
    pdb.gimp_message("end len="+str(len(points)))
    for i in range(1,len(points)-2,3):
    #for i in range(1,len(points)-11,3):
        #control points
        p0=points[i]
        p1=points[(i+1)]
        p2=points[(i+2)]
        p3=points[(i+3)]
        for ti in range(0,100):
            t=float(ti)*0.01
            #step1 points
            p10=[]
            p10.append((1.0-t)*float(p0[0])+t*float(p1[0]))
            p10.append((1.0-t)*float(p0[1])+t*float(p1[1]))
            p11=[]
            p11.append((1.0-t)*float(p1[0])+t*float(p2[0]))
            p11.append((1.0-t)*float(p1[1])+t*float(p2[1]))
            p12=[]
            p12.append((1.0-t)*float(p2[0])+t*float(p3[0]))
            p12.append((1.0-t)*float(p2[1])+t*float(p3[1]))
            #step2 points
            p20=[]
            p20.append((1.0-t)*float(p10[0])+t*float(p11[0]))
            p20.append((1.0-t)*float(p10[1])+t*float(p11[1]))
            p21=[]
            p21.append((1.0-t)*float(p11[0])+t*float(p12[0]))
            p21.append((1.0-t)*float(p11[1])+t*float(p12[1]))
            #step3 points
            p30=[]
            p30.append((1.0-t)*float(p20[0])+t*float(p21[0]))
            p30.append((1.0-t)*float(p20[1])+t*float(p21[1]))
            pdb.gimp_context_set_foreground((233,120,52))
            pdb.gimp_pencil(_drawable,2,p30)
        pdb.gimp_context_set_foreground((0,0,255))
        pdb.gimp_pencil(_drawable,2,p0)
        pdb.gimp_pencil(_drawable,2,p3)
    pdb.gimp_message("end for")
    pdb.gimp_image_flip(_img, ORIENTATION_VERTICAL)# upside down
 
register(
        "plugin_handmade_bezier",
        "plugin_handmade_bezier",
        "plugin_handmade_bezier",
        "Miffy Sora",
        "Miffy Sora",
        "2013",
        "<Image>/Image/HandMade Bezier...",
        "RGB*, GRAY*",
        [],
        [],
        plugin_handmade_bezier)
 
main()

bezier

サポートサイト Wikidot.com bezier