Wiskundelibrary

From Math Portfolio
Jump to: navigation, search
function Punt(context,x,y,straal,kleur){
	this.context = context;
	this.x = x || 100;
	this.y = y || 100;
	this.straal = straal || 15;
	this.kleur = kleur || "#ff0"; 
 
	this.teken = function(){
		this.context.fillStyle = this.kleur;
		this.context.beginPath();
		this.context.arc(this.x,this.y,this.straal,0,2*Math.PI);
		this.context.stroke();
		this.context.fill();
	}
 
}
 
function Vector(dx,dy){
	this.dx = dx || 0;
	this.dy = dy || 0;
 
	this.hoek = Math.atan2(this.dy, this.dx);
	this.straal = Math.sqrt(this.dx*this.dx + this.dy*this.dy);
}
 
function SleepPunt(canvas,context,x,y,straal,kleur){
	this.canvas = canvas;
	this.context = context;
	this.x = x || 100;
	this.y = y || 10;
	this.straal = straal || 15;
	this.kleur = kleur || "#ff0";
	var mouseX,mouseY;
	var offsetX = canvas.offsetLeft;
	var offsetY = canvas.offsetTop;
	this.sleep = false;
 
	addEventListener("mousedown",beginSleep,false); 
 
	this.teken = function(){
		console.log("ik teken",this.x,x);
		this.context.fillStyle = this.kleur;
		this.context.beginPath();
		this.context.arc(this.x,this.y,this.straal,0,2*Math.PI);
		this.context.stroke();
		this.context.fill();
	}
 
	function beginSleep(e){
		mouseX = e.pageX-offsetX;
		mouseY= e.pageY-offsetY;
		dPuntMuis = afstand(x,y,mouseX,mouseY);
 
		console.log("sleep",x,mouseX,mouseY,offsetX,offsetY,dPuntMuis);
		if(dPuntMuis <= straal){
			sleep=true;
			addEventListener("mousemove",beweeg,false);
		}
		else{
			sleep = false;
			removeEventListener("mousemove",beweeg,false);
 
		}
	}
 
	function beweeg(e){
		this.x = e.pageX;
		console.log(this.x,e.pageX);
	}
}
 
function afstand(x1,y1,x2,y2){
	console.log(x1);
	return Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
}
[[Categorie:JavaScript]]
Personal tools
Namespaces
Variants
Actions
Navigation
wiskundeportfolio
Toolbox