Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Making the Canvas.Object to follow Canvas.Path object
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Akonkagva  
View profile  
 More options Jun 21 2012, 10:46 am
From: Akonkagva <peter.puzan...@hotmail.com>
Date: Thu, 21 Jun 2012 07:46:38 -0700 (PDT)
Local: Thurs, Jun 21 2012 10:46 am
Subject: Making the Canvas.Object to follow Canvas.Path object

Hi,

Essentially I am trying to achieve two functions:

1) Dragging the Canvas.Object along the Canvas.Path (with mouse)(high
priority)

2) Animating the Canvas.Ojbect movement along the Canvas.Path path

What would be the quick'n elegant way to do these two things.

Any reply highly and much appreciated,
Akonkagva


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juriy Zaytsev  
View profile  
 More options Jun 22 2012, 5:03 am
From: Juriy Zaytsev <kan...@gmail.com>
Date: Fri, 22 Jun 2012 11:03:25 +0200
Local: Fri, Jun 22 2012 5:03 am
Subject: Re: Making the Canvas.Object to follow Canvas.Path object

Interesting functionalities. I haven't done this, and not sure right away
how to approach it best. Animation along the path seems easier, as you'd
just need to have a function producing left/top values for each point in
time (according to left/top value of point on path at that time).

Perhaps someone else has experimented with this.

--
kangax

On Thu, Jun 21, 2012 at 4:46 PM, Akonkagva <peter.puzan...@hotmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Akonkagva  
View profile  
 More options Jun 22 2012, 11:52 am
From: Akonkagva <peter.puzan...@hotmail.com>
Date: Fri, 22 Jun 2012 08:52:38 -0700 (PDT)
Local: Fri, Jun 22 2012 11:52 am
Subject: Re: Making the Canvas.Object to follow Canvas.Path object

Is it even possible to get the sequentual values from the canvas.Path
object ?(sequence of points(x,y) used to draw path) ?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juriy Zaytsev  
View profile  
 More options Jun 22 2012, 2:49 pm
From: Juriy Zaytsev <kan...@gmail.com>
Date: Fri, 22 Jun 2012 20:49:06 +0200
Local: Fri, Jun 22 2012 2:49 pm
Subject: Re: Making the Canvas.Object to follow Canvas.Path object

Good point. If your path is represented as a function, that's simple. Not
sure about coords from SVG-like paths. I'm sure you can find a lot on this
topic, though.

--
kangax

On Fri, Jun 22, 2012 at 5:52 PM, Akonkagva <peter.puzan...@hotmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Akonkagva  
View profile  
 More options Jun 25 2012, 9:09 am
From: Akonkagva <peter.puzan...@hotmail.com>
Date: Mon, 25 Jun 2012 06:09:24 -0700 (PDT)
Local: Mon, Jun 25 2012 9:09 am
Subject: Re: Making the Canvas.Object to follow Canvas.Path object

Thank you for your answer, I have created a simple func that return an
array of Path points fiven the required number of points and Path.

<script type="text/javascript">
 function getPathValues(path_val,samples){

  var path = document.createElementNS('http://www.w3.org/2000/svg','path');
  path.setAttribute('d',path_val);
  //var doc = path.ownerDocument;

  var points = [];
  var len  = path.getTotalLength();
  var step = step=len/samples;
  for (var i=0;i<=len;i+=step){
   var p = path.getPointAtLength(i);
   points.push( p.x+','+p.y );
  }
  console.log(points);
  return points;
 }
 getPathValues("M 65 0 Q 100, 100, 200, 0",50);
</script>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Akonkagva  
View profile   Translate to Translated (View Original)
 More options Jun 26 2012, 6:08 am
From: Akonkagva <peter.puzan...@hotmail.com>
Date: Tue, 26 Jun 2012 03:08:31 -0700 (PDT)
Local: Tues, Jun 26 2012 6:08 am
Subject: Re: Making the Canvas.Object to follow Canvas.Path object

Dragging along the Path Object:
<script src="fabric.js"></script>
    <!--[if lt IE 9]>
      <script src="
https://raw.github.com/kangax/fabric.js/master/lib/excanvas.js"></script>
    <![endif]-->
<canvas id="c" width="500" height="500" style="border:1px solid
#ccc"></canvas>
<script type="text/javascript" src="jquery.js"></script>
<script id="main">
var canvas = new fabric.Canvas('c');
var circle = new fabric.Circle({ radius: 30, fill: '#f55', top: 100, left:
300 });
canvas.add(circle);
canvas.observe({
  'object:moving': onObjectMoving

});

var line = new fabric.Path('M 65 0 Q 100, 100, 200, 0', { fill: '', stroke:
'black' });;
var points = getPathValues("M 65 0 Q 100, 100, 200, 0",45);
canvas.add(line);
function onObjectMoving(e) {
    var activeObject = e.target;
  var currentObjX = activeObject.left;
  var currentObjY = activeObject.top;
  var best = 0;
  var pastDist = 1000;

  for(var i =0; i < points.length; i = i +2)
  {
  var x = points[i];
  var y = points[i+1];
  var distance = lineDistance(mouseX,mouseY,x,y);
  if(distance < pastDist)
  {
   pastDist = distance;
   best = i;
  }
  }
  activeObject.left = points[best]
  activeObject.top = points[best+1];

}

function lineDistance( x0,y0, x1,y1 )
    {
    var xs = 0;
    var ys = 0;
    xs = x1 - x0;
    xs = xs * xs;
    ys = y1 - y0;
    ys = ys * ys;
    return Math.sqrt( xs + ys );

}

function getPathValues(path_val,samples){

  var path = document.createElementNS('http://www.w3.org/2000/svg','path');
  path.setAttribute('d',path_val);
  var points = [];
  var len  = path.getTotalLength();
  var step = step=len/samples;
  for (var i=0;i<=len;i+=step){
   var p = path.getPointAtLength(i);
   points.push( p.x );
   points.push( p.y );
  }
  console.log(points);
  return points;
 }
 var mouseX;
 var mouseY;
jQuery(document).ready(function(){
   $(document).mousemove(function(e){
   mouseX = e.pageX;
   mouseY = e.pageY;
   });


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Akonkagva  
View profile   Translate to Translated (View Original)
 More options Jun 26 2012, 6:35 am
From: Akonkagva <peter.puzan...@hotmail.com>
Date: Tue, 26 Jun 2012 03:35:39 -0700 (PDT)
Local: Tues, Jun 26 2012 6:35 am
Subject: Re: Making the Canvas.Object to follow Canvas.Path object

Animating along the movement path:

<script src="fabric.js"></script>
    <!--[if lt IE 9]>
      <script src="
https://raw.github.com/kangax/fabric.js/master/lib/excanvas.js"></script>
    <![endif]-->
<canvas id="c" width="500" height="500" style="border:1px solid
#ccc"></canvas>
<script type="text/javascript" src="jquery.js"></script>
<script id="main">
var canvas = new fabric.Canvas('c');

var circle = new fabric.Circle({ radius: 30, fill: '#f55', top: 0, left: 65

});

var circleToScale = new fabric.Circle({ radius: 30, fill: '#f10', top: 250,
left: 250 });
canvas.add(circleToScale);
canvas.add(circle);

var line = new fabric.Path('M 65 0 Q 100, 100, 200, 0', { fill: '', stroke:
'black' });;

var points = getPathValues("M 65 0 Q 100, 100, 200, 0",75);
canvas.add(line);

function getPathValues(path_val,samples){

  var path = document.createElementNS('http://www.w3.org/2000/svg','path');
  path.setAttribute('d',path_val);
  var points = [];
  var len  = path.getTotalLength();
  var step = step=len/samples;
  for (var i=0;i<=len;i+=step){
   var p = path.getPointAtLength(i);
   points.push( p.x );
   points.push( p.y );
  }
  console.log(points);
  return points;
 }

 var i = 0;

 setInterval(function animate() {
 i = i +2;
 if(i > points.length)
 {
 i = 0;
 }

 circle.left = points[i];
 circle.top = points[i+1];

 if(i != 0)
 circleToScale.scale(i/10);
  canvas.renderAll();

}, 100);

</script>

  </body>
</html>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »