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

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

  • Lynxx
  • OFFLINE
  • Moderator
  • Java/C#-Developer
  • Posts: 223
I reworked the script myself too, probably should posted that long before.

function Tracer(parent, fade, maxLength, thickness, updateFreq) {
var tracerthickness = thickness != null ? thickness : 0.25;
this.fade = fade != null ? fade: true;
this.maxLength = maxLength != null ? maxLength : 50;
this.updateFreq = updateFreq != null ? updateFreq : 2;
QGraphicsItem.call(this, parent);
var color = new QColor(Math.random()*256, Math.random()*256, Math.random()*256);
this.pen = new QPen(color, tracerthickness, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin);
this.polygon = new QPolygonF();
this.count = 0;
this.boundingRect = function() { return this.mapFromScene(this.polygon).boundingRect(); };
}
Tracer.prototype = new QGraphicsItem();
 
Tracer.prototype.paint = function(painter, styleOptionGraphicsItem, widget) {
this.count++;
if (this.count % this.updateFreq == 0) {
this.polygon.append(this.scenePos());
if(this.polygon.count() > this.maxLength)
this.polygon.remove(0);
}
 
painter.setPen(this.pen);
if(this.fade) {
for(var i=0; i<this.polygon.count()-1; i++) {
painter.setOpacity(((i+1) / this.polygon.count()));
painter.drawLine(this.mapFromScene(this.polygon.at(i)), this.mapFromScene(this.polygon.at(i+1)));
}
}
else {
painter.drawPolyline(this.mapFromScene(this.polygon));
}
}
 
function createTracer(item, fade, maxLength, thickness, updateFreq) { return new Tracer(item.graphicsItem(), fade, maxLength, thickness, updateFreq); }


Arguments are
fade = use fading or not, default true
maxLength = maximum length for the tail, default 50
thickness = thickness of the tail, default 0.25
updateFreq = update tail position every Nth redraw, default 2

You can also just call it with:

var tracer = createTracer(item);
or
var tracer = createTracer(item, true);

With this parameters it's exactly the original Tracer-Script:
var tracer = createTracer(item, false, 100, 0.25, 1);

With this parameters it's exactly DonDon6's Tracer-Script:
var tracer = createTracer(item, false, 20, 0.15, 1);
Infinity is vast, especially near end.
bye, Lynxx
Last Edit: 6 years, 2 months ago by Lynxx.

Re: Tracer script 4 years, 2 months ago #830

how do you add it so that the button on the toolbar works?

Re: Tracer script 4 years, 2 months ago #831

can you give me step by step instructions for how to apply the tracer script i feel stupid for not understanding but i have not used scripting before its kinda new to me
  • Page:
  • 1
  • 2
Moderators: Lynxx, Glenn555
Time to create page: 0.14 seconds