diff --git a/chameleonic.p8 b/chameleonic.p8 index 220c8eb..3348edd 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -1047,9 +1047,9 @@ function rope:draw(artificial_dx,artificial_dy) local color=8 if (highlight==0) color=12 if self.latch.dx==-1 and self.latch.dy==0 then - rectfill(x+1,y,x+3,y+1,color) + rectfill(x+1,y-1,x+3,y,color) elseif self.latch.dx==1 and self.latch.dy==0 then - rectfill(x-1,y,x-3,y+1,color) + rectfill(x-1,y-1,x-3,y,color) elseif self.latch.dx==0 and self.latch.dy==-1 then rectfill(x,y+1,x-1,y+3,color) elseif self.latch.dx==0 and self.latch.dy==1 then @@ -1090,17 +1090,69 @@ function rope:drag_src(x,y) self:drag(self.src,x,y) end -function rope:drag( - n1,ax_new,ay_new -) +function rope:drag(n1,ax_new,ay_new) -- TODO: stepwise? - rope:_drag1(n1,ax_new,ay_new) + self:_relax() + self:_drag(n1,ax_new,ay_new) + self:_relax() +end + +function rope:_relax() + local n0=self.src + while true do + if (n0==nil) return + local n1=n0.next + if (n1==nil) return + local n2=n1.next + if (n2==nil) return + + if n1.associated_with!=nil then + local x0,y0=n0.ax,n0.ay + local x1,y1=n1.ax,n1.ay + local x2,y2=n2.ax,n2.ay + + if (x0>x2) x0,y0,x2,y2=x2,y2,x0,y0 + + local dx=x2-x0 + local dy=y2-y0 + + local adx,ady + local x1_new,y1_new + if abs(dx)>abs(dy) then + local dprop=(x1-x0)/dx + x1_new,y1_new=x1,y0+dprop*(y2-y0) + ady=sgn0(y1_new-y1) + adx=0 + if (y0>y2) adx=ady + if (y0y2) ady=adx + if (y0