-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation-v4-1.html
975 lines (841 loc) · 26.9 KB
/
animation-v4-1.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
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
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css" media="screen">
/* #myCanvas1 { background:url(http://www.frontiersin.org/files/Articles/39500/fphys-04-00033-HTML/image_m/fphys-04-00033-g002.jpg);
background-size: 578px 210px;
background-repeat: no-repeat;
}*/
body {
margin: 0px;
padding: 0px;
}
#tabela {
border-collapse: collapse;
border: 1px solid black;
}
#tabela td {
border: 1px solid black;
}
</style>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script>
var i =0;
var b;
var mmm=9999999999;
var rv = 0;
var hop = 30;
var current_hop = 30;
var signal = 0;
var xacc =[];
var current_ball;
var start_dif = false;
var ditch =false;
var runAnimation = false;
var canvas;
var canvas1;
var balls;
var im;
var rec;
var recRed;
var array;
var half;
var recvel;
var x = 0;
var xx = 0;
var trace1 = {
x: [],
y: [],
type: 'scatter'
};
function stopAni()
{
i =0;
hop = 30;
x=0;
current_hop = 30;
signal = 0;
xacc =[];
current_ball;
start_dif = false;
ditch =false;
runAnimation = false;
trace1.x =[];
trace1.y =[];
lst =0;
//document.getElementById('g').disabled=false;
//document.getElementById('Del').disabled=false;
//document.getElementById('delta').disabled=false;
//document.getElementById('dv').disabled=false;
document.getElementById('start').innerHTML ="Start";
ini();
}
function ini()
{
xacc =[];
initBalls();
var canvas = document.getElementById('myCanvas');
var canvas1 = document.getElementById('myCanvas1');
var context = canvas.getContext('2d');
var context1 = canvas1.getContext('2d');
img = document.getElementById("img");
im = new ImObj(-31,img);
// clear
context.clearRect(0, 0, canvas.width, canvas.height);
context1.clearRect(0, 0, canvas1.width, canvas1.height);
var g = document.getElementById("g").value*1;
var gg = g;
g = g*(1/3);
var delta = document.getElementById("delta").value*1;
var dd = delta;
delta = delta*(10/4);
var D = document.getElementById("Del").value*1;
var DD = D;
D = D*(15/4);
var dv = document.getElementById("dv").value*1;
changeB();
hop=30-dv;
current_hop = hop;
//context.drawImage(im.img,-30, 580, 200, 40);
//
//context1.drawImage(seq,0,0,578,210);
context1.fillRect(40, 30, 5, 40); // excitation pulse
// render
context1.fillRect(250, 0, 5, 70); // inversion pulse
//context1.fillRect(460, 60, 5, 10); // readout
//context1.fillRect(145-(delta/2), 180-g, delta, g); // first gradient
//context1.fillRect(260 + (D*1), 180-g, delta, g); // second gradient
context1.fillRect((250-(D/2+(delta*1))), 180-g, delta, g); // first gradient
context1.fillRect(((255+D/2)), 180-g, delta, g); // second gradient
context1.beginPath();
context1.moveTo(0, 70);
context1.lineTo(canvas.width, 70);
context1.stroke();
context1.beginPath();
context1.moveTo(0, 180);
context1.lineTo(canvas.width, 180);
context1.stroke();
context1.font = "15px Arial";
context1.fillText("A",40,210);
context1.fillText("B",(250-(D/2+(delta*1))),210);
context1.fillText("C",(250-(D/2+(delta*1)))+ delta,210);
context1.fillText("D",255,210);
context1.fillText("E",((255+D/2)),210);
context1.fillText("F",((255+D/2)) + delta,210);
context.globalAlpha = 0.5;
context.fillStyle = 'red';
context.fillRect(70,0,2,620);
context.globalAlpha = 1;
//
//context1.drawImage(seq,0,0,578,210);
// render
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
context.beginPath();
context.arc(ball.x, ball.y, ball.radius, 0, 2 * Math.PI, false);
context.fillStyle = ball.color;
context.fill();
}
for(var j=0;j<30;j++)
{
var pos = j*20;
context.beginPath();
context.moveTo(0, pos);
context.lineTo(canvas.width, pos);
context.stroke();
}
}
function change()
{
stopAni();
document.getElementById('start').innerHTML ="Start";
var delta = document.getElementById("delta").value*1;
var D = document.getElementById("Del").value*1;
var g = document.getElementById("g").value*1;
if (delta>D){
alert("DELTA should be greater than delta");
if(delta<=40)
document.getElementById("delta").value = D;
else
document.getElementById("delta").value = 40;
return;
}
if (delta>40){
alert("The maximum value of delta can be 40");
document.getElementById("delta").value = 40;
return;
}
if (D>40){
alert("The maximum value of DELTA can be 40");
document.getElementById("Del").value = 40;
return;
}
if (g>300){
alert("The maximum value of G can be 300");
document.getElementById("g").value = 300;
return;
}
ini();
}
function poc()
{
//console.log("start");
if(i==0){
canvas = document.getElementById('myCanvas');
canvas1 = document.getElementById('myCanvas1');
//document.getElementById('g').disabled=true;
//document.getElementById('Del').disabled=true;
//document.getElementById('delta').disabled=true;
//document.getElementById('dv').disabled=true;
balls = initBalls();
rec = new Rec(10,0.5,5);
img = document.getElementById("img");
im = new ImObj(-31,img);
recRed = new Rec(70,balls[14].vx,2)
rv = xacc[14];
i +=1;
}
if(rec.x == 460 && document.getElementById('start').innerHTML == "Start")
{
stopAni();
ini();
return;
}
else runAnimation = !runAnimation;
if(runAnimation){
document.getElementById('start').innerHTML ="Pause";
var date = new Date();
var time = date.getTime();
animate(canvas, canvas1, balls, rec, recRed, im, time);
}
else{
document.getElementById('start').innerHTML ="Start";
}
}
var stop = false;
window.requestAnimFrame = (function(callback) {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
var flag = true;
function initBalls() {
//console.log("initBalls");
balls = [];
var blue = '#3A5BCD';
var red = '#EF2B36';
var yellow = '#FFC636';
var green = '#02A817';
var black = '#000000';
var g = document.getElementById("g").value;
g = (g*(1/2))/100;
//var g = document.getElementById("g").value/100;
// G
var pp = Math.floor(Math.random() * 28) + 1;
var vel;
//if(hop>20 && hop<100) vel=1;
vel = 2;
var yy = 10;
balls.push(new Ball(70, yy, 1.2, vel, g*(14/29), blue,0));
yy+=20;
xacc.push(g*(14/29));
for(var i=1;i<28;i++){
var rnd = Math.floor(Math.random() * 3) - 1;
while(rnd==0 || rnd ==2)
{
rnd = Math.floor(Math.random() * 3) - 1;
}
balls.push(new Ball(70, yy, 1.2, rnd*vel, g*((14-i)/29), blue,i));
xacc.push(g*((14-i)/29));
yy+=20;
}
balls.push(new Ball(70, yy, 1.2, -1*vel, g*((-14)/29), blue,28));
xacc.push(g*((-14)/29));
return balls;
}
function updateBalls(canvas, balls, rec, recRed, im, timeDiff) {
//console.log("updateBalls rec.x :", rec.x);
var g = document.getElementById("g").value;
g = g*(1/3);
var delta = document.getElementById("delta").value;
delta = delta*(10/4);
var D = document.getElementById("Del").value;
D = D*(15/4);
var context = canvas.getContext('2d');
if(rec.x >= 40 && rec.x < (250-(D/2+(delta*1)))){
recRed.x += recRed.vx;
im.x += recRed.vx;
if(document.getElementById("dv").valueAsNumber == 0) start_dif = false;
else start_dif=true;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
// set ball position based on velocity
if(start_dif){
if (hop - current_hop == 0)
{
do{
current_ball = Math.floor(Math.random() * 28);
}while((balls[current_ball].vy>0 && balls[current_ball].currentPos == 28) || (balls[current_ball].vy<0 && balls[current_ball].currentPos == 0))
current_hop = 0;
}
if(current_ball == n && ball.vy>0 && ball.y < (((balls[current_ball].currentPos+1)*20)+10)){
ball.y += ball.vy;
ditch = true;
}
if(current_ball == n && ball.vy<0 && ball.y > ((balls[current_ball].currentPos*20)-10)){
ball.y += ball.vy;
ditch = true;
}
if (current_ball == n && balls[n].vy>0 && balls[n].y == (((balls[current_ball].currentPos+1)*20)+10)){
balls[current_ball].currentPos+=1;
current_ball = -1
ditch = false;
}
if (current_ball == n && balls[n].vy<0 && balls[n].y == ((balls[current_ball].currentPos*20)-10)){
balls[current_ball].currentPos-=1;
current_ball = -1
ditch = false;
}
}
ball.x += ball.vx;
}
}
if(rec.x >= (250-(D/2+(delta*1))) && rec.x<(250-D/2)){
recRed.x += recRed.vx;
im.x += recRed.vx+rv;
if(document.getElementById("dv").valueAsNumber == 0) start_dif = false;
else start_dif=true;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
if(start_dif){
if (hop - current_hop == 0)
{
do{
current_ball = Math.floor(Math.random() * 28);
}while((balls[current_ball].vy>0 && balls[current_ball].currentPos == 28) || (balls[current_ball].vy<0 && balls[current_ball].currentPos == 0))
current_hop = 0;
}
if(current_ball == n && ball.vy>0 && ball.y < (((balls[current_ball].currentPos+1)*20)+10)){
ball.y += ball.vy;
ditch = true;
}
if(current_ball == n && ball.vy<0 && ball.y > ((balls[current_ball].currentPos*20)-10)){
ball.y += ball.vy;
ditch = true;
}
if (current_ball == n && balls[n].vy>0 && balls[n].y == (((balls[current_ball].currentPos+1)*20)+10)){
balls[current_ball].currentPos+=1;
current_ball = -1
ditch = false;
}
if (current_ball == n && balls[n].vy<0 && balls[n].y == ((balls[current_ball].currentPos*20)-10)){
balls[current_ball].currentPos-=1;
current_ball = -1
ditch = false;
}
}
ball.x += (ball.vx+xacc[ball.currentPos]);
}
}
if(rec.x>= (250-D/2) && rec.x<245){
if(document.getElementById("dv").valueAsNumber == 0) start_dif = false;
else start_dif=true;
recRed.x += recRed.vx;
im.x += recRed.vx;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
if(start_dif){
if (hop - current_hop == 0)
{
do{
current_ball = Math.floor(Math.random() * 28);
}while((balls[current_ball].vy>0 && balls[current_ball].currentPos == 28) || (balls[current_ball].vy<0 && balls[current_ball].currentPos == 0))
current_hop = 0;
}
if(current_ball == n && ball.vy>0 && ball.y < (((balls[current_ball].currentPos+1)*20)+10)){
ball.y += ball.vy;
ditch = true;
}
if(current_ball == n && ball.vy<0 && ball.y > ((balls[current_ball].currentPos*20)-10)){
ball.y += ball.vy;
ditch = true;
}
if (current_ball == n && balls[n].vy>0 && balls[n].y == (((balls[current_ball].currentPos+1)*20)+10)){
balls[current_ball].currentPos+=1;
current_ball = -1
ditch = false;
}
if (current_ball == n && balls[n].vy<0 && balls[n].y == ((balls[current_ball].currentPos*20)-10)){
balls[current_ball].currentPos-=1;
current_ball = -1
ditch = false;
}
}
ball.x += ball.vx;
}
}
if(rec.x >= 245 && rec.x<255){
if(document.getElementById("dv").valueAsNumber == 0) start_dif = false;
else start_dif=true;
if (rec.x == 245)
{
half = (recRed.x - 70)/2;
recvel = (recRed.x - 70)/(10*50);
x = -10;
}
if(recRed.x == half)
{
x = 10
}
if(rec.x == 250) {
recRed.vx *= -1;
}
if(recRed.x>70){
recRed.x += recRed.vx - 21;
im.x += recRed.vx - 21;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
if(rec.x == 250) {
ball.vx *= -1;
}
ball.x += ball.vx - 21;
}
}
current_hop = 0;
x+=-10;
}
if(rec.x >= 255 && rec.x<(255+D/2)){
if(document.getElementById("dv").valueAsNumber == 0) start_dif = false;
else start_dif=true;
if(rec.x == 255) {
recRed.vx *= -1;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
if(ball.x > recRed.x) ball.x = recRed.x - Math.abs(recRed.x - ball.x);
else ball.x = recRed.x + Math.abs(recRed.x - ball.x);
}
}
recRed.x += recRed.vx;
im.x += recRed.vx;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
if(rec.x == 255) {
ball.vx *= -1;
}
if(start_dif){
if (hop - current_hop == 0 && rec.x + hop <(260+(D*1)))
{
do{
current_ball = Math.floor(Math.random() * 28);
}while((balls[current_ball].vy>0 && balls[current_ball].currentPos == 28) || (balls[current_ball].vy<0 && balls[current_ball].currentPos == 0))
current_hop = 0;
}
if(current_ball == n && ball.vy>0 && ball.y < (((balls[current_ball].currentPos+1)*20)+10)){
ball.y += ball.vy;
ditch = true;
}
if(current_ball == n && ball.vy<0 && ball.y > ((balls[current_ball].currentPos*20)-10)){
ball.y += ball.vy;
ditch = true;
}
if (current_ball == n && balls[n].vy>0 && balls[n].y == (((balls[current_ball].currentPos+1)*20)+10)){
balls[current_ball].currentPos+=1;
current_ball = -1
ditch = false;
}
if (current_ball == n && balls[n].vy<0 && balls[n].y == ((balls[current_ball].currentPos*20)-10)){
balls[current_ball].currentPos-=1;
current_ball = -1
ditch = false;
}
}
ball.x += ball.vx;
}
}
if(rec.x >= (255+D/2) && rec.x <(255+((D/2)+(delta*1)))){
if(document.getElementById("dv").valueAsNumber == 0) start_dif = false;
else start_dif=true;
recRed.x += recRed.vx;
im.x += recRed.vx+rv;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
if(start_dif){
if (hop - current_hop == 0 )
{
do{
current_ball = Math.floor(Math.random() * 28);
}while((balls[current_ball].vy>0 && balls[current_ball].currentPos == 28) || (balls[current_ball].vy<0 && balls[current_ball].currentPos == 0))
current_hop = 0;
}
if(current_ball == n && ball.vy>0 && ball.y < (((balls[current_ball].currentPos+1)*20)+10)){
ball.y += ball.vy;
ditch = true;
}
if(current_ball == n && ball.vy<0 && ball.y > ((balls[current_ball].currentPos*20)-10)){
ball.y += ball.vy;
ditch = true;
}
if (current_ball == n && balls[n].vy>0 && balls[n].y == (((balls[current_ball].currentPos+1)*20)+10)){
balls[current_ball].currentPos+=1;
current_ball = -1
ditch = false;
}
if (current_ball == n && balls[n].vy<0 && balls[n].y == ((balls[current_ball].currentPos*20)-10)){
balls[current_ball].currentPos-=1;
current_ball = -1
ditch = false;
}
}
ball.x += (ball.vx+xacc[ball.currentPos]);
}
}
if(rec.x >= (255+((D/2)+(delta*1))) && rec.x<460){
recRed.x += recRed.vx;
im.x += recRed.vx;
if(document.getElementById("dv").valueAsNumber == 0) start_dif = false;
else start_dif=true;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
if(start_dif){
if (hop - current_hop == 0 && rec.x + hop <460)
{
do{
current_ball = Math.floor(Math.random() * 28);
}while((balls[current_ball].vy>0 && balls[current_ball].currentPos == 28) || (balls[current_ball].vy<0 && balls[current_ball].currentPos == 0))
current_hop = 0;
}
if(current_ball == n && ball.vy>0 && ball.y < (((balls[current_ball].currentPos+1)*20)+10)){
ball.y += ball.vy;
ditch = true;
}
if(current_ball == n && ball.vy<0 && ball.y > ((balls[current_ball].currentPos*20)-10)){
ball.y += ball.vy;
ditch = true;
}
if (current_ball == n && balls[n].vy>0 && balls[n].y == (((balls[current_ball].currentPos+1)*20)+10)){
balls[current_ball].currentPos+=1;
current_ball = -1
ditch = false;
}
if (current_ball == n && balls[n].vy<0 && balls[n].y == ((balls[current_ball].currentPos*20)-10)){
balls[current_ball].currentPos-=1;
current_ball = -1
ditch = false;
}
}
ball.x += ball.vx;
}
}
if (rec.x>=245 && rec.x<255){
if (recRed.x >half) x-=70;
else x += 70;
}
rec.x += rec.vx;
if(rec.x==460)
{
rec.vx = 0;
rec.vx =0;
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
ball.vx = 0;
if(ball.x<5) ball.x=5;
}
}
if(start_dif)
{
current_hop+= document.getElementById("dv").valueAsNumber/20;
if (hop - current_hop < document.getElementById("dv").valueAsNumber/20) current_hop = hop;
}
}
function Ball(x, y, vx, vy, tx, color, cpos) {
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.tx = tx;
this.color = color;
this.origX = x;
this.origY = y;
this.currentPos = cpos;
this.radius = 2;
}
function Rec(x, vx, line) {
this.x = x;
this.vx = vx;
this.line = line;
}
function ImObj (x, img)
{
this.img = img;
this.x = x;
}
function animate(canvas, canvas1, balls, rec, recRed, im, lastTime) {
var context = canvas.getContext('2d');
var context1 = canvas1.getContext('2d');
// update
var date = new Date();
var time = date.getTime();
var timeDiff = time - lastTime;
updateBalls(canvas, balls, rec, recRed, im, timeDiff);
lastTime = time;
// clear
context.clearRect(0, 0, canvas.width, canvas.height);
// red rectangle indicating the star position of the balls
context1.globalCompositeOperation = 'lighter';
context1.clearRect(0, 0, canvas1.width, canvas1.height);
var g = document.getElementById("g").value;
g = g*(1/3);
var delta = document.getElementById("delta").value;
delta = delta*(10/4);
var D = document.getElementById("Del").value;
D = D*(15/4);
//
//context1.drawImage(seq,0,0,578,210);
context1.fillRect(40, 30, 5, 40); // excitation pulse
context1.fillRect(250, 0, 5, 70); // inversion pulse
context1.fillRect((250-(D/2+(delta*1))), 180-g, delta, g); // first gradient
context1.fillRect(((255+D/2)), 180-g, delta, g); // second gradient
context1.beginPath();
context1.moveTo(0, 70);
context1.lineTo(canvas.width, 70);
context1.stroke();
context1.beginPath();
context1.moveTo(0, 180);
context1.lineTo(canvas.width, 180);
context1.stroke();
//
//context1.drawImage(seq,0,0,578,210);
context1.globalAlpha = 0.5;
context1.fillRect(rec.x, 0, 5, 300);
context1.globalAlpha = 1;
context1.font = "15px Arial";
context1.fillText("A",40,210);
context1.fillText("B",(250-(D/2+(delta*1))),210);
context1.fillText("C",(250-(D/2+(delta*1)))+ delta,210);
context1.fillText("D",255,210);
context1.fillText("E",((255+D/2)),210);
context1.fillText("F",((255+D/2)) + delta,210);
//context.drawImage(im.img,im.x, 580,200,40);
// render
context.beginPath();
context.moveTo(0, 0);
context.lineTo(canvas.width, 0);
context.stroke();
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
context.beginPath();
context.arc(ball.x, ball.y, ball.radius, 0, 2 * Math.PI, false);
context.fillStyle = ball.color;
context.fill();
}
context.globalAlpha = 0.5;
context.fillStyle = 'red';
context.fillRect(recRed.x,0,2,590);
context.globalAlpha = 1;
if (rec.x >= 245 && rec.x <255)
{
for(var j=0;j<30;j++)
{
pos=j*20;
context.beginPath();
context.moveTo(-x, pos);
context.lineTo(canvas.width + x, pos);
context.stroke();
}
}
else {
for(var j=0;j<30;j++)
{
pos=j*20;
if(ditch && j == balls[current_ball].currentPos && balls[current_ball].vy<0)
{
context.beginPath();
context.moveTo(0, pos);
context.lineTo(balls[current_ball].x - balls[current_ball].radius , pos);
context.stroke();
context.beginPath();
context.moveTo(balls[current_ball].x + 5, pos);
context.lineTo(canvas.width, pos);
context.stroke();
}
else if(ditch && j == balls[current_ball].currentPos +1 && balls[current_ball].vy>0)
{
context.beginPath();
context.moveTo(0, pos);
context.lineTo(balls[current_ball].x - balls[current_ball].radius , pos);
context.stroke();
context.beginPath();
context.moveTo(balls[current_ball].x + 5, pos);
context.lineTo(canvas.width, pos);
context.stroke();
}
else{
context.beginPath();
context.moveTo(0, pos);
context.lineTo(canvas.width, pos);
context.stroke();
}
}
}
/* for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
if(ball.x<recRed.x){
//console.log("ball[" + n + "].x = " + balls[n].x + "\n");
signal += Math.cos(((ball.x-recRed.x)/60)*Math.PI);
}
else signal += Math.cos(((ball.x-recRed.x)/60)*Math.PI);
}
signal = signal/29;
var p1 = Math.abs(signal-0.5);
var p2 = p1*0.99;
var p3 = p2 /0.5;
var p4 = p3+0.01;
console.log("min: ", mmm, " r.x: ", recRed.x);
var lst=trace1.x.length;
trace1.x.push(lst);
trace1.y.push(p4);
signal = 0;
lst+=1;*/
if (rec.x==460)
{
runAnimation = false;
document.getElementById('start').innerHTML ="Start";
for(var n = 0; n < balls.length; n++) {
var ball = balls[n];
//if(ball.x<recRed.x){
//console.log("ball[" + n + "].x = " + balls[n].x + "\n");
//signal += Math.abs(Math.cos(((ball.x-(recRed.x-100))/100)*Math.PI));
signal += Math.abs(ball.x-recRed.x)
//}
//else signal += Math.abs(Math.cos(((ball.x-recRed.x)/100)*Math.PI));
}
signal = Math.sqrt(signal);
var p1 = Math.abs(signal-0.5);
var p2 = p1*0.99;
var p3 = p2 /0.5;
var p4 = p3+0.01;
console.log("min: ", mmm, " r.x: ", recRed.x);
var lst=trace1.x.length;
trace1.x.push(lst);
trace1.y.push(1-(signal*0.99)/22.31);
if(document.getElementById('start').innerHTML == "Start"){
var tb = document.getElementById('tabela');
var row = tb.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = b.toFixed(2);
var za = document.getElementById('dv').valueAsNumber/20;
cell2.innerHTML = za.toFixed(2);
cell3.innerHTML = trace1.y[trace1.y.length-1].toFixed(2);
console.log("b: ", b.toFixed(2));
}
signal = 0;
}
// request new frame
if(runAnimation){requestAnimFrame(function() {
animate(canvas, canvas1, balls, rec, recRed, im, lastTime);
});
}
}
/*
* set mouse position really far away
* so the mouse forces are nearly obsolete
*/
// add click listener to canvas
if(runAnimation) {
var date = new Date();
var time = date.getTime();
animate(canvas, canvas1, balls, rec, recRed, im, time);
}
//animate(canvas, canvas1, balls, rec, time);
function ses()
{
window.location.replace("animation-v4-1.html");
}
function gre()
{
window.location.replace("animation-v4-2-GRE.html");
}
</script>
</head>
<body onload="ini()">
<table>
<tr>
<td>
<canvas id="myCanvas" width="760" height="900"></canvas>
</td>
<td style="vertical-align: top;">
<div style="margin-left:40px">
<canvas id="myCanvas1" width="540" height="220"></canvas>
<br/>
<center>
<button onclick="ses()">Spin Echo Sequence [SE]</button>
<button onclick="gre()">Gradient Echo Sequence [GRE]</button>
</center>
<br/>
<label style="font-size:24px"><b>G</b></label> <input type="range" id="g" onchange="change()" max="300" value="300" min="0" style="width:50px"> <label><i> </i></label>
<label style="font-size:24px"><b>Δ</b></label> <input type="range" id="Del" onchange="change()" value="40" max="40" min="0" style="width:50px"> <label><i> </i></label>
<label style="font-size:24px"><b>δ</b></label> <input type="range" id="delta" onchange="change()" max="40" value="40" min="0" style="width:50px"> <label><i> </i></label>
<br/> <br/>
<label style="font-size:18px">diffusion coefficient</label> <input type="range" id="dv" onchange="change()" max="20" min="0" value="0" style="width:50px">
<script>
function changeB(){
var g = document.getElementById("g").value*1.0;
var dv = document.getElementById("dv").value;
var delta = document.getElementById("delta").value*1.0;
var D = document.getElementById("Del").value*1.0;
if (g == 0) b = 0;
else
{
var p1 = 2*Math.PI*42.58*g;
var p2 = delta/1000;
var p3 = p1*p2;
var p4 = p3*p3
var p5 = delta/3;
var p6 = D-p5;
var p7 = p6/1000;
b = p4*p7;
b = b/274854.1351658991;
console.log("b= " , b);
}
}
</script>
<button id="start" onclick="poc()">Start</button>
<br/>
<img src="oska.png" id="img" style="display: none;" />
</div>
<br/>
<br/>
<center><table id="tabela" style="text-align: center; border: 1">
<tr><td style="padding-left:5px;padding-right: 5px;">Relative b-value</td><td style="padding-left:5px;padding-right: 5px;">Relative diffusion coefficient</td><td style="padding-left:5px;padding-right: 5px;">Relative signal</td></tr>
</table>
</center>
<script>
var trace2 = {
x: [1, 2, 3, 4],
y: [16, 5, 11, 9],
type: 'scatter'
};
var data = [trace1];
function draw()
{
var layout = {
xaxis: {
title: 'Time',
showgrid: true,
},
yaxis: {
title: 'Signal',
showline: true,
}
};
Plotly.newPlot('myDiv', data,layout);
}
</script>
</td>
</tr>
</table>
</body>
</html>