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
 
@@ -347,7 +347,7 @@ 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')
light9/curve.py
Show inline comments
 
@@ -71,6 +71,11 @@ def angle_between(base, p0, p1):
 
    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"""
 
@@ -117,10 +122,6 @@ class Sketch:
 
            
 
        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):
 
@@ -302,11 +303,26 @@ class Curveview(tk.Canvas):
 
                      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
 
@@ -320,6 +336,10 @@ class Curveview(tk.Canvas):
 
        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:
0 comments (0 inline, 0 general)