Physion

  • Increase font size
  • Default font size
  • Decrease font size
Welcome, Guest
Username Password: Remember me

Tracer script
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Tracer script

Tracer script 6 years, 5 months ago #486

  • Dimitris
  • OFFLINE
  • Administrator
  • Posts: 218
You may have noticed that there is a Tracer tool in the toolbars which is currently (v1.01) disabled. The reason I didn't enable the tool was due to some artifacts that were generated when the tracer was painted.

The Tracer.script is supposed to be a temporary replacement of this disabled tool. As the name suggests, this script provides a tool for visualizing the trajectories of moving objects as shown below:



DOWNLOAD
Download the tracer script

INSTALLATION
Put the downloaded file in data/scripts/autoload relative to Physion's installation directory and restart Physion (if it was already running)
NOTE: Users of version 1.00 won't have the autoload functionality available so please update to 1.01

USAGE EXAMPLES
Open the console (shift+~) and type the following:
var circle = world.createCircle(0, 15, 0, 0.5);
var tracer = createTracer(circle);
 

By default the tracer doesn't fade proportionally to the distance. If you want to enable this feature you can type the following:
tracer.fade = true;

File Attachment:

File Name: Tracer.script
File Size: 1216
Last Edit: 6 years, 5 months ago by Dimitris.

Re: Tracer script 6 years, 5 months ago #488

  • Lynxx
  • OFFLINE
  • Moderator
  • Java/C#-Developer
  • Posts: 223
Nice one.
Infinity is vast, especially near end.
bye, Lynxx

Re: Tracer script 6 years, 2 months ago #685

  • DonDon6
  • OFFLINE
  • Junior Boarder
  • Posts: 30
Why Does My Tracer Script Fail:

Console Dump:
 qt.core successfully imported into script engine
 qt.gui successfully imported into script engine
 ToolBox.script has been successfully loaded.
 tracer.script has been successfully loaded.
 07:54:48 zzz_mousefilter V1.0 by Holger 'Lynxx' Hippenstiel & Nait installed.
 zzzmouse.script has been successfully loaded.
 var circle = world.createCircle(0, 15, 0, 0.5); var;
 Expected `identifier'
 var circle = world.createCircle(0, 15, 0, 0.5); var;
 Expected `identifier'

Re: Tracer script 6 years, 2 months ago #686

  • Lynxx
  • OFFLINE
  • Moderator
  • Java/C#-Developer
  • Posts: 223
DonDon6 wrote:
var circle = world.createCircle(0, 15, 0, 0.5); var;
Expected `identifier'


This should be:
var circle = world.createCircle(0, 15, 0, 0.5);
and NOT
var circle = world.createCircle(0, 15, 0, 0.5); var;

then:
var tracer = createTracer(circle);
Infinity is vast, especially near end.
bye, Lynxx

Re: Tracer script 6 years, 2 months ago #687

  • DonDon6
  • OFFLINE
  • Junior Boarder
  • Posts: 30
Thanks for the help Lynxx,

That change to the Trace Script worked.

Re: Tracer script 6 years, 2 months ago #688

  • DonDon6
  • OFFLINE
  • Junior Boarder
  • Posts: 30
I;ve altered the tracer script slightly to produce a less cluttered display:
function Tracer(parent)
{
QGraphicsItem.call(this, parent);

var color = new QColor(Math.random()*256, Math.random()*256, Math.random()*256);
var thickness = 0.15;

this.pen = new QPen(color, thickness, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin);
this.fade = false;
this.maxLength = 20;
this.polygon = new QPolygonF();

this.boundingRect = function() { return this.mapFromScene(this.polygon).boundingRect(); };
}

Tracer.prototype = new QGraphicsItem();

Tracer.prototype.paint = function(painter, styleOptionGraphicsItem, widget)
{
this.polygon.append(this.scenePos());
if(this.polygon.count() > this.maxLength)
this.polygon.remove(0);

if(this.fade)
{
for(var i=0; i<this.polygon.count()-1; i++)
{
var p1 = this.mapFromScene(this.polygon.at(i));
var p2 = this.mapFromScene(this.polygon.at(i+1));

var opacity = (i+1) / this.polygon.count();

painter.setPen(this.pen);
painter.setOpacity(opacity);
painter.drawLine(this.mapFromScene(this.polygon.at(i)), this.mapFromScene(this.polygon.at(i+1)));
}
}
else
{
painter.setPen(this.pen);
painter.drawPolyline(this.mapFromScene(this.polygon));
}
}

function createTracer(item) { return new Tracer(item.graphicsItem()); }
  • Page:
  • 1
  • 2
Moderators: Lynxx, Glenn555
Time to create page: 0.15 seconds