-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoollines.html
132 lines (117 loc) · 2.61 KB
/
coollines.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<body tabindex=0>
<canvas style="position:fixed; top:0; left:0;" id="c">
</canvas>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>
<script>
// Credits: This comes from a simple script at
// http://davidbau.com/archives/2010/11/22/stuck_pixel_utility.html
var canvas = null;
var context = null;
try {
canvas = $('#c').get(0);
context = canvas.getContext('2d');
} catch (e) {
document.write('<tt><canvas></tt> unsupported on this browser.<br>'+e);
}
if (context) { $(function() {
var posx = Math.floor($(window).width() / 2);
var posy = Math.floor($(window).height() / 2);
var colors = {
'W': { dim: '#112', bright: '#fff' },
'R': { dim: '#300', bright: '#f00' },
'G': { dim: '#020', bright: '#0f0' },
'B': { dim: '#003', bright: '#00f' }
};
var color = 'W';
function redraw() {
context.fillStyle="#000";
context.fillRect(0, 0, $(window).width(), $(window).height());
//context.fillStyle = colors[color].dim;
//context.fillRect(posx, 0, 10, $(window).height());
//context.fillRect(0, posy, $(window).width(), 10);
}
$('body').click(function(event) {
posx = event.pageX;
posy = event.pageY;
redraw();
});
$('body').keydown(function(event) {
switch (event.keyCode) {
case 37: posx -= 1; break;
case 38: posy -= 1; break;
case 39: posx += 1; break;
case 40: posy += 1; break;
default:
var key = String.fromCharCode(event.keyCode);
if (key in colors) color = key;
}
redraw();
});
$('body').focus();
var index = 0;
var x1 = 0;
var y1 = 0;
var x2 = 10;
var y2 = 0;
var dx1 = 10;
var dy1 = 5;
var dx2 = 6;
var dy2 = 10;
setInterval(function() {
//context.fillStyle = ['#000', colors[color].bright][index]
//context.fillRect(posx, posy, 10, 10);
//index = (index + 1) % 2;
var w = $(window).width();
var h = $(window).height()
context.strokeStyle="#FF0000";
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.stroke();
x1 = x1 + dx1;
x2 = x2 + dx2;
y1 = y1 + dy1;
y2 = y2 + dy2;
if (x1>w) {
x1 = (w-(x1-w));
dx1 = -dx1;
};
if (x1<0) {
x1 = -x1;
dx1 = -dx1;
};
if (x2>w) {
x2 = (w-(x2-w));
dx2 = -dx2;
};
if (x2<0) {
x2 = -x2;
dx2 = -dx2;
};
if (y1>h) {
y1 = (h-(y1-h));
dy1 = -dy1;
};
if (y1<0) {
y1 = -y1;
dy1 = -dy1;
};
if (y2>h) {
y2 = (h-(y2-h));
dy2 = -dy2;
};
if (y2<0) {
y2 = -y2;
dy2 = -dy2;
};
}, 1);
$(window).resize(function() {
canvas.width = $(window).width();
canvas.height = $(window).height();
redraw();
});
$(window).resize();
});
}
</script>