Files
RTT/main.qml
2019-02-26 14:46:10 +01:00

158 lines
3.4 KiB
QML

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.4
Window {
id: window
visible: true
width: 640
height: 680
title: qsTr("Hello World")
Column {
id: column
Label {
text: "dist1: " + ((mgmt.dist1 ? mgmt.dist1+sld1.value : 0)/1000).toFixed(2);
}
Label {
text: "dist2: " + ((mgmt.dist2 ? mgmt.dist2+sld1.value : 0)/1000).toFixed(2);
}
Label {
text: "dist3: " + ((mgmt.dist3 ? mgmt.dist3+sld1.value : 0)/1000).toFixed(2);
}
Label {
text: "dist4: " + ((mgmt.dist4 ? mgmt.dist4+sld1.value : 0)/1000).toFixed(2);
}
Slider {
width: 400;
id: sld1;
from: -3000;
to: 5000;
onValueChanged: leCanvas.requestPaint();
}
Label {
text: "offset: " + sld1.value;
}
Connections {
target: mgmt
onDistChanged: leCanvas.requestPaint();
}
Button {
text: "party hard";
onClicked: mgmt.trigger();
}
}
Canvas {
id: leCanvas;
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.top: column.bottom
anchors.topMargin: 20
readonly property double s: 0.02;
function leArc(ctx, cx, cy, dist, stdDev) {
// center circle
ctx.fillStyle = "#000000";
ctx.beginPath();
ctx.arc(cx*s, cy*s, 2, 0, 360);
ctx.fill();
// error circle
// ctx.beginPath();
// ctx.arc(cx*s, cy*s, (dist+sld1.value)*s, 0, 360);
// ctx.closePath();
// ctx.lineWidth = stdDev*s*0.5;
// ctx.strokeStyle = "#66000000";
// ctx.stroke();
// circle
ctx.lineWidth = 1;
ctx.strokeStyle = "#aa000000";
ctx.beginPath();
ctx.arc(cx*s, cy*s, (dist+sld1.value)*s, 0, 360);
ctx.stroke();
}
onPaint: {
var ctx = getContext("2d")
ctx.reset();
ctx.fillStyle = "#dddddd";
ctx.clearRect(0, 0, leCanvas.width, leCanvas.height);
//ctx.strokeStyle = Qt.rgba(0, 0, 0, 1)
//ctx.lineWidth = 1
var ox = 4000;
var oy = 4000;
var cx1 = ox+0;
var cy1 = oy+0;
var cx2 = ox+0;
var cy2 = oy+7250;
var cx3 = ox+9000;
var cy3 = oy+7250;
var cx4 = ox+9000;
var cy4 = oy+0;
leArc(ctx, cx1, cy1, mgmt.dist1, mgmt.stdDev1);
leArc(ctx, cx2, cy2, mgmt.dist2, mgmt.stdDev2);
leArc(ctx, cx3, cy3, mgmt.dist3, mgmt.stdDev3);
leArc(ctx, cx4, cy4, mgmt.dist4, mgmt.stdDev4);
var sigma = 2000;
var stepSize = 333;
var maxP = Math.pow( 1.0 / Math.sqrt(2*Math.PI*sigma), 4.1);
for (var y = 0; y < leCanvas.height/s; y += stepSize) {
for (var x = 0; x < leCanvas.width/s; x += stepSize) {
var d1 = Math.sqrt( Math.pow(x-cx1, 2) + Math.pow(y-cy1, 2) ) - (mgmt.dist1-sld1.value);
var d2 = Math.sqrt( Math.pow(x-cx2, 2) + Math.pow(y-cy2, 2) ) - (mgmt.dist2-sld1.value);
var d3 = Math.sqrt( Math.pow(x-cx3, 2) + Math.pow(y-cy3, 2) ) - (mgmt.dist3-sld1.value);
var d4 = Math.sqrt( Math.pow(x-cx4, 2) + Math.pow(y-cy4, 2) ) - (mgmt.dist4-sld1.value);
var p = 1;
p *= 1.0 / Math.sqrt(2*Math.PI*sigma) * Math.exp( - d1*d1/(2*sigma*sigma) );
p *= 1.0 / Math.sqrt(2*Math.PI*sigma) * Math.exp( - d2*d2/(2*sigma*sigma) );
p *= 1.0 / Math.sqrt(2*Math.PI*sigma) * Math.exp( - d3*d3/(2*sigma*sigma) );
p *= 1.0 / Math.sqrt(2*Math.PI*sigma) * Math.exp( - d4*d4/(2*sigma*sigma) );
//p = Math.pow(p, 1);
if (p > maxP / 50) {
ctx.fillStyle = Qt.rgba(1,0,0, p/maxP);
ctx.fillRect(x*s, y*s, stepSize*s, stepSize*s);
}
}
}
}
}
}