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
| <!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title> Calcul d'intégrale </title>
<link <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript">
function carre(x){
return (x * x);
}
function showIntegrale(){
var borneInf = parseInt(document.getElementById("borne_inf").value, 10);
var borneSup = parseInt(document.getElementById("borne_sup").value, 10);
var nbreInterval = parseInt(document.getElementById("nbre_interval").value, 10);
drawIntegrale(borneInf, borneSup, nbreInterval, carre);
}
function drawIntegrale(borneInf, borneSup, nbreInterval, callback){
var canvas = document.getElementById("drawing");
if (canvas.getContext) {
var interval = (borneSup - borneInf) / nbreInterval;
var maximum = max(borneInf, borneSup, nbreInterval, interval, callback);
var coefHoriz = canvas.width / borneSup;
var coefVert = - canvas.height / maximum;
var ctx = canvas.getContext("2d");
ctx.translate(0, canvas.height);
ctx.scale(coefHoriz, coefVert);
for ( i = 0; i < nbreInterval; i++)
ctx.fillRect((borneInf + i * interval), 0, interval, callback(borneInf + i * interval));
}
}
function max(borneInf, borneSup, nbreInterval, interval, callback){
var result = callback(borneSup);
for ( i = 0; i < nbreInterval; i++)
if (callback(borneInf + i * interval) > result) result = callback(borneInf + i * interval);
return result;
}
</script>
</head>
<body>
<section class="container">
<article name="data" class="well form-inline pull-left col-lg-5">
<legend>Entrer les valeurs pour le calcul</legend>
<fieldset class="row">
<label for="borneInferieure" class="col-lg-5">Borne inferieure :</label>
<input id="borne_inf" type="number" style="width:130px" class="input-sm form-control">
</fieldset>
<h1></h1>
<fieldset class="row">
<label for="borneSuperieure" class="col-lg-5">Borne superieure :</label>
<input id="borne_sup" type="number" style="width:120px" class="input-sm form-control">
</fieldset>
<h1></h1>
<fieldset class="row">
<label for="nbreIntervalles" class="col-lg-5">Nombre d'intervalles :</label>
<input id="nbre_interval" type="number" style="width:100px" class="input-sm form-control">
</fieldset>
<h1></h1>
<fieldset class="row">
<button class="btn btn-primary" type="submit" onclick="showIntegrale()"><span class="glyphicon glyphicon-ok-sign"></span> Dessiner l'integrale</button>
</fieldset>
</article>
</section>
<section class="container">
<article name="graphic" class="well form-inline pull-left col-lg-10">
<canvas id="drawing" width="750" height="500"></canvas>
</article>
</section>
</body>
</html> |