Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 1438a044671e2f583ca93261d90e86419778fd13 @bjwbell committed May 22, 2009
Showing with 209 additions and 0 deletions.
  1. 0 README
  2. +10 −0 main.html
  3. +67 −0 main.html~
  4. +132 −0 main.js
  5. 0 main.js~
0 README
No changes.
@@ -0,0 +1,10 @@
+<html><head>
+<title>Line Intersection Tests</title>
+<script type="text/javascript" src="main.js">
+</script>
+</head>
+<body>
+
+ <canvas id="canvas" width="800" height="600"><p>Fallback content goes here.</p></canvas>
+</body>
+</html>
@@ -0,0 +1,67 @@
+<html><head>
+<title>Line Intersection Tests</title>
+<script type="text/javascript">
+var width = 150;
+var height = 300;
+function getCanvas() {
+return document.getElementById('canvas');
+}
+
+window.addEventListener('load', function() {
+ var canvas = getCanvas();
+ if(canvas && canvas.getContext) {
+ var context = canvas.getContext('2d');
+ if (context) {
+ context.fillStyle = '#fff';
+ context.fillRect(0, 0, width, height);
+ }
+ }
+ canvas.addEventListener('mousemove', mouseMove, false);
+}, false);
+
+function getEventXCoord(ev){
+ if(ev.layerX){ //Firefox
+ return ev.layerX;
+ }
+ return ev.offsetX; //Opera
+}
+function getEventYCoord(ev){
+ if(ev.layerY){ //Firefox
+ return ev.layerY;
+ }
+ return ev.offsetY; //Opera
+}
+
+function mouseMove(ev) {
+ //alert('t3');
+ var canvas = getCanvas();
+ context = canvas.getContext('2d');
+ context.fillStyle = '#fff';
+ context.fillRect(0, 0, width, height);
+ context.fillStyle = '#f00'; //red
+ //alert('t3.5');
+ context.strokeStyle = '#000'; //green
+ context.lineWidth = 4;
+ context.beginPath();
+ //alert('t3.75');
+ context.moveTo(0, 0);
+ //alert('t3.95');
+ var x = getEventXCoord(ev);
+ var y = getEventYCoord(ev);
+ context.lineTo(x, y);
+ //alert('t4');
+ context.closePath();
+ //alert('t5');
+ context.fill();
+ //alert('t6');
+ context.stroke();
+ //alert('t7');
+
+};
+</script>
+</head>
+<body>
+
+ <canvas id="canvas" width="200" height="200"><p>Fallback content goes here.</p></canvas>
+</body>
+</html>
132 main.js
@@ -0,0 +1,132 @@
+var width = 800;
+var height = 600;
+function getCanvas() {
+ return document.getElementById('canvas');
+}
+
+window.addEventListener('load', function() {
+ var canvas = getCanvas();
+ if(canvas && canvas.getContext) {
+ var context = canvas.getContext('2d');
+ if (context) {
+ context.fillStyle = '#fff';
+ context.fillRect(0, 0, width, height);
+ }
+ }
+ canvas.addEventListener('mousemove', mouseMove, false);
+ canvas.addEventListener('mousedown', mouseDown, false);
+
+
+}, false);
+
+function getEventXCoord(ev){
+ if(ev.layerX){ //Firefox
+ return ev.layerX;
+ }
+ return ev.offsetX; //Opera
+}
+function getEventYCoord(ev){
+ if(ev.layerY){ //Firefox
+ return ev.layerY;
+ }
+ return ev.offsetY; //Opera
+}
+
+function Vector(x, y){
+ this.x = x;
+ this.y = y;
+ this.draw = function() {
+ var canvas = getCanvas();
+ context = canvas.getContext('2d');
+ context.strokeStyle = '#000'; //black
+ context.fillRect(this.x, this.y, 5, 5);
+
+ };
+ this.dot = function(v2) {
+ return this.x * v2.x + this.y * v2.y;
+ };
+ this.perp = function() {
+ return new Vector(-1 * this.y, this.x);
+ };
+ this.subtract = function(v2) {
+ return new Vector(this.x - v2.x, this.y - v2.y);
+ };
+}
+
+function Segment(p1, p2){
+ //alert('s1');
+ this.p1 = p1;
+ this.p2 = p2;
+ //alert('s2');
+ this.draw = function() {
+ //alert('s3');
+ var canvas = getCanvas();
+ context = canvas.getContext('2d');
+ context.strokeStyle = '#000'; //black
+ context.lineWidth = 4;
+ //alert('s4');
+ context.beginPath();
+ context.moveTo(p1.x, p1.y);
+ context.lineTo(p2.x, p2.y);
+ //alert('s5');
+ context.closePath();
+ context.stroke();
+ //alert('s6');
+ };
+
+}
+
+function intersect(seg1, seg2) {
+
+}
+
+function mouseDown(ev){
+ var canvas = getCanvas();
+ context = canvas.getContext('2d');
+
+}
+
+function getLine2(){
+ return new Segment(new Vector(0, 100), new Vector(150, 50));
+}
+
+function drawLine2(){
+ var canvas = getCanvas();
+ context = canvas.getContext('2d');
+
+}
+
+function mouseMove(ev) {
+ //alert('t3');
+ var canvas = getCanvas();
+ context = canvas.getContext('2d');
+ context.fillStyle = '#fff';
+ context.fillRect(0, 0, width, height);
+ context.fillStyle = '#f00'; //red
+ //alert('t3.5');
+ context.strokeStyle = '#000'; //green
+ context.lineWidth = 4;
+ //context.beginPath();
+ //alert('t3.75');
+ //context.moveTo(0, 0);
+ //alert('t3.95');
+ var x = getEventXCoord(ev);
+ var y = getEventYCoord(ev);
+ //context.lineTo(x, y);
+ //alert('t4');
+ //context.closePath();
+ //alert('t5');
+ //context.fill();
+ //alert('t6');
+ //context.stroke();
+ //alert('t7');
+ //alert('b1');
+ var seg1 = new Segment(new Vector(0, 0), new Vector(x, y));
+ //alert('b2');
+ seg1.draw();
+
+ var seg2 = new Segment(new Vector(0, 100), new Vector(100, 50));
+ seg2.draw();
+};
+
+
No changes.

0 comments on commit 1438a04

Please sign in to comment.