Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first commit

  • Loading branch information...
commit 1438a044671e2f583ca93261d90e86419778fd13 0 parents
Bryan Bell authored May 22, 2009
0  README
No changes.
10  main.html
... ...
@@ -0,0 +1,10 @@
  1
+<html><head>
  2
+<title>Line Intersection Tests</title>
  3
+<script type="text/javascript" src="main.js">
  4
+</script>
  5
+</head>
  6
+<body>
  7
+
  8
+  <canvas id="canvas" width="800" height="600"><p>Fallback content goes here.</p></canvas>    
  9
+</body>
  10
+</html>
67  main.html~
... ...
@@ -0,0 +1,67 @@
  1
+<html><head>
  2
+<title>Line Intersection Tests</title>
  3
+<script type="text/javascript">
  4
+var width = 150;
  5
+var height = 300;
  6
+function getCanvas() {
  7
+return document.getElementById('canvas');
  8
+}
  9
+
  10
+window.addEventListener('load', function() {
  11
+  var canvas = getCanvas();
  12
+  if(canvas && canvas.getContext) {
  13
+    var context = canvas.getContext('2d');
  14
+    if (context) {
  15
+       context.fillStyle = '#fff';
  16
+       context.fillRect(0, 0, width, height);
  17
+    }
  18
+  }
  19
+  canvas.addEventListener('mousemove', mouseMove, false);
  20
+}, false);
  21
+
  22
+function getEventXCoord(ev){
  23
+ if(ev.layerX){ //Firefox
  24
+   return ev.layerX;
  25
+ }
  26
+ return ev.offsetX; //Opera
  27
+}
  28
+function getEventYCoord(ev){
  29
+ if(ev.layerY){ //Firefox
  30
+   return ev.layerY; 
  31
+ }
  32
+ return ev.offsetY; //Opera
  33
+}
  34
+
  35
+function mouseMove(ev) {
  36
+  //alert('t3');
  37
+  var canvas = getCanvas();
  38
+  context = canvas.getContext('2d');
  39
+  context.fillStyle = '#fff';
  40
+  context.fillRect(0, 0, width, height);
  41
+  context.fillStyle = '#f00'; //red
  42
+  //alert('t3.5');
  43
+  context.strokeStyle = '#000'; //green
  44
+  context.lineWidth = 4;
  45
+  context.beginPath();
  46
+  //alert('t3.75');
  47
+  context.moveTo(0, 0);
  48
+  //alert('t3.95');
  49
+  var x = getEventXCoord(ev);
  50
+  var y = getEventYCoord(ev);
  51
+  context.lineTo(x, y);
  52
+  //alert('t4');
  53
+  context.closePath();
  54
+  //alert('t5');
  55
+  context.fill();
  56
+  //alert('t6');
  57
+  context.stroke();
  58
+  //alert('t7');
  59
+
  60
+};
  61
+</script>
  62
+</head>
  63
+<body>
  64
+
  65
+  <canvas id="canvas" width="200" height="200"><p>Fallback content goes here.</p></canvas>    
  66
+</body>
  67
+</html>
132  main.js
... ...
@@ -0,0 +1,132 @@
  1
+var width = 800;
  2
+var height = 600;
  3
+function getCanvas() {
  4
+  return document.getElementById('canvas');
  5
+}
  6
+
  7
+window.addEventListener('load', function() {
  8
+			  var canvas = getCanvas();
  9
+			  if(canvas && canvas.getContext) {
  10
+			    var context = canvas.getContext('2d');
  11
+			    if (context) {
  12
+			      context.fillStyle = '#fff';
  13
+			      context.fillRect(0, 0, width, height);
  14
+			    }
  15
+			  }
  16
+			  canvas.addEventListener('mousemove', mouseMove, false);
  17
+			  canvas.addEventListener('mousedown', mouseDown, false);
  18
+
  19
+
  20
+}, false);
  21
+
  22
+function getEventXCoord(ev){
  23
+ if(ev.layerX){ //Firefox
  24
+   return ev.layerX;
  25
+ }
  26
+ return ev.offsetX; //Opera
  27
+}
  28
+function getEventYCoord(ev){
  29
+ if(ev.layerY){ //Firefox
  30
+   return ev.layerY;
  31
+ }
  32
+ return ev.offsetY; //Opera
  33
+}
  34
+
  35
+function Vector(x, y){
  36
+  this.x = x;
  37
+  this.y = y;
  38
+  this.draw = function() {
  39
+    var canvas = getCanvas();
  40
+    context = canvas.getContext('2d');
  41
+    context.strokeStyle = '#000'; //black
  42
+    context.fillRect(this.x, this.y, 5, 5);
  43
+
  44
+  };
  45
+  this.dot = function(v2) {
  46
+    return this.x * v2.x + this.y * v2.y;
  47
+  };
  48
+  this.perp = function() {
  49
+    return new Vector(-1 * this.y, this.x);
  50
+  };
  51
+  this.subtract = function(v2) {
  52
+    return new Vector(this.x - v2.x, this.y - v2.y);
  53
+  };
  54
+}
  55
+
  56
+function Segment(p1, p2){
  57
+  //alert('s1');
  58
+  this.p1 = p1;
  59
+  this.p2 = p2;
  60
+  //alert('s2');
  61
+  this.draw = function() {
  62
+    //alert('s3');
  63
+    var canvas = getCanvas();
  64
+    context = canvas.getContext('2d');
  65
+    context.strokeStyle = '#000'; //black
  66
+    context.lineWidth = 4;
  67
+    //alert('s4');
  68
+    context.beginPath();
  69
+    context.moveTo(p1.x, p1.y);
  70
+    context.lineTo(p2.x, p2.y);
  71
+    //alert('s5');
  72
+    context.closePath();
  73
+    context.stroke();
  74
+    //alert('s6');
  75
+  };
  76
+
  77
+}
  78
+
  79
+function intersect(seg1, seg2) {
  80
+
  81
+}
  82
+
  83
+function mouseDown(ev){
  84
+  var canvas = getCanvas();
  85
+  context = canvas.getContext('2d');
  86
+
  87
+}
  88
+
  89
+function getLine2(){
  90
+  return new Segment(new Vector(0, 100), new Vector(150, 50));
  91
+}
  92
+
  93
+function drawLine2(){
  94
+  var canvas = getCanvas();
  95
+  context = canvas.getContext('2d');
  96
+
  97
+}
  98
+
  99
+function mouseMove(ev) {
  100
+  //alert('t3');
  101
+  var canvas = getCanvas();
  102
+  context = canvas.getContext('2d');
  103
+  context.fillStyle = '#fff';
  104
+  context.fillRect(0, 0, width, height);
  105
+  context.fillStyle = '#f00'; //red
  106
+  //alert('t3.5');
  107
+  context.strokeStyle = '#000'; //green
  108
+  context.lineWidth = 4;
  109
+  //context.beginPath();
  110
+  //alert('t3.75');
  111
+  //context.moveTo(0, 0);
  112
+  //alert('t3.95');
  113
+  var x = getEventXCoord(ev);
  114
+  var y = getEventYCoord(ev);
  115
+  //context.lineTo(x, y);
  116
+  //alert('t4');
  117
+  //context.closePath();
  118
+  //alert('t5');
  119
+  //context.fill();
  120
+  //alert('t6');
  121
+  //context.stroke();
  122
+  //alert('t7');
  123
+  //alert('b1');
  124
+  var seg1 = new Segment(new Vector(0, 0), new Vector(x, y));
  125
+  //alert('b2');
  126
+  seg1.draw();
  127
+
  128
+  var seg2 = new Segment(new Vector(0, 100), new Vector(100, 50));
  129
+  seg2.draw();
  130
+};
  131
+
  132
+
0  main.js~
No changes.

0 notes on commit 1438a04

Please sign in to comment.
Something went wrong with that request. Please try again.