//emit value every 1 second
var div = document.createElement('div');
div.innerHTML = 'status';
document.body.appendChild(div);
var display = function(val){
var msg = val;
div.innerHTML = msg;
console.log(msg);
}
var points = [];
var oldPoint = new THREE.Vector3();
var newPoint = new THREE.Vector3();
var mouseDownPoint = new THREE.Vector3();
var isMouseDown = false;
var isPrecision = false;
const tickerInterval = Rx.Observable.interval(2000);
// throttle for five seconds
// last value emitted before throttle ends will be emitted from source
//const example = source.throttleTime(5000);
//output: 0...6...12
var tickSubscriber;
var isIntervalStarted = false;
var stopInterval = function(){
isIntervalStarted = false;
if(tickSubscriber){
tickSubscriber.unsubscribe();
}
}
// trigger precision
var startInterval = function(){
isIntervalStarted = true;
// interval helps swtich back into precision mode when
// the mouse is not being moved
tickSubscriber = tickerInterval.subscribe((val) => {
//display(ox + ',' + x + ': ' + oy + ',' + y);
if(!isPrecision){
var dist = oldPoint.distanceTo(newPoint);
var result = dist < 5;
if(result){
isPrecision = true;
}
}
if(isPrecision) {
display('precision mode');
}else{
display('normal mode');
}
//display(ox + ',' + x + ': ' + oy + ',' + y);
});
}
var mousemove = Rx.Observable.fromEvent(document, 'mousemove');
mousemove.throttleTime(100).subscribe((evt) => {
if(isMouseDown){
newPoint.x = evt.offsetX;
newPoint.y = evt.offsetY;
if(isPrecision){
// threshold when to break out
var threshold = 200;
if(mouseDownPoint.distanceTo(newPoint) > threshold){
console.log('break out precision');
isPrecision = false;
stopInterval();
}
}else{
console.log('mousemove');
oldPoint.copy(newPoint);
newPoint.x = evt.offsetX;
newPoint.y = evt.offsetY;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.