Changeset - 50ba9ec2b17e
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 20 years ago 2005-06-18 06:09:28
drewp@bigasterisk.com
you can now delete curve points
2 files changed with 26 insertions and 6 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -344,13 +344,13 @@ def savekey(*args):
 
    print "saved"
 
    
 
root.bind("<Control-Key-s>",savekey)
 
root.bind("<Control-Key-r>", lambda evt: dispatcher.send('reload all subs'))
 

	
 
create_status_lines(root)
 
for helpline in ["Bindings: C-s save subterms; B1 drag point; C-B1 curve add point; S-B1 sketch points; 1..5 add point at time; Esc see current time; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse",
 
for helpline in ["Bindings: C-s save subterms; B1 drag point; C-B1 curve add point; S-B1 sketch points; Del point under mouse; 1..5 add point at time; Esc see current time; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse",
 
                 "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; curvename(t) eval curve"]:
 
    tk.Label(root,text=helpline, font="Helvetica -12 italic",
 
             anchor='w').pack(side='top',fill='x')
 

	
 
#def logprint(msg):
 
#    print "log",msg
light9/curve.py
Show inline comments
 
@@ -68,12 +68,17 @@ def angle_between(base, p0, p1):
 
    p0 = [x/vlen(p0) for x in p0]
 
    p1 = [x/vlen(p1) for x in p1]
 
    dot = p0[0]*p1[0]+p0[1]*p1[1]
 
    dot = max(-1,min(1,dot))
 
    return math.degrees(math.acos(dot))
 

	
 
def slope(p1,p2):
 
    if p2[0] == p1[0]:
 
        return 0
 
    return (p2[1] - p1[1]) / (p2[0] - p1[0])
 

	
 
class Sketch:
 
    """a sketch motion on a curveview, with temporary points while you
 
    draw, and simplification when you release"""
 
    
 
    def __init__(self,curveview,ev):
 
        self.curveview = curveview
 
@@ -114,16 +119,12 @@ class Sketch:
 
            p = pts[i]
 
            if abs(self.curveview.curve(p[0]) - p[1]) > .1:
 
                self.curveview.add_point(p)
 
            
 
        self.curveview.update_curve()
 

	
 
    def slope(self,p1,p2):
 
        if p2[0] == p1[0]:
 
            return 0
 
        return (p2[1] - p1[1]) / (p2[0] - p1[0])
 

	
 
class Curveview(tk.Canvas):
 
    def __init__(self,master,curve,**kw):
 
        self.curve=curve
 
        self._time = 0
 
        tk.Canvas.__init__(self,master,width=10,height=10,
 
@@ -299,17 +300,32 @@ class Curveview(tk.Canvas):
 
            self.tag_bind('handle%d' % i,"<ButtonPress-1>",
 
                          lambda ev,i=i: self.dotpress(ev,i))
 
            self.bind("<Motion>",
 
                      lambda ev,i=i: self.dotmotion(ev,i))
 
            self.bind("<ButtonRelease-1>",
 
                      lambda ev,i=i: self.dotrelease(ev,i))
 
            #self.tag_bind('handle%d' % i, "<Key-d>",
 
            #              lambda ev, i=i: self.remove_point_idx(i))
 
                      
 
            self.dots[i]=dot
 

	
 
        def delpoint(ev):
 
            # had a hard time tag_binding to the points, so i trap at
 
            # the widget level (which might be nice anyway when there
 
            # are multiple pts selected)
 
            tags = self.gettags(self.find_closest(ev.x, ev.y))
 
            try:
 
                handletags = [t for t in tags if t.startswith('handle')]
 
                i = int(handletags[0][6:])
 
            except IndexError:
 
                return
 
            self.remove_point_idx(i)
 
        self.bind("<Key-Delete>", delpoint)
 

	
 
        self.highlight_selected_dots()
 
        
 

	
 
    def newpointatmouse(self, ev):
 
        p = self.world_from_screen(ev.x,ev.y)
 
        x, y = p
 
        y = max(0, y)
 
        y = min(1, y)
 
        p = x, y
 
@@ -317,12 +333,16 @@ class Curveview(tk.Canvas):
 

	
 
    def add_point(self, p):
 
        self.unselect()
 
        self.curve.insert_pt(p)
 
        self.update_curve()
 

	
 
    def remove_point_idx(self, i):
 
        self.curve.points.pop(i)
 
        self.update_curve()
 

	
 
    def highlight_selected_dots(self):
 
        for i,d in self.dots.items():
 
            if i in self.selected_points:
 
                self.itemconfigure(d,fill='red')
 
            else:
 
                self.itemconfigure(d,fill='blue')
0 comments (0 inline, 0 general)