<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Looking for a way to control and move a shape across a graph in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751733#M93291</link>
    <description>&lt;P&gt;Could you provide better example about what you try to visualize? JMP does for example have Mousetrap() which can draw things based on the cursor location in the framebox&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

gb = dt &amp;lt;&amp;lt; Graph Builder(
	Variables(X(:weight), Y(:height), Overlay(:sex)),
	Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11)))
);

exx = 70;
exy = 70;

Report(gb)[FrameBox(1)] &amp;lt;&amp;lt; Add Graphics Script(
	Mousetrap(
		exx = x;
		exy = y;
	);
	Rect({exx - 10, exy - 10}, {exx, exy});	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2024 16:53:56 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-05-02T16:53:56Z</dc:date>
    <item>
      <title>Looking for a way to control and move a shape across a graph</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751693#M93285</link>
      <description>&lt;P&gt;I'm looking for a way to control and move a 'drawn' shape or series of shapes across plot (graph builder) using JSL script, for data visualisation purposes. Think of it as an animation using a series of frames and then scrolling through them to give the impression of movement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By 'drawn' shape, I mean something like:&lt;/P&gt;&lt;P&gt;Rect ()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking of taking the following approach, but I'm not sure exactly how to execute this or if there's a better approach:&lt;/P&gt;&lt;P&gt;-&amp;nbsp; Script / draw the shape(s) required and associate them with a variable (which could be a row value) - we'll call this a frame&lt;/P&gt;&lt;P&gt;- Construct multiples frames, with the shape(s) required in different positions, with each frame assigned to a distinct variable&lt;/P&gt;&lt;P&gt;E.g.&lt;/P&gt;&lt;P&gt;Frame 1 - Shape is in position (X+0,Y) and associated with variable (v = 1)&lt;/P&gt;&lt;P&gt;Frame 2 - Shape is in position (X+1,Y) and associated with variable (v = 2)&lt;/P&gt;&lt;P&gt;Frame 3 - Shape is in position (X+2,Y) and associated with variable (v = 3)&lt;/P&gt;&lt;P&gt;- Use local data filter to scroll which variable is selected and therefore the position of the drawn shape(s)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd hope that this, as described in my example, would give the impression of the shape moving in direction X+.&lt;/P&gt;&lt;P&gt;As aforementioned I am unsure that this would work, the graph builder report would need to be updated / refreshed somehow to remove the old drawing (overwritten) in place of the new one when the variable selected is being changed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm eager to see if something like this is possible and how this could be coded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 16:10:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751693#M93285</guid>
      <dc:creator>EDM</dc:creator>
      <dc:date>2024-05-02T16:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for a way to control and move a shape across a graph</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751733#M93291</link>
      <description>&lt;P&gt;Could you provide better example about what you try to visualize? JMP does for example have Mousetrap() which can draw things based on the cursor location in the framebox&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

gb = dt &amp;lt;&amp;lt; Graph Builder(
	Variables(X(:weight), Y(:height), Overlay(:sex)),
	Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11)))
);

exx = 70;
exy = 70;

Report(gb)[FrameBox(1)] &amp;lt;&amp;lt; Add Graphics Script(
	Mousetrap(
		exx = x;
		exy = y;
	);
	Rect({exx - 10, exy - 10}, {exx, exy});	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 16:53:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751733#M93291</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-05-02T16:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for a way to control and move a shape across a graph</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751817#M93298</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x1 = y1 = x2 = y2 = 0;
keepRunning=1;
New Window( "Example", gb = Graph Box( Frame Size( 800, 800 ), Oval( x1, y1, x2, y2 ) ), &amp;lt;&amp;lt;onclose(keepRunning=0;1) );
Wait( 0.1 );
radius = 5;
x = 50;
y = 90;
velocity = 0;
accel = .2;
prevtime = Tick Seconds();
While( keepRunning,
	curtime = Tick Seconds();
	dt = curtime - prevtime;
	prevtime = curtime;
	velocity -= accel;
	dy = velocity * dt;
	y = Max( 1, y + dy );
	//Show( y );
	ysize = Min( radius, y );
	xsize = radius ^ 2 / ysize;
	x1 = x - xsize;
	x2 = x + xsize;
	y1 = y + ysize;
	y2 = y - ysize;
	gb[framebox( 1 )] &amp;lt;&amp;lt; inval &amp;lt;&amp;lt; reshow;
	Wait( 0 );
	// the bounce is hard to model. the velocity decreases rapidly, then reverses rapidly.
	// the following isn't quite right...
	If( y &amp;lt; radius,
		velocity += 5 / y; // reverse harder as the ball squishes more.
	);
	velocity *= .99;
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6352215904112w960h540r74" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6352215904112" data-account="6058004218001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6058004218001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6352215904112w960h540r74');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.jmp.com/t5/video/gallerypage/video-id/6352215904112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;Looks like some rusty physics.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 03:52:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751817#M93298</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2024-05-03T03:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for a way to control and move a shape across a graph</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751895#M93313</link>
      <description>&lt;P&gt;This is really neat.&lt;/P&gt;&lt;P&gt;I think I can find a use for this, I'm eager to a have a play around to see how it works.&lt;/P&gt;&lt;P&gt;I'm now keen on taking a more passive approach to my initial problem, I didn't realise you can control a shapes velocity, acceleration over time like in Craige's example.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 09:13:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751895#M93313</guid>
      <dc:creator>EDM</dc:creator>
      <dc:date>2024-05-03T09:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for a way to control and move a shape across a graph</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751896#M93314</link>
      <description>&lt;P&gt;This looks really good, I think this is what I'm after - I really like how this can be time driven.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would it be possible to get this to work for a more complex drawing, such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fill Color( RGB Color( 255, 0, 0 ) );&lt;BR /&gt;Rect (50, 90, 60, 80, 1);&lt;BR /&gt;Fill Color( RGB Color( 204, 0, 0 ) );&lt;BR /&gt;Rect (51, 89, 59, 81, 1);&lt;BR /&gt;Fill Color( RGB Color( 255, 0, 0 ) );&lt;BR /&gt;Polygon ( {59, 89}, {60, 90}, {50, 90}, {51, 89});&lt;BR /&gt;Fill Color( RGB Color( 153, 0, 0 ) );&lt;BR /&gt;Polygon ( {60, 80}, {59, 81}, {51, 81}, {50, 80});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rather than bouncing, when the bottom of the shape hits the X-axis, I want to be able to get it to stop and stay in place.&lt;/P&gt;&lt;P&gt;Also, after a given time has elapsed I'd like other shapes drawing to enter the screen and follow the same path, with each one settling on the X-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've had a play around with the script you sent, but not sure quite how to modify it in the right way - really clever!!!&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 09:16:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751896#M93314</guid>
      <dc:creator>EDM</dc:creator>
      <dc:date>2024-05-03T09:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for a way to control and move a shape across a graph</title>
      <link>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751904#M93319</link>
      <description>&lt;P&gt;Yes, you can do that.&amp;nbsp; It sounds like your object has a rigid shape and you want it to stop instantly when some condition is met. Not gradually slow down or distort. And it sounds like you will have multiple objects that may be released over time. I'd use a data table with one row per object, with column names similar to these:&lt;/P&gt;
&lt;PRE&gt;Xpos  Ypos  Xvel  Yvel  XdeltaVel  TdeltaVel  IsActive  IsDrawing  Color  Size  Shape&lt;/PRE&gt;
&lt;P&gt;Then I'd write two functions: UpdateRow( row number, deltaTime ) and DrawRow( row number ). UpdateRow might look something like this (untested, approximately right...):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;UpdateRow = function({rowNumber, deltaTime}
   if( dtQ:isActive[rowNumber],
      dtQ:Xpos[rowNumber] += dtQ:Xvel[rowNumber] * deltaTime;
      dtQ:Ypos[rowNumber] += dtQ:Yvel[rowNumber] * deltaTime;
      // you might want the velocity to change as well, possibly using the deltaVelocity,
      // make sure the Xs and Ys stay together
      // do a test to see if still active
      if( dtQ:y[rowNumber] &amp;lt;= 0, // whatever condition makes it stop
          dtQ:isActive[rowNumber] = 0;
          dtQ:isDrawing[rowNumber] -= 1; // count down until vanishes
      )
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you add a row to the table (&lt;CODE class=" language-jsl"&gt;dtQ&lt;/CODE&gt;, above, I tend to use dt for a table not delta time!) make sure to set the row's value for isActive to 1, and if you want the non-active objects to eventually expire, set the isDrawing to 100 or 1000 to control how many cycles go by before it stops drawing.&lt;/P&gt;
&lt;P&gt;The DrawRow function looks something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;DrawRow = function({RowNumber},
   if( dtQ:isDrawing[RowNumber],
      // your code goes here. Add the dtQ:Xpos[RowNumber] to your X coords
      // and same for Ypos/Y.
      // .... use the color/size/shape values from the row if you find them useful
   )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the graphics script becomes a pair of loops over dtQ, the first to apply the updates, and the second to do the drawing. You don't have to keep them separated, but you might find it helpful later if you decide to handle collisions.&lt;/P&gt;
&lt;P&gt;In this example, the data table in dtQ could also be displayed with graph builder by plotting the xpos, ypos, color, size, shape values. GraphBuilder will update automatically and you don't need the DrawRow function. I've never used it but I think there might be a custom shape drawing mechanism for the points.&lt;/P&gt;
&lt;P&gt;If you are trying to make a video (rather than an interactive, real-time display), settle on 30 or 60 FPS and let the delta time be constant from frame to frame. Above, I picked numbers that made it work on my machine. But if I picked 1/30 and made a set of numbered images, they would make a very smooth video.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 11:39:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Looking-for-a-way-to-control-and-move-a-shape-across-a-graph/m-p/751904#M93319</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2024-05-03T11:39:33Z</dc:date>
    </item>
  </channel>
</rss>

