File: modelepagewebmac.txt

package info (click to toggle)
algobox 1.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,380 kB
  • sloc: cpp: 13,758; makefile: 13; xml: 8; sh: 5
file content (1523 lines) | stat: -rw-r--r-- 46,497 bytes parent folder | download | duplicates (3)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
<html>
<head>
<title>AlgoBox</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
BODY 
{
font-family:  'Liberation Sans', 'Arial',sans-serif;
background-color:#FFFFFF;
color:#000000;
margin-top: 5px;
margin-left: 5px;
margin-right: 5px;
margin-bottom: 5px;
}
A:link    { color:#335d88;font-weight: bold; text-decoration: none;}
A:visited { color:#335d88;font-weight: bold;  text-decoration: none;}
A:hover   { color:red; font-weight: bold; text-decoration: none;}

textarea
{
border-width : 1px;
font-family :  'Monaco', 'Courier New', monospace;
background : #f6f6f6;
padding : .1em .3em;
border-color : #000;
}

.header
{
    font-family: 'Liberation Sans', 'Arial',sans-serif;
    font-size: normal;
    font-weight:bold;
    color: #fff;
    background-color: #69c;
    border:2px solid #69c;
    font-size: 12pt;
    padding: 4px 20px;
    margin-left: 15px; 
    border-radius: 8px; 
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px; 
}

#footer
{
text-align: center;
font-size: .8em;
font-weight:bold;
color:#479;
font-family :  'Liberation Sans', 'Arial',sans-serif;
padding: 2px;
}

.post
{
    margin-bottom: 20px;
}

.post > FIELDSET
{
    background-color: #f9f9f9;
    padding: 0px;
    padding-top: 10px;
    padding-left: 10px;
    border:1px solid #69c;
    color:#000;
    border-radius: 20px; 
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px; 
}

.title
{
    background-color: #69c;
    border:2px solid #69c;
    font-size: 12pt;
    padding: 4px 20px;
    margin-left: 15px; 
    border-radius: 8px; 
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px; 
}

#title,
LEGEND,
LEGEND A
{
    font-family: 'Liberation Sans', 'Arial',sans-serif;
    color: #fff;
    font-weight:bold;
}

.code
{
    padding: 1px 15px;
    color: #111111;
    line-height: 120%;
    font-size: 10pt;
    font-family :  'Monaco', 'Courier New', monospace;
}

.graphique
{
    padding: 1px 15px;
    color: #111111;
    font-size: 10pt;
    font-family :  'Monaco', 'Courier New', monospace;
}

.output
{
    overflow: auto;
    padding: 1px 15px;
    color: #111111;
    font-size: 10pt;
}
.output pre 
{
margin: 0;
font-family: 'Monaco', 'Courier New', monospace;
padding: 0;
}

</style>
<script type="text/javascript">
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtWebChannel module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

"use strict";

var QWebChannelMessageTypes = {
    signal: 1,
    propertyUpdate: 2,
    init: 3,
    idle: 4,
    debug: 5,
    invokeMethod: 6,
    connectToSignal: 7,
    disconnectFromSignal: 8,
    setProperty: 9,
    response: 10,
};

var QWebChannel = function(transport, initCallback)
{
    if (typeof transport !== "object" || typeof transport.send !== "function") {
        console.error("The QWebChannel expects a transport object with a send function and onmessage callback property." +
                      " Given is: transport: " + typeof(transport) + ", transport.send: " + typeof(transport.send));
        return;
    }

    var channel = this;
    this.transport = transport;

    this.send = function(data)
    {
        if (typeof(data) !== "string") {
            data = JSON.stringify(data);
        }
        channel.transport.send(data);
    }

    this.transport.onmessage = function(message)
    {
        var data = message.data;
        if (typeof data === "string") {
            data = JSON.parse(data);
        }
        switch (data.type) {
            case QWebChannelMessageTypes.signal:
                channel.handleSignal(data);
                break;
            case QWebChannelMessageTypes.response:
                channel.handleResponse(data);
                break;
            case QWebChannelMessageTypes.propertyUpdate:
                channel.handlePropertyUpdate(data);
                break;
            default:
                console.error("invalid message received:", message.data);
                break;
        }
    }

    this.execCallbacks = {};
    this.execId = 0;
    this.exec = function(data, callback)
    {
        if (!callback) {
            // if no callback is given, send directly
            channel.send(data);
            return;
        }
        if (channel.execId === Number.MAX_VALUE) {
            // wrap
            channel.execId = Number.MIN_VALUE;
        }
        if (data.hasOwnProperty("id")) {
            console.error("Cannot exec message with property id: " + JSON.stringify(data));
            return;
        }
        data.id = channel.execId++;
        channel.execCallbacks[data.id] = callback;
        channel.send(data);
    };

    this.objects = {};

    this.handleSignal = function(message)
    {
        var object = channel.objects[message.object];
        if (object) {
            object.signalEmitted(message.signal, message.args);
        } else {
            console.warn("Unhandled signal: " + message.object + "::" + message.signal);
        }
    }

    this.handleResponse = function(message)
    {
        if (!message.hasOwnProperty("id")) {
            console.error("Invalid response message received: ", JSON.stringify(message));
            return;
        }
        channel.execCallbacks[message.id](message.data);
        delete channel.execCallbacks[message.id];
    }

    this.handlePropertyUpdate = function(message)
    {
        for (var i in message.data) {
            var data = message.data[i];
            var object = channel.objects[data.object];
            if (object) {
                object.propertyUpdate(data.signals, data.properties);
            } else {
                console.warn("Unhandled property update: " + data.object + "::" + data.signal);
            }
        }
        channel.exec({type: QWebChannelMessageTypes.idle});
    }

    this.debug = function(message)
    {
        channel.send({type: QWebChannelMessageTypes.debug, data: message});
    };

    channel.exec({type: QWebChannelMessageTypes.init}, function(data) {
        for (var objectName in data) {
            var object = new QObject(objectName, data[objectName], channel);
        }
        // now unwrap properties, which might reference other registered objects
        for (var objectName in channel.objects) {
            channel.objects[objectName].unwrapProperties();
        }
        if (initCallback) {
            initCallback(channel);
        }
        channel.exec({type: QWebChannelMessageTypes.idle});
    });
};

function QObject(name, data, webChannel)
{
    this.__id__ = name;
    webChannel.objects[name] = this;

    // List of callbacks that get invoked upon signal emission
    this.__objectSignals__ = {};

    // Cache of all properties, updated when a notify signal is emitted
    this.__propertyCache__ = {};

    var object = this;

    // ----------------------------------------------------------------------

    this.unwrapQObject = function(response)
    {
        if (response instanceof Array) {
            // support list of objects
            var ret = new Array(response.length);
            for (var i = 0; i < response.length; ++i) {
                ret[i] = object.unwrapQObject(response[i]);
            }
            return ret;
        }
        if (!response
            || !response["__QObject*__"]
            || response.id === undefined) {
            return response;
        }

        var objectId = response.id;
        if (webChannel.objects[objectId])
            return webChannel.objects[objectId];

        if (!response.data) {
            console.error("Cannot unwrap unknown QObject " + objectId + " without data.");
            return;
        }

        var qObject = new QObject( objectId, response.data, webChannel );
        qObject.destroyed.connect(function() {
            if (webChannel.objects[objectId] === qObject) {
                delete webChannel.objects[objectId];
                // reset the now deleted QObject to an empty {} object
                // just assigning {} though would not have the desired effect, but the
                // below also ensures all external references will see the empty map
                // NOTE: this detour is necessary to workaround QTBUG-40021
                var propertyNames = [];
                for (var propertyName in qObject) {
                    propertyNames.push(propertyName);
                }
                for (var idx in propertyNames) {
                    delete qObject[propertyNames[idx]];
                }
            }
        });
        // here we are already initialized, and thus must directly unwrap the properties
        qObject.unwrapProperties();
        return qObject;
    }

    this.unwrapProperties = function()
    {
        for (var propertyIdx in object.__propertyCache__) {
            object.__propertyCache__[propertyIdx] = object.unwrapQObject(object.__propertyCache__[propertyIdx]);
        }
    }

    function addSignal(signalData, isPropertyNotifySignal)
    {
        var signalName = signalData[0];
        var signalIndex = signalData[1];
        object[signalName] = {
            connect: function(callback) {
                if (typeof(callback) !== "function") {
                    console.error("Bad callback given to connect to signal " + signalName);
                    return;
                }

                object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];
                object.__objectSignals__[signalIndex].push(callback);

                if (!isPropertyNotifySignal && signalName !== "destroyed") {
                    // only required for "pure" signals, handled separately for properties in propertyUpdate
                    // also note that we always get notified about the destroyed signal
                    webChannel.exec({
                        type: QWebChannelMessageTypes.connectToSignal,
                        object: object.__id__,
                        signal: signalIndex
                    });
                }
            },
            disconnect: function(callback) {
                if (typeof(callback) !== "function") {
                    console.error("Bad callback given to disconnect from signal " + signalName);
                    return;
                }
                object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];
                var idx = object.__objectSignals__[signalIndex].indexOf(callback);
                if (idx === -1) {
                    console.error("Cannot find connection of signal " + signalName + " to " + callback.name);
                    return;
                }
                object.__objectSignals__[signalIndex].splice(idx, 1);
                if (!isPropertyNotifySignal && object.__objectSignals__[signalIndex].length === 0) {
                    // only required for "pure" signals, handled separately for properties in propertyUpdate
                    webChannel.exec({
                        type: QWebChannelMessageTypes.disconnectFromSignal,
                        object: object.__id__,
                        signal: signalIndex
                    });
                }
            }
        };
    }

    /**
     * Invokes all callbacks for the given signalname. Also works for property notify callbacks.
     */
    function invokeSignalCallbacks(signalName, signalArgs)
    {
        var connections = object.__objectSignals__[signalName];
        if (connections) {
            connections.forEach(function(callback) {
                callback.apply(callback, signalArgs);
            });
        }
    }

    this.propertyUpdate = function(signals, propertyMap)
    {
        // update property cache
        for (var propertyIndex in propertyMap) {
            var propertyValue = propertyMap[propertyIndex];
            object.__propertyCache__[propertyIndex] = propertyValue;
        }

        for (var signalName in signals) {
            // Invoke all callbacks, as signalEmitted() does not. This ensures the
            // property cache is updated before the callbacks are invoked.
            invokeSignalCallbacks(signalName, signals[signalName]);
        }
    }

    this.signalEmitted = function(signalName, signalArgs)
    {
        invokeSignalCallbacks(signalName, signalArgs);
    }

    function addMethod(methodData)
    {
        var methodName = methodData[0];
        var methodIdx = methodData[1];
        object[methodName] = function() {
            var args = [];
            var callback;
            for (var i = 0; i < arguments.length; ++i) {
                if (typeof arguments[i] === "function")
                    callback = arguments[i];
                else
                    args.push(arguments[i]);
            }

            webChannel.exec({
                "type": QWebChannelMessageTypes.invokeMethod,
                "object": object.__id__,
                "method": methodIdx,
                "args": args
            }, function(response) {
                if (response !== undefined) {
                    var result = object.unwrapQObject(response);
                    if (callback) {
                        (callback)(result);
                    }
                }
            });
        };
    }

    function bindGetterSetter(propertyInfo)
    {
        var propertyIndex = propertyInfo[0];
        var propertyName = propertyInfo[1];
        var notifySignalData = propertyInfo[2];
        // initialize property cache with current value
        // NOTE: if this is an object, it is not directly unwrapped as it might
        // reference other QObject that we do not know yet
        object.__propertyCache__[propertyIndex] = propertyInfo[3];

        if (notifySignalData) {
            if (notifySignalData[0] === 1) {
                // signal name is optimized away, reconstruct the actual name
                notifySignalData[0] = propertyName + "Changed";
            }
            addSignal(notifySignalData, true);
        }

        Object.defineProperty(object, propertyName, {
            configurable: true,
            get: function () {
                var propertyValue = object.__propertyCache__[propertyIndex];
                if (propertyValue === undefined) {
                    // This shouldn't happen
                    console.warn("Undefined value in property cache for property \"" + propertyName + "\" in object " + object.__id__);
                }

                return propertyValue;
            },
            set: function(value) {
                if (value === undefined) {
                    console.warn("Property setter for " + propertyName + " called with undefined value!");
                    return;
                }
                object.__propertyCache__[propertyIndex] = value;
                webChannel.exec({
                    "type": QWebChannelMessageTypes.setProperty,
                    "object": object.__id__,
                    "property": propertyIndex,
                    "value": value
                });
            }
        });

    }

    // ----------------------------------------------------------------------

    data.methods.forEach(addMethod);

    data.properties.forEach(bindGetterSetter);

    data.signals.forEach(function(signal) { addSignal(signal, false); });

    for (var name in data.enums) {
        object[name] = data.enums[name];
    }
}

//required for use with nodejs
if (typeof module === 'object') {
    module.exports = {
        QWebChannel: QWebChannel
    };
}





</script>

<script language="JavaScript">
        new QWebChannel(qt.webChannelTransport, function (channel) {
                    browserDialog = channel.objects.BrowserDialog;
            });
/***************************************************************************
 *   copyright       : (C) 2009-2013 by Pascal Brachet                     *
 *   with the collaboration of Joël Amblard                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

var ALGOBOX_x1=0;
var ALGOBOX_x2=450;
var ALGOBOX_y1=0;
var ALGOBOX_y2=450;
var ALGOBOX_canevas_repere=document.createElement("canvas");
if (navigator.appName!="Microsoft Internet Explorer")
    {
    var ALGOBOX_contexte_repere=ALGOBOX_canevas_repere.getContext("2d");
    }
ALGOBOX_canevas_repere.style.left=0;
ALGOBOX_canevas_repere.style.zIndex=0;
ALGOBOX_canevas_repere.setAttribute("width",ALGOBOX_x2+4);
ALGOBOX_canevas_repere.setAttribute("height",ALGOBOX_y2+4);

var ALGOBOX_canevas=document.createElement("canvas");
if (navigator.appName!="Microsoft Internet Explorer")
    {
    var ALGOBOX_contexte=ALGOBOX_canevas.getContext("2d");
    }
ALGOBOX_canevas.style.left=0;
ALGOBOX_canevas.style.position="absolute";
ALGOBOX_canevas.style.zIndex=1;
ALGOBOX_canevas.setAttribute("width",ALGOBOX_x2+4);
ALGOBOX_canevas.setAttribute("height",ALGOBOX_y2+4);
var ALGOBOX_REPERE_DEFINI=false;
var ALGOBOX_Xmin=-10;
var ALGOBOX_Xmax=10;
var ALGOBOX_Ymin=-10;
var ALGOBOX_Ymax=10;
var ALGOBOX_gradx=1;
var ALGOBOX_grady=1;
var ALGOBOX_COMPTEUR_AFFICHAGE=0;
var ALGOBOX_COMPTEUR_ETAPE=0;
var ALGOBOX_DEPASSEMENT_AFFICHAGE=false;
var ALGOBOX_COMPTEUR_BOUCLE_GLOBAL=0;
var ALGOBOX_COMPTEUR_RECURSION=0;
var ALGOBOX_LIGNE_COURANTE=1;
var ALGOBOX_EMERGENCY_STOP=false;

//*******************************
function ALGOBOX_SOMME(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var somme=0;
for (var ind = debut; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else somme+=liste[ind];
  }
return somme;
}

function ALGOBOX_MOYENNE(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var somme, result;
somme=ALGOBOX_SOMME(liste,debut,fin);
if (somme=="Erreur") return "Erreur";
result=somme/(fin-debut+1);
return result;
}

function ALGOBOX_VARIANCE(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var carres=new Array();
var moyenne=ALGOBOX_MOYENNE(liste,debut,fin);
var somme,result;
if (moyenne=="Erreur") return "Erreur";
for (var ind = debut; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else carres[ind]=Math.pow(liste[ind]-moyenne,2);
  }
somme=ALGOBOX_SOMME(carres,debut,fin);
if (somme=="Erreur") return "Erreur";
result=somme/(fin-debut+1);
return result;
}

function ALGOBOX_ECART_TYPE(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var variance,result;
variance=ALGOBOX_VARIANCE(liste,debut,fin);
if ((variance=="Erreur") || (variance<0)) return "Erreur";
result=Math.sqrt(variance);
return result;
}

function ALGOBOX_MEDIANE(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var liste_triee=new Array();
for (var ind = debut; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else liste_triee[ind-debut]=liste[ind];
  }
liste_triee.sort(function(a,b){ return a-b } );
var eff=fin-debut+1;
var rang=Math.floor(eff/2);
var mediane;
if (eff%2==0)  mediane=(liste_triee[rang]+liste_triee[rang-1])/2;
else mediane=liste_triee[rang];
return mediane;
}

function ALGOBOX_QUARTILE1(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var eff=fin-debut+1;
if (eff<4) return "Erreur";
var liste_triee=new Array();
for (var ind = debut; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else liste_triee[ind-debut]=liste[ind];
  }
liste_triee.sort(function(a,b){ return a-b } );
var quartile;
var reste=eff%4;
var quotient=Math.floor(eff/4);
switch (reste)
  {
  case 0:
  quartile=(liste_triee[quotient-1]+liste_triee[quotient])/2;
  break;
  case 1:
  quartile=(liste_triee[quotient-1]+liste_triee[quotient])/2;
  break;
  case 2:
  quartile=liste_triee[quotient];
  break;
  case 3:
  quartile=liste_triee[quotient];
  break;
  }
return quartile;
}

function ALGOBOX_QUARTILE3(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var eff=fin-debut+1;
if (eff<4) return "Erreur";
var liste_triee=new Array();
for (var ind = debut; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else liste_triee[ind-debut]=liste[ind];
  }
liste_triee.sort(function(a,b){ return a-b } );
var quartile;
var reste=eff%4;
var quotient=Math.floor(eff/4);
switch (reste)
  {
  case 0:
  quartile=(liste_triee[3*quotient-1]+liste_triee[3*quotient])/2;
  break;
  case 1:
  quartile=(liste_triee[3*quotient]+liste_triee[3*quotient+1])/2;
  break;
  case 2:
  quartile=liste_triee[3*quotient+1];
  break;
  case 3:
  quartile=liste_triee[3*quotient+2];
  break;
  }
return quartile;
}

function ALGOBOX_QUARTILE1_BIS(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var eff=fin-debut+1;
if (eff<4) return "Erreur";
var liste_triee=new Array();
for (var ind = debut; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else liste_triee[ind-debut]=liste[ind];
  }
liste_triee.sort(function(a,b){ return a-b } );
var quartile;
var quotient=Math.floor(eff/4);
var reste=eff/4-quotient;
if (reste==0) quartile=liste_triee[quotient-1];
else quartile=liste_triee[quotient];
return quartile;
}

function ALGOBOX_QUARTILE3_BIS(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
var eff=fin-debut+1;
if (eff<4) return "Erreur";
var liste_triee=new Array();
for (var ind = debut; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else liste_triee[ind-debut]=liste[ind];
  }
liste_triee.sort(function(a,b){ return a-b } );
var quartile;
var quotient=Math.floor(3*eff/4);
var reste=3*eff/4-quotient;
if (reste==0) quartile=liste_triee[quotient-1];
else quartile=liste_triee[quotient];
return quartile;
}

function ALGOBOX_MINIMUM(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
if ( (!isFinite(liste[debut])) || isNaN(liste[debut])) return "Erreur";
var result=liste[debut];
for (var ind = debut+1; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else if (liste[ind]<result) result=liste[ind];
  }
return result;
}

function ALGOBOX_POS_MINIMUM(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
if ( (!isFinite(liste[debut])) || isNaN(liste[debut])) return "Erreur";
var result=debut;
for (var ind = debut+1; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else if (liste[ind]<liste[result]) result=ind;
  }
return result;
}

function ALGOBOX_MAXIMUM(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
if ( (!isFinite(liste[debut])) || isNaN(liste[debut])) return "Erreur";
var result=liste[debut];
for (var ind = debut+1; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else if (liste[ind]>result) result=liste[ind];
  }
return result;
}

function ALGOBOX_POS_MAXIMUM(liste,debut,fin)
{
if ( (!isFinite(debut)) || isNaN(debut) || (!isFinite(fin)) || isNaN(fin)) return "Erreur";
if ( (debut<0) && (debut>fin) ) return "Erreur";
if ( (!isFinite(liste[debut])) || isNaN(liste[debut])) return "Erreur";
var result=debut;
for (var ind = debut+1; ind<=fin ; ind++)
  {
  if ( (!isFinite(liste[ind])) || isNaN(liste[ind])) return "Erreur";
  else if (liste[ind]>liste[result]) result=ind;
  }
return result;
}
//*******************************
function ALGOBOX_FACTORIELLE(n)
{
if ( (!isFinite(n)) || isNaN(n)) return "Erreur";
if ( (n<0) || (n>69) ) return "Erreur";
if ( parseInt(n)!=n ) return "Erreur";
if (n<=1) return 1;
else return n*ALGOBOX_FACTORIELLE(n-1);
}

function ALGOBOX_NB_COMBINAISONS(n,p)
{
var cn,cp,tp,result;
if ( (!isFinite(n)) || isNaN(n)) return "Erreur";
if ( (n<0) || (n>100) ) return "Erreur";
if ( parseInt(n)!=n ) return "Erreur";
if ( (!isFinite(p)) || isNaN(p)) return "Erreur";
if ( (p<0) || (p>100) ) return "Erreur";
if ( parseInt(p)!=p ) return "Erreur";
cn=n;
cp=p;
if (cp>cn)  
  {
  tp=cn;
  cn=cp;
  cp=tp;
  }
if (cn==cp || cp==0) return 1;
if (cp==1) return cn;
result=cn/cp;
for(var i=1;i<=cp-1;i++)
  {
  result=result*(cn-i)/(cp-i);
  }
return result;
}

function ALGOBOX_COEFF_BINOMIAL(n,p)
{
return ALGOBOX_NB_COMBINAISONS(n,p);
}

function ALGOBOX_LOI_BINOMIALE(n,p,k)
{
if ( (!isFinite(n)) || isNaN(n)) return "Erreur";
if ( (n<0) || (n>100) ) return "Erreur";
if ( parseInt(n)!=n ) return "Erreur";
if ( (!isFinite(k)) || isNaN(k)) return "Erreur";
if ( (k<0) || (k>100) ) return "Erreur";
if ( parseInt(k)!=k ) return "Erreur";
if ( k>n ) return "Erreur";
if ( (!isFinite(p)) || isNaN(p)) return "Erreur";
if ( (p<0) || (p>1) ) return "Erreur";
var cn=ALGOBOX_NB_COMBINAISONS(n,k);
if (cn=="Erreur") return "Erreur";
return cn*Math.pow(p,k)*Math.pow(1-p,n-k);
}

function ALGOBOX_LOI_NORMALE_CR(x)
{
var xabs,s,t,b,q,i;
if ( (!isFinite(x)) || isNaN(x)) return "Erreur";
xabs=Math.abs(x);
if (xabs<5)
  {
    s = xabs;
    t = 0;
    b = xabs;
    q = xabs * xabs;
    i = 1 ;
    while(s > t) { s = (t = s) + (b *=q / (i += 2)) }
    s= .5 + s * Math.exp(-.5 * q - .91893853320467274178) ;
    s=Math.floor(s*100000000+0.5)/100000000;
  }
else s=1;
if (x<0) s=1-s;
return s;
}

function ALGOBOX_LOI_NORMALE(esp,ecart,x)
{
var xcr;
if ( (!isFinite(esp)) || isNaN(esp)) return "Erreur";
if ( (!isFinite(ecart)) || isNaN(ecart)) return "Erreur";
if (ecart<=0) return "Erreur";
if ( (!isFinite(x)) || isNaN(x)) return "Erreur";
xcr=(x-esp)/ecart;
return ALGOBOX_LOI_NORMALE_CR(xcr);
}

function ALGOBOX_INVERSE_LOI_NORMALE_CR(p)
{
if ( (!isFinite(p)) || isNaN(p)) return "Erreur";
if ( (p<=0) || (p>=1) ) return "Erreur";
var a_Ninv = [-39.69683028665376 ,  220.9460984245205 , -275.9285104469687 ,  138.3577518672690 , -30.66479806614716 ,  2.506628277459239] ;
var b_Ninv = [-54.47609879822406,  161.5858368580409, -155.6989798598866,  66.80131188771972, -13.28068155288572 , 1] ;
var c_Ninv = [-.007784894002430293 , -.3223964580411365 , -2.400758277161838, -2.549732539343734, 4.374664141464968,  2.938163982698783] ;
var d_Ninv = [.007784695709041462, .3224671290700398, 2.445134137142996,  3.754408661907416 , 1] ;
var horn = function(A , v) { var w = A[0] ; for (var i = 1 , l = A.length ; l - i ; i++) { w *= v ; w += A[i] } return w } ;
var Phi = function (x) {
    var s = x < 0 ? -x : x , t = 0 , b = s , q = s * s , i = 1 ;
    while(s > t) s = (t = s) + (b *=q / (i += 2)) ;
    s *= Math.exp(-.5 * q - .91893853320467274178) ;
    return x < 0 ? .5 - s  : .5 + s 
}
var q , r,u,e,x ,result;
if (p < 0.02425) x =  horn(c_Ninv , q  = Math.sqrt(-2*Math.log(p))) / horn(d_Ninv , q) ;
else if (p > 0.97575) x = -horn(c_Ninv , q  = Math.sqrt(-2*Math.log(1 - p))) / horn(d_Ninv , q) ;
else { q = p - 0.5 ; x = q * horn(a_Ninv , r = q*q) / horn(b_Ninv , r) }
e = Phi(x) - p ; u = e * Math.sqrt(2 * Math.PI) * Math.exp(x*x/2) ;
result= x - u ;
result=Math.floor(result*100000000+0.5)/100000000;
return result;
}

function ALGOBOX_INVERSE_LOI_NORMALE(esp,ecart,p)
{
var result;
if ( (!isFinite(esp)) || isNaN(esp)) return "Erreur";
if ( (!isFinite(ecart)) || isNaN(ecart)) return "Erreur";
if (ecart<=0) return "Erreur";
if ( (!isFinite(p)) || isNaN(p)) return "Erreur";
if ( (p<=0) || (p>=1) ) return "Erreur";
result=ALGOBOX_INVERSE_LOI_NORMALE_CR(p)*ecart+esp;
return result;
}

function ALGOBOX_ALEA_ENT(p,n)
{
var cp,cn,tp;
if ( (!isFinite(n)) || isNaN(n)) return "Erreur";
if (n<0) return "Erreur";
if ( parseInt(n)!=n ) return "Erreur";
if ( (!isFinite(p)) || isNaN(p)) return "Erreur";
if (p<0) return "Erreur";
if ( parseInt(p)!=p ) return "Erreur";
if (n==p) return "Erreur";
cn=n;
cp=p;
if (cp>cn)  
  {
  tp=cn;
  cn=cp;
  cp=tp;
  }
return Math.floor((cn-cp+1)*Math.random()+cp);
}

//*******************************
function ALGOBOX_CALCULER_EXPRESSION(calcul)
{
var r;
calcul.replace(new RegExp("Math.PI","g"),"PI");
while (calcul.charAt(0) == '0') 
  {
  if (calcul.length == 1) { break };
  if (calcul.charAt(1) == '.') { break };
  calcul = calcul.substr(1,calcul.length-1)
  }
with (Math) {r=eval(calcul)}
if ( (!isFinite(r)) || isNaN(r)) return "Erreur";
else return ALGOBOX_ARRONDI(r);
}

function ALGOBOX_FORMAT_TEXTE(u)
{
var r,negatif,m,p,result;
if (isNaN(u)) result="Erreur";
else 
	{
	if (u<0) negatif=true;
	r=String(Math.abs(u).toPrecision(#NB_DECIMALES_AFFICHEES#));
	if (r.lastIndexOf("e")>0)
	  {
	  m=r.substring(0,r.lastIndexOf("e"));
	  p=r.substring(r.lastIndexOf("e"),r.length);
 	  while ((m.length>1) && (m.indexOf(".")>=0) && (m.lastIndexOf("0")==m.length-1)) {m=m.substring(0,m.length-1);}
 	  if ((m.length>1) && (m.lastIndexOf(".")==m.length-1)) {m=m.substring(0,m.length-1);}
	  result=m+p;
	  }
	else
	  {
 	  while ((r.length>1) && (r.indexOf(".")>=0) && (r.lastIndexOf("0")==r.length-1)) {r=r.substring(0,r.length-1);}
 	  if ((r.length>1) && (r.lastIndexOf(".")==r.length-1)) {r=r.substring(0,r.length-1);}
	  result=r;
	  }
	if (result.substring(0,1)==".") result="0"+result;
	if (negatif) result='-'+result;
	}   
return result;
}

function ALGOBOX_ENTIER(nb) 
{ 
if (Math.abs(nb)<1) return 0 
else return parseInt(nb);
}

function ALGOBOX_ARRONDIR(nb,pre) 
{
if ( (!isFinite(nb)) || isNaN(nb)) return "Erreur";
else return parseFloat(nb.toFixed(ALGOBOX_ENTIER(pre)));
}

function ALGOBOX_ARRONDI(nb) 
{
if ( (!isFinite(nb)) || isNaN(nb)) return "Erreur";
#INSTRUCTION_ARRONDI#
}
//******************
function ALGOBOX_HX(ALGOBOX_x)
{
return (ALGOBOX_x2-ALGOBOX_x1)/(ALGOBOX_Xmax-ALGOBOX_Xmin)*(ALGOBOX_x-ALGOBOX_Xmin)+ALGOBOX_x1;
}

function ALGOBOX_HY(ALGOBOX_y)
{
return (ALGOBOX_y1-ALGOBOX_y2)/(ALGOBOX_Ymax-ALGOBOX_Ymin)*(ALGOBOX_y-ALGOBOX_Ymax)+ALGOBOX_y1;
}

function ALGOBOX_AXEX()
{
 ALGOBOX_DESSINE(0,ALGOBOX_Ymin,0,ALGOBOX_Ymax,5);
}

function ALGOBOX_AXEY()
{
ALGOBOX_DESSINE(ALGOBOX_Xmin,0,ALGOBOX_Xmax,0,5);
}

function ALGOBOX_IHX(ALGOBOX_x)
{
return ALGOBOX_x*(ALGOBOX_Xmax-ALGOBOX_Xmin)/(ALGOBOX_x2-ALGOBOX_x1);
}

function ALGOBOX_IHY(ALGOBOX_y)
{
return ALGOBOX_y*(ALGOBOX_Ymax-ALGOBOX_Ymin)/(ALGOBOX_y1-ALGOBOX_y2);
}

function ALGOBOX_DESSINE(ALGOBOX_X,ALGOBOX_Y,ALGOBOX_U,ALGOBOX_V,ALGOBOX_coul)
{
if (navigator.appName=="Microsoft Internet Explorer") return;
if (ALGOBOX_coul==9)
{
ALGOBOX_contexte.globalCompositeOperation = "destination-out";
ALGOBOX_contexte.beginPath();
ALGOBOX_contexte.lineWidth=2*#LINEWIDTH#;
ALGOBOX_contexte.strokeStyle="rgba(0,0,0,1)";
ALGOBOX_contexte.fillStyle="rgba(0,0,0,1)";
ALGOBOX_contexte.moveTo(Math.round(ALGOBOX_HX(ALGOBOX_X))+2,Math.round(ALGOBOX_HY(ALGOBOX_Y))+2);
ALGOBOX_contexte.lineTo(Math.round(ALGOBOX_HX(ALGOBOX_U))+2,Math.round(ALGOBOX_HY(ALGOBOX_V))+2);
ALGOBOX_contexte.stroke();
ALGOBOX_contexte.globalCompositeOperation = "source-over";
}
else
{
if ((ALGOBOX_coul==0) || (ALGOBOX_coul==5))  ALGOBOX_contexte_repere.beginPath();
else ALGOBOX_contexte.beginPath();
    switch (ALGOBOX_coul)
    {
    case 0:
    ALGOBOX_contexte_repere.strokeStyle='#ccc';
    ALGOBOX_contexte_repere.lineWidth=1;
    break;
    case 1:
    ALGOBOX_contexte.strokeStyle="black";
    ALGOBOX_contexte.lineWidth=#LINEWIDTH#;
    break;
    case 2:
    ALGOBOX_contexte.strokeStyle="#4040FF";
    ALGOBOX_contexte.lineWidth=#LINEWIDTH#;
    break;
    case 3:
    ALGOBOX_contexte.strokeStyle="#FF420E";
    ALGOBOX_contexte.lineWidth=#LINEWIDTH#;
    break;
    case 4:
    ALGOBOX_contexte.strokeStyle="#00CC00";
    ALGOBOX_contexte.lineWidth=#LINEWIDTH#;
    break;
    case 5:
    ALGOBOX_contexte_repere.strokeStyle="black";
    ALGOBOX_contexte_repere.lineWidth=1;
    break;
    }
if ((ALGOBOX_coul==0) || (ALGOBOX_coul==5))
  {
  ALGOBOX_contexte_repere.moveTo(Math.round(ALGOBOX_HX(ALGOBOX_X))+2.5,Math.round(ALGOBOX_HY(ALGOBOX_Y))+2.5);
  ALGOBOX_contexte_repere.lineTo(Math.round(ALGOBOX_HX(ALGOBOX_U))+2.5,Math.round(ALGOBOX_HY(ALGOBOX_V))+2.5);
  ALGOBOX_contexte_repere.stroke();
  }
else
  {
  ALGOBOX_contexte.moveTo(Math.round(ALGOBOX_HX(ALGOBOX_X))+2,Math.round(ALGOBOX_HY(ALGOBOX_Y))+2);
  ALGOBOX_contexte.lineTo(Math.round(ALGOBOX_HX(ALGOBOX_U))+2,Math.round(ALGOBOX_HY(ALGOBOX_V))+2);
  ALGOBOX_contexte.stroke();
  }
}
}

function ALGOBOX_GRADUERY(ALGOBOX_originex,ALGOBOX_originey)
{
var ALGOBOX_temp=(ALGOBOX_originey-ALGOBOX_Ymin)/ALGOBOX_grady;
var ALGOBOX_yd=(ALGOBOX_temp-parseInt(ALGOBOX_temp))*ALGOBOX_grady+ALGOBOX_Ymin;
do
	{
	ALGOBOX_DESSINE(ALGOBOX_Xmin,ALGOBOX_yd,ALGOBOX_Xmax,ALGOBOX_yd,0);
	//ALGOBOX_DESSINE(ALGOBOX_originex,ALGOBOX_yd,ALGOBOX_originex+ALGOBOX_IHX(0.01*(ALGOBOX_x2-ALGOBOX_x1)),ALGOBOX_yd,0);
	ALGOBOX_yd=ALGOBOX_yd+ALGOBOX_grady;
	}
while (ALGOBOX_yd<=ALGOBOX_Ymax);
}

function ALGOBOX_GRADUERX(ALGOBOX_originex,ALGOBOX_originey)
{
var ALGOBOX_temp=(ALGOBOX_originex-ALGOBOX_Xmin)/ALGOBOX_gradx;
var ALGOBOX_xd=(ALGOBOX_temp-parseInt(ALGOBOX_temp))*ALGOBOX_gradx+ALGOBOX_Xmin;
do
	{
	ALGOBOX_DESSINE(ALGOBOX_xd,ALGOBOX_Ymin,ALGOBOX_xd,ALGOBOX_Ymax,0);
	//ALGOBOX_DESSINE(ALGOBOX_xd,ALGOBOX_originey,ALGOBOX_xd,ALGOBOX_originey-ALGOBOX_IHY(0.01*(ALGOBOX_y2-ALGOBOX_y1)),0);
	ALGOBOX_xd=ALGOBOX_xd+ALGOBOX_gradx;
	}
while (ALGOBOX_xd<=ALGOBOX_Xmax);
}

function ALGOBOX_GRADUATION()
{
if (ALGOBOX_Xmin*ALGOBOX_Xmax<=0) ALGOBOX_originex=0;
else ALGOBOX_originex=ALGOBOX_Xmin;
if (ALGOBOX_Ymin*ALGOBOX_Ymax<=0) ALGOBOX_originey=0;
else ALGOBOX_originey=ALGOBOX_Ymin;
ALGOBOX_GRADUERX(ALGOBOX_originex,ALGOBOX_originey);
ALGOBOX_GRADUERY(ALGOBOX_originex,ALGOBOX_originey);
}

function ALGOBOX_CODAGE_POINT(ALGOBOX_x,ALGOBOX_y)
{
var tableau=new Array(4);
if (ALGOBOX_x<ALGOBOX_Xmin) tableau[0]=1;
else tableau[0]=0;
if (ALGOBOX_x>ALGOBOX_Xmax) tableau[1]=1;
else tableau[1]=0;
if (ALGOBOX_y<ALGOBOX_Ymin) tableau[2]=1;
else tableau[2]=0;
if (ALGOBOX_y>ALGOBOX_Ymax) tableau[3]=1;
else tableau[3]=0;
return tableau;
}

function ALGOBOX_INTER(ALGOBOX_code1,ALGOBOX_code2)
{
var ALGOBOX_s=0;
for (ALGOBOX_ind=0;ALGOBOX_ind<=3;ALGOBOX_ind++) 
	{
	ALGOBOX_s=ALGOBOX_s+ALGOBOX_code1[ALGOBOX_ind]*ALGOBOX_code2[ALGOBOX_ind];
	}
return ALGOBOX_s;
}

function ALGOBOX_DEDANS(ALGOBOX_c)
{
var ALGOBOX_result=true;
for (ALGOBOX_ind=0;ALGOBOX_ind<=3;ALGOBOX_ind++) 
	{
	if (ALGOBOX_c[ALGOBOX_ind]==1) ALGOBOX_result=false;
	}
return ALGOBOX_result;
}

function ALGOBOX_POINT(ALGOBOX_xd,ALGOBOX_yd,ALGOBOX_coul)
{
if (navigator.appName=="Microsoft Internet Explorer") return;
var ALGOBOX_code=ALGOBOX_CODAGE_POINT(ALGOBOX_xd,ALGOBOX_yd);
if (ALGOBOX_DEDANS(ALGOBOX_code))
    {
    if (ALGOBOX_coul==9)
      {
      ALGOBOX_contexte.globalCompositeOperation = "destination-out";
      ALGOBOX_contexte.beginPath();
      ALGOBOX_contexte.fillStyle="rgba(0,0,0,1)";
      ALGOBOX_contexte.arc(ALGOBOX_HX(ALGOBOX_xd)+2,ALGOBOX_HY(ALGOBOX_yd)+2, #POINTWIDTH#, 0, Math.PI*2, true);
      ALGOBOX_contexte.closePath();
      ALGOBOX_contexte.fill();
      ALGOBOX_contexte.globalCompositeOperation = "source-over";
      }
    else
    {
	if (ALGOBOX_coul==0) ALGOBOX_contexte_repere.beginPath();
	else ALGOBOX_contexte.beginPath();
	switch (ALGOBOX_coul)
	{
	case 0:
	ALGOBOX_contexte_repere.fillStyle="gray";
	break;
	case 1:
	ALGOBOX_contexte.fillStyle="black";
	break;
	case 2:
	ALGOBOX_contexte.fillStyle="#4040FF";
	break;
	case 3:
	ALGOBOX_contexte.fillStyle="#FF420E";
	break;
	case 4:
	ALGOBOX_contexte.fillStyle="#00CC00";
	break;
	}
	if (ALGOBOX_coul==0)
	{
	ALGOBOX_contexte_repere.arc(ALGOBOX_HX(ALGOBOX_xd)+2,ALGOBOX_HY(ALGOBOX_yd)+2, 2, 0, Math.PI*2, true);
	ALGOBOX_contexte_repere.closePath();
	ALGOBOX_contexte_repere.fill();    
	}
	else
	{
	ALGOBOX_contexte.arc(ALGOBOX_HX(ALGOBOX_xd)+2,ALGOBOX_HY(ALGOBOX_yd)+2,#POINTWIDTH#, 0, Math.PI*2, true);
	ALGOBOX_contexte.closePath();
	ALGOBOX_contexte.fill();
	}
    }
    }
}

function ALGOBOX_EFFACE_GRAPHIQUE()
{
ALGOBOX_contexte.clearRect(0, 0, ALGOBOX_canevas.width,ALGOBOX_canevas.height);
}

function ALGOBOX_TRAIT(ALGOBOX_xd,ALGOBOX_yd,ALGOBOX_xf,ALGOBOX_yf,ALGOBOX_coul)
{
var ALGOBOX_xdd=ALGOBOX_xd;
var ALGOBOX_ydd=ALGOBOX_yd;
var ALGOBOX_xff=ALGOBOX_xf;
var ALGOBOX_yff=ALGOBOX_yf;
var ALGOBOX_coded=ALGOBOX_CODAGE_POINT(ALGOBOX_xdd,ALGOBOX_ydd);
var ALGOBOX_codef=ALGOBOX_CODAGE_POINT(ALGOBOX_xff,ALGOBOX_yff);
if (ALGOBOX_DEDANS(ALGOBOX_coded) && ALGOBOX_DEDANS(ALGOBOX_codef)) ALGOBOX_DESSINE(ALGOBOX_xdd,ALGOBOX_ydd,ALGOBOX_xff,ALGOBOX_yff,ALGOBOX_coul);
else
{
	if (ALGOBOX_INTER(ALGOBOX_coded,ALGOBOX_codef)==0)
	{
		do
		{
			ALGOBOX_dx=(ALGOBOX_xff-ALGOBOX_xdd);
			ALGOBOX_dy=(ALGOBOX_yff-ALGOBOX_ydd);
			if (ALGOBOX_coded[0]==1)
					{
					ALGOBOX_ydd=ALGOBOX_ydd+(ALGOBOX_Xmin-ALGOBOX_xdd)*ALGOBOX_dy/ALGOBOX_dx;
					ALGOBOX_xdd=ALGOBOX_Xmin;
					}
			else if (ALGOBOX_coded[1]==1)
					{
					ALGOBOX_ydd=ALGOBOX_ydd+(ALGOBOX_Xmax-ALGOBOX_xdd)*ALGOBOX_dy/ALGOBOX_dx;
					ALGOBOX_xdd=ALGOBOX_Xmax;
					}
				else if (ALGOBOX_coded[2]==1)
						{
						ALGOBOX_xdd=ALGOBOX_xdd+(ALGOBOX_Ymin-ALGOBOX_ydd)*ALGOBOX_dx/ALGOBOX_dy;
						ALGOBOX_ydd=ALGOBOX_Ymin;
						}
					else if (ALGOBOX_coded[3]==1)
							{
							ALGOBOX_xdd=ALGOBOX_xdd+(ALGOBOX_Ymax-ALGOBOX_ydd)*ALGOBOX_dx/ALGOBOX_dy;
							ALGOBOX_ydd=ALGOBOX_Ymax;
							}
			ALGOBOX_coded=ALGOBOX_CODAGE_POINT(ALGOBOX_xdd,ALGOBOX_ydd);
		}
		while (!ALGOBOX_DEDANS(ALGOBOX_coded));
		do
		{
			ALGOBOX_dx=(ALGOBOX_xff-ALGOBOX_xdd);
			ALGOBOX_dy=(ALGOBOX_yff-ALGOBOX_ydd);
			if (ALGOBOX_codef[0]==1)
					{
					ALGOBOX_yff=ALGOBOX_ydd+(ALGOBOX_Xmin-ALGOBOX_xdd)*ALGOBOX_dy/ALGOBOX_dx;
					ALGOBOX_xff=ALGOBOX_Xmin;
					}
			else if (ALGOBOX_codef[1]==1)
					{
					ALGOBOX_yff=ALGOBOX_ydd+(ALGOBOX_Xmax-ALGOBOX_xdd)*ALGOBOX_dy/ALGOBOX_dx;
					ALGOBOX_xff=ALGOBOX_Xmax;
					}
				else if (ALGOBOX_codef[2]==1)
						{
						ALGOBOX_xff=ALGOBOX_xdd+(ALGOBOX_Ymin-ALGOBOX_ydd)*ALGOBOX_dx/ALGOBOX_dy;
						ALGOBOX_yff=ALGOBOX_Ymin;
						}
					else if (ALGOBOX_codef[3]==1)
							{
							ALGOBOX_xff=ALGOBOX_xdd+(ALGOBOX_Ymax-ALGOBOX_ydd)*ALGOBOX_dx/ALGOBOX_dy;
							ALGOBOX_yff=ALGOBOX_Ymax;
							}
			ALGOBOX_codef=ALGOBOX_CODAGE_POINT(ALGOBOX_xff,ALGOBOX_yff);
		}
		while (!ALGOBOX_DEDANS(ALGOBOX_codef));
		ALGOBOX_DESSINE(ALGOBOX_xdd,ALGOBOX_ydd,ALGOBOX_xff,ALGOBOX_yff,ALGOBOX_coul);
	}
}
}
function ALGOBOX_REPERE(xmin,xmax,ymin,ymax,gradx,grady)
{
ALGOBOX_Xmin=xmin;
ALGOBOX_Xmax=xmax;
ALGOBOX_Ymin=ymin;
ALGOBOX_Ymax=ymax;
ALGOBOX_gradx=gradx;
ALGOBOX_grady=grady;
var output_legende=document.getElementById("legende");
while (output_legende.firstChild) 
  {
  output_legende.removeChild(output_legende.firstChild);
  }
if (navigator.appName=="Microsoft Internet Explorer")
    {
    output_legende.appendChild(document.createTextNode("Votre navigateur ne permet pas l'affichage des graphiques : utilisez AlgoBox ou un navigateur autre qu'internet explorer."));
    return;
    }
if ((ALGOBOX_Xmin>=ALGOBOX_Xmax) || (ALGOBOX_Ymin>=ALGOBOX_Ymax))
    {
    ALGOBOX_Xmin=-10;
    ALGOBOX_Xmax=10;
    ALGOBOX_Ymin=-10;
    ALGOBOX_Ymax=10;
    }
if (ALGOBOX_gradx<=0) ALGOBOX_gradx=1;
if (ALGOBOX_grady<=0) ALGOBOX_grady=1;
if ((ALGOBOX_Xmax-ALGOBOX_Xmin)/ALGOBOX_gradx>45) ALGOBOX_gradx=Math.round((ALGOBOX_Xmax-ALGOBOX_Xmin)/45);
if ((ALGOBOX_Ymax-ALGOBOX_Ymin)/ALGOBOX_grady>45) ALGOBOX_grady=Math.round((ALGOBOX_Ymax-ALGOBOX_Ymin)/45); 
ALGOBOX_GRADUATION();
ALGOBOX_contexte_repere.strokeStyle="black";
ALGOBOX_contexte_repere.strokeRect(ALGOBOX_x1+2,ALGOBOX_y1+2,ALGOBOX_x2-ALGOBOX_x1,ALGOBOX_y2-ALGOBOX_y1);
if (ALGOBOX_Xmin*ALGOBOX_Xmax<=0) ALGOBOX_AXEX();
if (ALGOBOX_Ymin*ALGOBOX_Ymax<=0) ALGOBOX_AXEY();
output_legende.appendChild(document.createTextNode("Xmin: "+ALGOBOX_FORMAT_TEXTE(ALGOBOX_Xmin)+" ; Xmax: "+ALGOBOX_FORMAT_TEXTE(ALGOBOX_Xmax)));
output_legende.appendChild(document.createElement("br"));
output_legende.appendChild(document.createTextNode("Ymin: "+ALGOBOX_FORMAT_TEXTE(ALGOBOX_Ymin)+" ; Ymax: "+ALGOBOX_FORMAT_TEXTE(ALGOBOX_Ymax)));
output_legende.appendChild(document.createElement("br"));
output_legende.appendChild(document.createTextNode("GradX: "+ALGOBOX_FORMAT_TEXTE(ALGOBOX_gradx)+" ; GradY: "+ALGOBOX_FORMAT_TEXTE(ALGOBOX_grady)));
ALGOBOX_REPERE_DEFINI=true;
}

function ALGOBOX_AJOUTE_RESULTAT(texte)
{
var output=document.getElementById("output");
var ligne=document.createElement("pre");
ligne.appendChild(document.createTextNode(texte));
output.appendChild(ligne);
}

function ALGOBOX_INIT_VARIABLES()
{
ALGOBOX_COMPTEUR_AFFICHAGE=0;
ALGOBOX_COMPTEUR_ETAPE=0;
ALGOBOX_DEPASSEMENT_AFFICHAGE=false;
ALGOBOX_EMERGENCY_STOP=false;
#INIT_VARIABLES#
}

function ALGOBOX_EFFACE_OUTPUT()
{
var output=document.getElementById("output");
while (output.firstChild) 
  {
  output.removeChild(output.firstChild);
  }
browserDialog.scriptEffacer();
}

function ALGOBOX_PING_OUTPUT()
{
browserDialog.scriptAfficher("",false);
}

function ALGOBOX_AJOUTE_OUTPUT(texte,nl)
{
ALGOBOX_COMPTEUR_AFFICHAGE++;
if (ALGOBOX_COMPTEUR_AFFICHAGE>=#MAX_AFFICHAGES#)
  {
  if (confirm("L'algorithme demande d'afficher un très grand nombre de données.\nSouhaitez-vous arrêter l'algorithme?")) ALGOBOX_DEPASSEMENT_AFFICHAGE=true;
  else 
	{
	browserDialog.scriptAfficher(texte,nl);
	}
	ALGOBOX_COMPTEUR_AFFICHAGE=0;
  }
else browserDialog.scriptAfficher(texte,nl);
}

function ALGOBOX_AFFICHE_PASAPAS(texte,nl)
{
browserDialog.scriptAfficherVariables(texte,nl);
}

function ALGOBOX_AFFICHE_ETAT_VARIABLES(ALGOBOX_ID_LIGNE)
{
ALGOBOX_COMPTEUR_ETAPE++;
ALGOBOX_AFFICHE_PASAPAS("#"+ALGOBOX_COMPTEUR_ETAPE+" Nombres/chaines (ligne "+ALGOBOX_ID_LIGNE+") -> ",false);
#AFFICHE_VARIABLES#
ALGOBOX_AFFICHE_PASAPAS(" ",true);
}

function ALGOBOX_PAUSE()
{
ALGOBOX_AJOUTE_OUTPUT(" ",true);
ALGOBOX_AJOUTE_OUTPUT("***Pause***",true);
browserDialog.scriptDebutPause();
var reponse=confirm("Pause");
browserDialog.scriptFinPause();
return reponse;
}

function ALGOBOX_ACTIVER_LIGNE(ALGOBOX_ID_LIGNE)
{
var ligne_source=document.getElementById("ligne"+ALGOBOX_ID_LIGNE);
ligne_source.style.background="rgba(255, 255, 0, 0.6)";
}

function ALGOBOX_DESACTIVER_LIGNE(ALGOBOX_ID_LIGNE)
{
var ligne_source=document.getElementById("ligne"+ALGOBOX_ID_LIGNE);
ligne_source.style.background="#f9f9f9";
}

function ALGOBOX_PAUSE_PAS_A_PAS(ALGOBOX_ID_LIGNE)
{
window.location.href = "#"+ALGOBOX_ID_LIGNE;
ALGOBOX_ACTIVER_LIGNE(ALGOBOX_ID_LIGNE);
ALGOBOX_AFFICHE_ETAT_VARIABLES(ALGOBOX_ID_LIGNE);
browserDialog.scriptDebutPause();
var rep=confirm("Pause");
browserDialog.scriptFinPause();
ALGOBOX_DESACTIVER_LIGNE(ALGOBOX_ID_LIGNE)
return rep;
}

function ALGOBOX_INFO_PAS_A_PAS(ALGOBOX_ID_LIGNE,ALGOBOX_INFO)
{
window.location.href = "#"+ALGOBOX_ID_LIGNE;
ALGOBOX_ACTIVER_LIGNE(ALGOBOX_ID_LIGNE);
ALGOBOX_AFFICHE_PASAPAS(ALGOBOX_INFO+" (ligne "+ALGOBOX_ID_LIGNE+")",true);
browserDialog.scriptDebutPause();
var rep=confirm("Pause");
browserDialog.scriptFinPause();
ALGOBOX_DESACTIVER_LIGNE(ALGOBOX_ID_LIGNE)
return rep;
}

// Code Algorithme :
#JAVASCRIPT#
</script>
</head>
<body>
<div align="center" style="margin:10px;"><span class="header">#TITRE#</span></div>
#DESCRIPTION#

<div class="post" id="contentgraphic" style="visibility : hidden;">
#GRAPHIQUE#
</div>

<div class="post">
<fieldset>
<legend class="title">Code de l'algorithme</legend>
<div class="code">
#CODE#
</div>
<br clear="all">
</fieldset>
</div>

<div class="post" >
<fieldset style="width: 760px; height: 260px;">
<legend class="title">Résultats</legend>
<div style="width: 700px; height: 200px;" class="output" id="output" >
</div>
<br clear="all">
</fieldset>
</div>

<div id="footer">Généré par AlgoBox</div>
</body>
</html>