# Line bending?

**URL:** <https://forum.kirupa.com/t/line-bending/19648>\
**Category:** Uncategorized\
**Created:** [April 30, 2003, 5:18am UTC](https://forum.kirupa.com/t/line-bending/19648 "2003-04-30T05:18:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://forum.kirupa.com/u/Mike)\
**Post date:** [April 30, 2003, 5:18am UTC](https://forum.kirupa.com/t/line-bending/19648/1 "2003-04-30T05:18:25Z")

</div>

Heres an easy one I hope.

How do draw a vertical line and make it bend into a curve as the mouse hits it.

or better yet,

a box that traps the mouse in it and stretches out when mouse hits the side.

hope I explained well.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 30, 2003, 5:31am UTC](https://forum.kirupa.com/t/line-bending/19648/2 "2003-04-30T05:31:55Z")

</div>

:)… good luck

It would be very difficult to do, if you wanted the sides to be truely responsive to the location of the mouse. I’ve seen some things that do a poor job of simulating the effect… but they never looked right.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 30, 2003, 8:39am UTC](https://forum.kirupa.com/t/line-bending/19648/3 "2003-04-30T08:39:51Z")

</div>

Wow, that would be a challenge indeed. You’d have to use the drawing API for sure, with a bit of curveTos here and there. I’ll try to give it a go if I manage to put my dirty hands on Flash.

pom 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 30, 2003, 10:21am UTC](https://forum.kirupa.com/t/line-bending/19648/4 "2003-04-30T10:21:59Z")

</div>

You could imagine something based on Robert Penner’s code:

```auto
/* Credits: Robert Penner */
  // Extreme points of the curve
  x1=100;
  y1=200;
  x2=400;
  y2=200;
  this.onEnterFrame=function(){
	// control points
	controlX=_xmouse*2-(x1+x2)/2;
	controlY=_ymouse*2-(y1+y2)/2;
	// draw the curve
	this.clear();
	this.lineStyle(1,0,100);
	this.moveTo(x1,y1);
	this.curveTo(controlX,controlY,x2,y2);
  }

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 30, 2003, 10:57am UTC](https://forum.kirupa.com/t/line-bending/19648/5 "2003-04-30T10:57:19Z")

</div>

Or something inspired from Jean-Louis Gaujal’s submission to the Bit contest a long time ago if you replace the dot with the position of the mouse:

```auto
/* Author: JL Gaujal */
_root.createEmptyMovieClip("b", 1); 
b.lineStyle(30, 0xff0000); 
b.lineTo(1, 1); 
b._x = 275; 
b._y = 100; 
_root.onEnterFrame = function() { 
   ax = -30+50*Math.sin(_root._xmouse/200); 
   ay = 250+50*Math.cos(_root._xmouse/200); 
   dx = 530+50*Math.sin(_root._xmouse/200); 
   dy = 250-50*Math.cos(_root._xmouse/200); 
   _root.clear(); 
   _root.lineStyle(10); 
   vby += (b._y-Math.abs(ay+dy)/2)/25; 
   b._y -= vby; 
   b._x -= vbx; 
   _root.moveTo(ax, ay); 
   if (b._y<Math.abs(ay+dy)/2) { 
      _root.lineTo(dx, dy); 
   } else { 
      vbx += (ay-dy)/100+(b._x-(ax+dx)/2)/20; 
      _root.curveTo(b._x, Math.abs(ay+dy)/2, b._x, b._y); 
      _root.moveTo(dx, dy); 
      _root.curveTo(b._x, Math.abs(ay+dy)/2, b._x, b._y); 
   } 
};

```
