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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Untitled Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type='text/css'>
#conteneur {
position: relative;
overflow: hidden;
width: 500px;
height: 500px;
padding: 0;
background-color: white;
border: 1px solid #7f9db9;
}
#graph {
position: absolute;
top: 0;
left: 0;
padding: 0;
}
#graph div{
position: absolute;
width: 1px;
height: 1px;
}
.VisibleOn{display: block;}
.VisibleOff{display: none;}
</style>
<script type="text/javascript">
var myAbsisse = 0;
var points = [];
var heightGraph = 500;
var widthGraph = 500;
var FirstPoints = 0;
var last_top = 0;
var last_x = 0;
var last_y = 0;
/*
function plot(x, y, color) {
var e;
if (x < widthGraph){
e = document.createElement('div');
points.push(e);
document.getElementById('graph').appendChild(e);
} else {
e = points[FirstPoints%widthGraph];
FirstPoints++;
document.getElementById('graph').style.left = -FirstPoints + "px";
}
e.style.left = Math.round(x) + "px";
e.style.top = ((heightGraph/2) - Math.round(y)) + "px";
e.style.backgroundColor = color;
}
*/
function plotPoints(x, y, color){
var a = (y - last_y) / (x - last_x); // calcul de la pente
var i = 0;
var myY;
while (++last_x < x){
myY = Math.round(last_y + (a * ++i));
plot(last_x, myY, color);
}
plot(x, y, color);
last_x = x;
last_y = y;
}
function plot(x, y, color) {
var e;
if (x < widthGraph){
e = document.createElement('div');
points.push(e);
document.getElementById('graph').appendChild(e);
} else {
e = points[FirstPoints%widthGraph];
FirstPoints++;
document.getElementById('graph').style.left = -FirstPoints + "px";
}
e.style.left = Math.round(x) + "px";
var top = ((heightGraph/2) - Math.round(y));
if(points.length==1) last_top = top; // cas initial
var h = last_top - top;
if(h==0) h = 1;
if(h>0) {
e.style.top = top + "px";
e.style.height = h + "px";
}
else {
h = -h;
e.style.top = (top - h) + "px";
e.style.height = h + "px";
}
e.style.backgroundColor = color;
last_top = top;
}
function InitGraph(){
setInterval(function(){RefreshGraph()}, 5);
};
function RefreshGraph(){
var y = Math.sin(myAbsisse/10) * 200;
plotPoints(myAbsisse, y, 'red');
myAbsisse += 5;
}
</script>
</head>
<body onload="InitGraph()">
<div id="conteneur">
<div id="graph"></div>
</div>
</body>
</html> |
Partager