-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1019 lines (832 loc) · 48 KB
/
index.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
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
<html lang="en">
<!-- February 5, 2021
based on the novel by: Wilma Bainbridge osf.io/tgavx
revised by: Shuyao Wang
revised again by: John D. Patterson
SEE THIS REPO FOR HOSTING OFF GITHUB, AND GETTING AWAY FROM PAVLOVIA:https://github.com/brianspiering/online-psychology-experiment/blob/master/response.php
code attempts to create for loop of experiment, where each trial participant draws an image from a starting cue
Also note that this code relies heavily on open source Javascript plugin wPaint.
You can learn more about it here: https://github.com/websanova/wPaint
/-->
<head>
<meta charset="utf-8"/>
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />
<title>Drawing</title>
<link
href="wpaint/lib/jquery-ui.css"
rel="stylesheet"
/>
<!--- Let's put some CSS in here to make our buttons bigger and prettier -->
<style>
.animbutton {
background-color: #f2f2f2;
font-size: 40px;
border: 3px solid #000000;
}
.animbutton:hover {
background-color: #cccccc;
}
.animbutton:active {
background-color: #cccccc;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
</style>
</head>
<body>
<form method="post" autocomplete="off">
<div id="root"></div>
<!--- HTML Code -->
<!-- Here is all the code that defines the HTML appearance of the page! -->
<!-- Put the buttons that start the experiment and progress through the different trials. This will also save the drawings when done drawing. Different buttons will be visible at different points in the experiment.-->
<div style="text-align:center">
<span id="welcome" style="font-family:helvetica;font-size:40px;">
<!--<br><br><br>-->
<br>
<b>Welcome to the experiment!</b>
</span>
<!--<span id="instructionsNoDraw" style="font-family:helvetica;font-size:20px;" hidden>
<b>Nothing to draw!<br />
<b>Click to advance to see the next image. <br/>
<br />
</span>-->
<!--commenting out ends here-->
<input type="button" name="start" id="startpr" value="Start" class="animbutton" hidden/>
<input type="button" name="start" id="startexp" value="Start" class="animbutton" hidden/>
<input type="button" name="practiceButton" id="practiceSubmit" value="Submit" class="animbutton" hidden/>
<input type="button" name="submitDrawing" id="drawSubmit" value="Submit" class="animbutton" hidden />
<input type="button" name="EndExperiment" id="submitButton" value="Submit" class="animbutton" hidden />
<!-- can probably comment out staring here-->
<input type="button" name="pre_next_pillows" id="pre_nextbutton1" value="Circle location of any pillows" class="animbutton" hidden />
<input type="button" name="pre_next_wallArt" id="pre_nextbutton2" value="Circle location of any wall art" class="animbutton" hidden />
<input type="button" name="nextTrial" id="nextTrialButton" value="Next image" class="animbutton" hidden />
<input type="button" name="draw_surp" id="draw_surpbutton" value="Surprise! Draw the whole room" class="animbutton" style = "color: red" hidden />
<!-- commenting out ends here-->
</div>
<!-- Code for where to put the drawing interface-->
<div style="text-align: center">
<!-- Practice drawing instructions-->
<div style="text-align: left">
<!-- These are the instructions: edit to describe the drawing task you will implement-->
<span id="instructionsPractice" style="font-family:helvetica;font-size:20px;" hidden>
<!--<br><br><br>-->
<br>
<b>Drawing Instruction</b> <br />
<br />
In the experiment, you will be presented with 1 incomplete image each time. <br />
<br />
Please complete the images by filling in the occluded portions with line drawings using your mouse or touch screen. <br />
<br />
Remember to give a quick, intuitive judgement, without thinking too much about it. <br />
<br />
Press START to begin. </b> <br />
</span>
</div>
<!-- If no text will appear alongside creativity drawing canvas, this can be commented out-->
<!-- <span id="instructionsSurprise" style="font-family:helvetica;font-size:20px;" hidden>
<b>Draw a picture of the whole room you just saw!</b>
<b>Highly accurate AND detailed drawings of the whole room may earn bonus credit on SONA. </b>
<br />
</span>-->
<!-- commenting out ends here-->
<!-- can probably comment out staring here-->
<!--<span id="imagedisplay" style="position:relative">This is where other experimental info will display-->
<!--</span>-->
<!-- commenting out ends here-->
<span id="drawingdisplay" hidden>
<br />
<b>Please complete the images using the paint tools on the left. </b> <br />
<br />
<b>You are only allowed to use BLACK pen for drawing. </b> <br />
<br />
<b>Press SUBMIT button to submit your drawing each time. </b> <br />
<div id="wPain" style="position:relative; width:500px; height:500px; margin:50px auto 0 auto; border-style:solid; border-color:#000000; border-width:3px"></div>
<!-- <img id="canvasImage" src=""/>-->
</span>
<script>
function setClicking() {
console.log("Oye");
clicking = true;
}
</script>
<script type="importmap">
{ "imports": {
"vue": "https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.41/vue.esm-browser.prod.js",
"vue-router": "https://cdnjs.cloudflare.com/ajax/libs/vue-router/4.1.5/vue-router.esm-browser.min.js"
} }
</script>
<!-- Consent Form-->
<!--<div style="text-align:center">
<span id="consentP" style="font-family:helvetica;font-size:25px;">
<br>
<b>Consent for Exempt Research: The Pennsylvania State University</b> <br />
<!-- You are being invited to volunteer to participate in a research study. This summary explains information about this research. Before beginning the experiment, please read the consent form carefully and indicate whether or not you agree to participate in this study. <br />
<br /> -->
<div style="text-align: left">
<span id="consentP" style="font-family:helvetica;font-size:25px;">
<!--<br><br><br>-->
<br>
<u>Consent for Exempt Research: The Pennsylvania State University</u> <br />
<br />
Title of Project: <b>Drawing Creativity Experiment</b> <br />
<br />
Principal Investigator: <b>Roger E. Beaty, PhD</b> <br />
<br />
Telephone Number: 814-863-8524 <br />
<br />
Email: [email protected] <br />
<br />
You are being invited to volunteer to participate in a research study. This summary explains information about this research:</strong> <br />
<ul>
<li>The purpose of this study is to examine people's creativity of drawing.</li>
<li>If you agree to participate in this research, you will be asked to complete electronically administered tasks. In general, these tasks will ask you to draw whether you come up with in mind based on some incomleted images.</li>
<li>Every effort will be made to maintain your confidentiality and anonymity to the degree permitted by the technology used. However, no guarantees can be made regarding the interception of data sent via the Internet by any third parties.</li>
<li>De-identified experimental data will be stored by our lab for a minimum of 3 years on password-protected computers and/or a secure server.</li>
<li>Information collected in this project may be shared with other researchers, but we will not share any information that could identify you directly.</li>
</ul>
If you have questions or concerns, including about the withdrawal of consent or data, you should contact the Principal Investigator, Dr. Roger Beaty. If you have questions regarding your rights as a research subject or concerns regarding your privacy, you may contact the Penn State University Office for Research Protections at 814-865-1775. <br />
<br />
Your participation is voluntary, and you may decide to stop at any time. You do not have to answer any questions that you do not wish to answer. <br />
<br />
<b>Please sign in the below button and click “Accept” if you understand the information presented above and consent to participate in our study.</b> <br />
<br />
<input type="text" name="name" id = "name"/>
<input type="button" name="accept" id="acceptConsent" value="Accept" class="animbutton" />
</span>
</div>
<div style="text-align: left">
<!-- These are the instructions: edit to describe the drawing task you will implement -->
<span id="instructionsW" style="font-family:helvetica;font-size:25px;" hidden>
<!--<br><br><br>-->
<br>
<b>Drawing Instruction</b> <br />
<br />
Okay, now you are ready to get started with the main task. <br />
<br />
You will complete 13 rounds of the task. Each round will have 1 incomplete image. <br />
<br />
Please complete the images by filling in the occluded portions with line drawings using your mouse or touch screen. <br />
<br />
Remember to give a quick, intuitive judgement, without thinking too much about it. <br />
<br />
Press START to begin. </b> <br />
</span>
</div>
<!-- These are hidden tags that save the drawings when they're done. Need to make 10 -->
<input type="hidden" name="practicedrawing1" id="pDrawId" value="" />
<!-- <input type="text" id="canvasImageData" />-->
<input type="hidden" name="drawing1" id="draw1id" value="" />
<input type="hidden" name="drawing2" id="draw2id" value="" />
<input type="hidden" name="drawing3" id="draw3id" value="" />
<input type="hidden" name="drawing4" id="draw4id" value="" />
<input type="hidden" name="drawing5" id="draw5id" value="" />
<input type="hidden" name="drawing6" id="draw6id" value="" />
<input type="hidden" name="drawing7" id="draw7id" value="" />
<input type="hidden" name="drawing8" id="draw8id" value="" />
<input type="hidden" name="drawing9" id="draw9id" value="" />
<input type="hidden" name="drawing10" id="draw10id" value="" />
<input type="hidden" name="drawing11" id="draw11id" value="" />
<input type="hidden" name="drawing12" id="draw12id" value="" />
<input type="hidden" name="drawing13" id="draw13id" value="" />
<!-- These are hidden tags that save the mouse movements for the drawings. Need to make 10 -->
<input type="hidden" name="practicemousemove1" id="pmousemoveid" value="" />
<input type="hidden" name="mousemove1" id="mousemove1id" value="" />
<input type="hidden" name="mousemove2" id="mousemove2id" value="" />
<input type="hidden" name="mousemove3" id="mousemove3id" value="" />
<input type="hidden" name="mousemove4" id="mousemove4id" value="" />
<input type="hidden" name="mousemove5" id="mousemove5id" value="" />
<input type="hidden" name="mousemove6" id="mousemove6id" value="" />
<input type="hidden" name="mousemove7" id="mousemove7id" value="" />
<input type="hidden" name="mousemove8" id="mousemove8id" value="" />
<input type="hidden" name="mousemove9" id="mousemove9id" value="" />
<input type="hidden" name="mousemove10" id="mousemove10id" value="" />
<input type="hidden" name="mousemove11" id="mousemove11id" value="" />
<input type="hidden" name="mousemove12" id="mousemove12id" value="" />
<input type="hidden" name="mousemove13" id="mousemove13id" value="" />
<!-- Save the locations of the edges of the canvas-->
<input type="hidden" name="wpaintleft" id="wpaintleftout" value = "" />
<input type="hidden" name="wpaintright" id="wpaintrightout" value = "" />
<input type="hidden" name="wpainttop" id="wpainttopout" value="" />
<input type="hidden" name="wpaintbottom" id="wpaintbottomout" value="" />
<!-- Demographic questions asked at the end of the experiment. Are there any other question you'll want to ask?-->
<span id="otherquestions" style="font-family:helvetica" hidden>
<br><br><br>
<b>Age:</b>
<input type="text" name="age" id = "age"/><br /><br>
<b>Gender (M/F/NB; optional):</b>
<input type="text" name="gender (optional)" id = "gender"/><br /><br>
<b>Handedness (L/R):</b>
<input type="text" name="handedness" id = "handedness"/><br /><br>
<b>What type of device are you using?</b><br>
<input name="device" type="radio" id="desktop" value="desktop" /><label for="desktop">Desktop Computer</label>
<input name="device" type="radio" id="laptop" value="laptop" /><label for="laptop"> Laptop</label>
<input name="device" type="radio" id="tablet" value="tablet" /><label for="tablet"> Tablet</label>
<input name="device" type="radio" id="smartphone" value="smartphone" /><label for="smartphone"> Smartphone</label><br><br>
<b>Which input method are you using right now?</b><br>
<input name="inputdevice" type="radio" value="mouse" /><label for="desktop">Mouse</label>
<input name="inputdevice" type="radio" id="trackpad" value="trackpad" /><label for="trackpad"> Trackpad</label>
<input name="inputdevice" type="radio" id="joystick" value="joystick" /><label for="joystick"> Joystick</label>
<input name="inputdevice" type="radio" id="nub" value="nub" /><label for="nub"> Keyboard nub</label>
<input name="inputdevice" type="radio" id="finger" value="finger" /><label for="finger"> Finger</label>
<input name="inputdevice" type="radio" id="stylus" value="stylus" /><label for="stylus"> Stylus</label><br><br>
<b>How would you rate your artistic abilities?</b><br>
Very poor <input type="radio" name="artabilities" id="art1" value="1"><label for="art1">1</label>
<input type="radio" name="artabilities" id="art2" value="2"><label for="art2"> 2</label>
<input type="radio" name="artabilities" id="art3" value="3"><label for="art3"> 3</label>
<input type="radio" name="artabilities" id="art4" value="4"><label for="art4"> 4</label>
<input type="radio" name="artabilities" id="art5" value="5"><label for="art5"> 5 </label> Very good<br><br>
<b>Please briefly list any experience you have with artistic training (e.g., art classes). Write N/A if none. </b><br>
<input type="text" name="artexperience" id = "artexperience" size="50"/><br /><br>
</span>
<!-- </div>-->
<!-- -------------------------------------------------------------------- -->
<!-- Here is all the code that does all the behind-the-scenes work! -->
<!-- This loads in all the plugins necessary. I have JQuery and WPaint hosted in this Pavlovia Directory -->
<!-- load jQuery -->
<!-- jQuery UI -->
<script type="text/javascript" src="wpaint/lib/jquery.1.10.2.min.js"></script>
<script type="text/javascript" src="wpaint/lib/jquery.ui.core.1.10.3.min.js"></script>
<script type="text/javascript" src="wpaint/lib/jquery.ui.widget.1.10.3.min.js"></script>
<script type="text/javascript" src="wpaint/lib/jquery.ui.mouse.1.10.3.min.js"></script>
<script type="text/javascript" src="wpaint/lib/jquery.ui.draggable.1.10.3.min.js"></script>
<!-- wColorPicker -->
<link rel="Stylesheet" type="text/css" href="wpaint/lib/wColorPicker.min.css"/>
<script type="text/javascript" src="wpaint/lib/wColorPicker.min.js"></script>
<!-- wPaint -->
<link rel="Stylesheet" type="text/css" href="wpaint/src/wPaint.css"/>
<script type="text/javascript" src="wpaint/src/wPaint.js"></script>
<script type="text/javascript" src="wpaint/src/wPaint.utils.js"></script>
<script type="text/javascript" src="wpaint/plugins/main/src/wPaint.menu.main.js"></script>
<!--Commented out additional functionality of wpaint
<script type="text/javascript" src="wpaint/plugins/text/src/wPaint.menu.text.js"></script>
<script type="text/javascript" src="wpaint/plugins/shapes/wPaint.menu.main.shapes.js"></script>
<script type="text/javascript" src="wpaint/plugins/file/src/wPaint.menu.main.file.js"></script>-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.8.7/pixi.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/log4javascript/1.4.9/log4javascript.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.2/xlsx.full.min.js"></script>
<!-- <script type="application/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/psychopy.js"></script>-->
<!-- -------------------------------------------------------------------- -->
<!-- Start of JavaScript Code -->
<script type="module">
// npm install --save buffer
// notice that Javascript comments use 2 backslashes!!
//import { PsychoJS } from './lib/core-2021.1.4.js';
import { PsychoJS } from './wpaint/lib/core-2020.2.js';
import * as core from './wpaint/lib/core-2020.2.js';
import * as data from './wpaint/lib/data-2020.2.js';
//import { TrialHandler } from './wpaint/lib/data-2020.2.js';
import { ExperimentHandler } from './wpaint/lib/data-2020.2.js';
//import { data } from './wpaint/lib/psychojs-2021.2.3.js';
// const { TrialHandler } = data;
import { Scheduler } from './wpaint/lib/util-2020.2.js';
import * as visual from './wpaint/lib/visual-2020.2.js';
import * as sound from './wpaint/lib/sound-2020.2.js';
import * as util from './wpaint/lib/util-2020.2.js';
//import { createTrialHandler } from 'psychopy/iohub/datastore/util';
//import psychopy.iohub.util;
//const data = import * as core from './lib/core-2020.2.js';
const { abs, sin, cos, PI: pi, sqrt } = Math;
const { round } = util;
//import { ioHubConnection } from 'psychopy.iohub.client';
//const { TrialHandler } = data;
//import { createRequire } from "module";
//const require = createRequire(import.meta.url);
//const yourData = require("./your.json");
// import fs from 'fs';
// const fs = import * as fs from 'fs';
//import { createRequire } from 'module';
//const require = createRequire(import.meta.url);
//const fs = require("fs");
import saveAs from './wpaint/lib/FileSaver.js';
let expName = 'Drawing Test';
let expInfo = {'participant': ''};
const psychoJS = new PsychoJS({
debug: true
});
psychoJS.start({
expName: expName,
expInfo: expInfo,
resources: [
]
});
var filename = './data/pracfile';
const thisExp = new data.ExperimentHandler({
"name": expName,
"version": "",
"extraInfo": expInfo,
"runtimeInfo": null,
"originPath": "/creativity_drawing/html/index.html",
"savePickle": true,
"saveWideText": true,
"dataFileName": filename}
);
//const data = [[1, 2, 3], [4, 5, 6]];
// Save the data to a CSV file in the specified location
//util.saveAsWideText('./data/myfile.csv', data);
// const data = [[1, 2, 3], [4, 5, 6]];
// Save the data to a CSV file in the specified location
// psychopy.iohub.util.saveAsWideText('/path/to/save/location/myfile.csv', data);
// Define the data that you want to save to the CSV file
// psychoJS.experimentLogger.setLevel(core.Logger.ServerLevel.EXP);
// console.log(psychoJS);
// psychoJS.exp = new ExperimentHandler({extraInfo: expInfo, originPath: 'creativity_drawing/data/'});
// util.addInfoFromUrl(expInfo);
// psychoJS.filename = "/users/shuyaowang/desktop/DrawingTest/" + expInfo['participant'] + expName + expInfo['date'];
//adds participant number
// psychoJS.exp = new ExperimentHandler({extraInfo: expInfo});
// util.addInfoFromUrl(expInfo);
// csv_file = os.path.join('/Users/shuyaowang/', 'drawing', (document.getElementById('name').value).toString(), '.csv');
//const trials = createTrialHandler('./data/file.csv');
//trials.saveAsWideText(filePath);
// console.log(csv_file);
/* to do:
1. make a to-do list of everything you need this code to accomplish and what needs to be done to make it so
*/
// Now this is Javascript code that initializes the wPaint interface and gets image saving to work
// * If you want to remove certain capabilities, you can do that here with code like:
// * That will delete the ellipse features. You can look at jQuery.fn.wPaint.menus.main.items to see all your options.
//<center id="wPaint-img"></center>
// var images = './images/Image1.png';
// initialize wPaint
//var imgURLs = new Array();
//function(resp) {
// resp= $.parseJSON(resp);
// images.push(resp.img);
// $('#wPaint-img').append($('<img/>').attr('src', image));
// }
// for (let im = 0; im < nDrawTrials; im++) {
// imgURLs.push('./images/Image"+(im+1).toString()+".png'); //loops through all image names, adding them to arra
// }
// function loadImgBg () {
// internal function for displaying background images modal
// where images is an array of images (base64 or url path)
// NOTE: that if you can't see the bg image changing it's probably
// becasue the foregroud image is not transparent.
// this._showFileModal('bg', images);
// }
$("#wPain").wPaint({
path: 'wpaint/',
bg: '#FFFFFF',
menuOffsetLeft: -50,
menuOffsetTop: -50,
mode: 'pencil',
lineWidth: '3',
strokeStyle: '#000000',
fillStyle: '#000000',
});
$("#wPain").wPaint({
onShapeDown: function (e) {
console.log("Over here");
console.log(this.settings.mode + ": " + e.pageX + ',' + e.pageY);
},
onShapeMove: function (e) {
console.log(this.settings.mode + ": " + e.pageX + ',' + e.pageY);
},
onShapeUp: function (e) {
console.log(this.settings.mode + ": " + e.pageX + ',' + e.pageY);
}
});
// delete jQuery.fn.wPaint.menus.main.items.delete
$.fn.wPaint.defaults = {
autoCenterImage: true,
autoScaleImage: true,
onShapeDown: setClicking(), // callback for draw down event
onShapeMove: null, // callback for draw move event
onShapeUp: null // callback for draw up event
};
//this hides all the various wapint functions of the main menu. To reactivate any option, comment out line (with '//'')
$('.wPaint-menu-icon-name-ellipse').css('display', 'none'); //remove ellipse button
$('.wPaint-menu-icon-name-bucket').css('display', 'none'); //remove fill
$('.wPaint-menu-icon-name-lineWidth').css('display', 'none'); //remove line width
$('.wPaint-menu-icon-name-fillStyle').css('display', 'none'); //remove fill Color
$('.wPaint-menu-icon-name-rectangle').css('display', 'none'); //remove draw filled rectangle
$('.wPaint-menu-icon-name-line').css('display', 'none'); //remove straight line button
//$('.wPaint-menu-icon-name-undo').css('display', 'none');
//$('.wPaint-menu-icon-name-redo').css('display', 'none');
$('.wPaint-menu-icon-name-clear').css('display', 'none');
// Track mouse movements
// get canvas position
var rect = "";
var mousemovements = "";
var clicking = false;
var startTime = new Date().getTime();
var outputRadio1;
var outputRadio2;
var outputRadio3;
// Save the drawing in the hidden input when this function is triggered
// This function is updated for Example 3!
//this saves output of multiple choice question in demographics
function saveRadioValue(name) {
var outputRadio;
var ele = document.getElementsByName(name);
console.log(ele)
for(let i = 0; i < ele.length; i++) {
if(ele[i].type="radio") {
if(ele[i].checked){
outputRadio = ele[i].value;
return outputRadio
}
}
}
}
//function selects random integer in range [min:max]
function randint(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// this selects a random number based on guassian ; you probably do not need
function randn_bm() {
let u = 0, v = 0;
while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
while(v === 0) v = Math.random();
let num = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
num = num / 10.0 + 0.5; // Translate to 0 -> 1
if (num > 1 || num < 0) return randn_bm() // resample between 0 and 1
return num
}
// shuffle function to randomize order of images
function shuffle(array) {
array.sort(() => Math.random() - 0.5);
}
//freezes screen for a 'milliseconds' amount of time
function sleep(milliseconds) {
const date = Date.now();
let currentDate = 0;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
//function saves demographic data to CSV, shows debriefing screen, ends experiment, and redirects back to SONA
function quitPsychoJS() {
thisExp.addData('age',document.getElementById("age").value);
psychoJS.experiment.addData('age',document.getElementById("age").value);
psychoJS.experiment.addData('gender',document.getElementById("gender").value);
psychoJS.experiment.addData('handedness',document.getElementById("handedness").value);
psychoJS.experiment.addData('current_device',outputRadio1 = saveRadioValue("device"));//calls function to save radioData
psychoJS.experiment.addData('input_method',outputRadio1 = saveRadioValue("inputdevice"));
psychoJS.experiment.addData('art_ability',outputRadio1 = saveRadioValue("artabilities"));
psychoJS.experiment.addData('art_training',document.getElementById("artexperience").value);
//psychoJS.experiment.name(document.getElementById("age").value);
// Check for and save orphaned data
if (psychoJS.experiment.isEntryEmpty()) {
psychoJS.experiment.nextEntry();
}
//psychoJS.experiment.saveAsWideText((filename + ".csv"), {"delim": "auto"});
//psychoJS.experiment.saveAsPickle(filename);
// fetch("https://pipe.jspsych.org/api/data/", {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// Accept: "*/*",
// },
// body: JSON.stringify({
// experimentID: "E95sqAFaof9C",
// filename: "UNIQUE_FILENAME.csv",
// data: function(){
// return psychoJS.experiment.save()
// },
// }),
// });
psychoJS.experiment.save();
//psychoJS.window.close();
//psychoJS.quit({message: 'mess', isCompleted: true});
//this alert is the debriefing screen. Chnage the wording accordingly or remove if you do not use
//alert("This concludes the study!\nWe were interested in how a surprising interuption damaged your memory of a scene. That is why we had a pop up appear on the last trial. We were hoping that this irrelevant pop up would have a minimal impairment on one's memory. \nOn the next box, click 'Leave' to be redirected back to SONA. \nThank you and have a nice day!");
//window.onbeforeunload = null;
//redirect to SONA and grant credit (will need to change URL to match your directory)
window.location.assign('https://pennstate.sona-systems.com/webstudy_credit.aspx?experiment_id=2985&credit_token=8444538ba59b48ceb2c075b0e341f28d&survey_code=' + expInfo['participant'])
window.onbeforeunload = null;
//return Scheduler.Event.QUIT;
}
//saving the practice drawing
var saveTime, thinkingTime, drawingStart, drawingTime; //note that you have to predfine any variable you create in JavaScript
function savePracImg() {
// var d = new Date();
//drawingStart = d.getTime();
//thinkingTime = drawingStart - startTime;
//RT = saveTime - drawingStart;
// find which hidden element to update based on the trial number
document.getElementById('pDrawId').value = $('#wPain').wPaint('image'); //call which drawing holder to use (note here it is pDrawID)
$("#canvas").attr('src', document.getElementById('pDrawId').value);
// $("#canvasImageData").val(document.getElementById('pDrawId').value);
//var code = "<img src='" + $("#canvasImage") + "' width=500 height=500>";
//document.getElementById('imagedisplay').innerHTML = code;
document.getElementById('pmousemoveid').value = mousemovements;
// Get the location of the wPaint canvas and save it in the hidden inputs
var rect = document.getElementById('wPain').getBoundingClientRect();
document.getElementById('wpaintleftout').value = rect.left;
document.getElementById('wpaintrightout').value = rect.right;
document.getElementById('wpainttopout').value = rect.top;
document.getElementById('wpaintbottomout').value = rect.bottom;
var d = new Date();
saveTime = d.getTime() - startTime;
//DownloadCanvasAsImage();
// drawingTime = saveTime - thinkingTime;
//$("#canvasImage").attr('src', imageData);
//$(“#canvasImageData”).val(imageData);
//const canvas =
// const canvas = document.getElementById('myCanvas');
//DownloadCanvasAsImage();
// clear the interface and the mouse movements for the new image!
//var image = $('#wPain').toDataURL("image/png").replace("image/png", "image/octet-stream");
//window.location.href=image; // it will save locall
$('#wPain').wPaint('clear');
mousemovements = '';
var d = new Date();
startTime = d.getTime();
//var wp = $("#container").wPaint({
// image: "data:image/png;base64,base64 encoded string of the image here"
// });
//function base64ToFile((base64 data: document.getElementById('pDrawId').value).toString(), myFileNameWithdotExtention: 'prac.png',
//save drawing data to final CSV
//psychoJS.experiment.addData("foo", $('#canvasImage').val(imageData);
psychoJS.experiment.addData('user_drawing', document.getElementById('pDrawId').value);
//const fs = require('fs');
// Create a base64 string from an image => ztso+Mfuej2mPmLQxgD ...
// const base64 = fs.readFileSync("path-to-image.jpg", "base64");
// Convert base64 to buffer => <Buffer ff d8 ff db 00 43 00 ...
// const buffer = Buffer.from(base64, "base64");
// fs.writeFileSync("new-path.jpg", buffer);
//var img = document.getElementById('pDrawId').value;
//var data = img.replace(/^data:image\/png;base64,/, "");
//data += data.replace('+', ' ');
//var buf = new Buffer(data, 'base64')
// fs.writeFile('imagePra.png', buf);
var base = (document.getElementById('pDrawId').value).toString();
var base_string = base.replace('data:image/png;base64,', '');
let imgData = atob(base_string);
var pracname = (document.getElementById('name').value).toString() + '_' + (util.MonotonicClock.getDateStr()).toString() + '_pracimage.png';
let buffer = new ArrayBuffer(imgData.length);
let view = new Uint8Array(buffer);
for (let i=0; i<imgData.length; i++) {
view[i] = imgData.charCodeAt(i);
}
let blob = new File([buffer], {type: 'image/png'});
//let saveAs = import {saveAs} from './wpaint/lib/FileSaver.js';
//Servermanager = new ServerManager();
//Servermanager.uploadAudioVideo(blob, pracname, waitForCompletion = true);
console.log(buffer);
console.log(view);
console.log(imgData);
saveAs(blob, pracname);
fetch("https://pipe.jspsych.org/api/base64/", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "*/*",
},
body: JSON.stringify({
experimentID: "E95sqAFaof9C",
filename: "imageprac.png",
data: (document.getElementById('name').value).toString(),
}),
});
// test(document.getElementById('pDrawId').value);
// getFileFromBase64((document.getElementById('pDrawId').value).toString(),'pac.png')
psychoJS.experiment.addData('user_mouse', document.getElementById('pmousemoveid').value);
// psychoJS.experiment.addData('thinking_time', thinkingTime);
// psychoJS.experiment.addData('drawing_time', drawingTime); //time at they click submit
psychoJS.experiment.addData('whole_process_time_in_seconds', saveTime/1000);
RunInstructions(); //runs next part of experiment: the instructions screen
}
//function getFileFromBase64(string64, fileName) {
// const trimmedString = string64.replace('data:image/png;base64,', '/');
// const imageContent = atob(trimmedString);
// const buffer = new ArrayBuffer(imageContent.length);
// const view = new Uint8Array(buffer);
// for (let n = 0; n < imageContent.length; n++) {
// view[n] = imageContent.charCodeAt(n);
// }
// const type = 'image/png';
// const blob = new Blob([buffer], { type });
// return new File([blob], fileName, { lastModified: new Date().getTime(), type });
// }
//saves non-practice images
function saveImg() {
//var d = new Date();
//drawingStart = d.getTime();
// thinkingTime = drawingStart - startTime;
// find which hidden element to update based on the trial number
var drawid = 'draw' + drawCount + 'id';
var moveid = 'mousemove' + drawCount + 'id';
//moveid = 'mousemove1id';
document.getElementById(drawid).value = $('#wPain').wPaint('image');
var exname = (document.getElementById('name').value).toString() + '_' + (util.MonotonicClock.getDateStr()).toString() + '_image' + Trialnumber.toString() + '.png';
var base = (document.getElementById(drawid).value).toString();
var base_string = base.replace('data:image/png;base64,', '');
let imgData = atob(base_string);
let buffer = new ArrayBuffer(imgData.length);
let view = new Uint8Array(buffer);
for (let i=0; i<imgData.length; i++) {
view[i] = imgData.charCodeAt(i);
}
let blob = new File([buffer], {type: 'image/png'});
// let saveAs = import {saveAs} from './wpaint/lib/FileSaver.js';
saveAs(blob, exname);
document.getElementById(moveid).value = mousemovements;
document.getElementById('wpaintleftout').value = rect.left;
document.getElementById('wpaintrightout').value = rect.right;
document.getElementById('wpainttopout').value = rect.top;
document.getElementById('wpaintbottomout').value = rect.bottom;
var d = new Date();
saveTime = d.getTime() - startTime;
//DownloadCanvasAsImage();
//drawingTime = saveTime - thinkingTime;
// clear the interface and the mouse movements for the new image!
$('#wPain').wPaint('clear');
mousemovements = '';
var d = new Date();
startTime = d.getTime();
psychoJS.experiment.nextEntry();
console.log(Trialnumber);
//saves last trial's data to CSV
psychoJS.experiment.addData('trial',Trialnumber);
psychoJS.experiment.addData('seen_image',imgURLs[Trialnumber-1]); //saves to CSV which image was shown (may want to note which starting line was given)
psychoJS.experiment.addData('user_drawing', document.getElementById(drawid).value);
psychoJS.experiment.addData('user_mouse', document.getElementById(moveid).value);
//psychoJS.experiment.addData('thinking_time', thinkingTime);
// psychoJS.experiment.addData('drawing_time', drawingTime); //time at they click submit
psychoJS.experiment.addData('whole_process_time_in_seconds', saveTime/1000);
Trialnumber = Trialnumber + 1; //adds counter to proceed to next trial
RunExperiment(); //calls run Experiment to run next trial
}
// Track when they're holding the mouse button down, here it starts to save mousemovements (only id made in drawing canvas)
$(document).mousedown(function(){
//$("#drawingdisplay").mousedown(function(){
clicking = true;
});
// Save where the mouse is when it's moving while clicked
$(document).mousemove(function(e){
var d = new Date(); // get the time
var padding = 100; // extra pixel padding so don't miss drawing
if(clicking == false) return; // don't save data when the mouse isn't clicked
// Get the x and y coordinates of the click
var xcoord = e.pageX;
var ycoord = e.pageY;
var timeDiff = d.getTime() - startTime; //saves time of mousemovement
// Save the mouse movement as: X,Y,milliseconds-from-start;
console.log("(" + xcoord + "," + ycoord + ")");
mousemovements = mousemovements + xcoord + "," + ycoord + "," + timeDiff + ";";
});
$(document).mouseup(function(){
//console.log(clicking);
clicking = false;
// Add in a marker that a drawing stroke ended: 9999,9999,9999;
mousemovements = mousemovements + "9999,9999,9999;";
});
/*******************************************************/
//parameters for running experiment
//probably can comment from here:
var conditionIdentifier = randn_bm(); //determines which condition to run if multiple
console.log(conditionIdentifier); //shows output in log (Press Ctrl+Shift+'j' on PC to open console)
var condition = 'wall art'; //changes to particular condition
if (condition =='pillow'){
var buttonText = 'pre_nextbutton1';
var buttonText = 'pre_nextbutton2';
}
//to here
var instructionText = 'instructionsW';
var instructionPtext = 'instructionsP';
var Trialnumber = 1; //count variable to track the trial number
var nDrawTrials = 13; //change to however many drawing trials you will need
var drawCount = 0; //counter to save images to each data holder
var Trialmax = nDrawTrials+1; //this is the the trial where questionnaire appears (set to nDrawingTrials+1 for extra instructions canvas)
//nDrawTrials = 2; //for debugging
//var stimTime = 2000; // for how many ms do you want to show the image or blank screen? may probably delete
//make sure images are the same dimensions
var imgURLs = new Array();
for (let im = 0; im < 13; im++) {
imgURLs.push("./images/Image"+(im+1).toString()+".png");
}
//for loop to call image names loaded into canvas (JavaScript is 0-ordered)
shuffle(imgURLs); //shuffles order of drawing trials
console.log(imgURLs);
function runPInstructions(){
document.getElementById('welcome').hidden = true;
document.getElementById('consentP').hidden = true;
document.getElementById('acceptConsent').hidden = true;
document.getElementById('instructionsPractice').hidden = false;
document.getElementById('startpr').hidden = false;
}
//start of functions that run different aspects of experiment
function runPractice(){
$("#wPain").wPaint("image", imgURLs[0]);
var d = new Date();
startTime = d.getTime();
//hides all consent form information
//document.getElementById('consentP').hidden = true;
//document.getElementById('acceptConsent').hidden = true;
//reveals practice screen
document.getElementById('instructionsPractice').hidden = true;
document.getElementById('startpr').hidden = true;
document.getElementById('drawingdisplay').hidden = false;
document.getElementById('practiceSubmit').hidden = false; //pressing this button runs 'RunInstructions'
//var wp = $("#container").wPaint({
//image: "data:image/png;base64,base64 encoded string of the image here"
// });
//var imageData = wp.wPaint("image");
// $("#someImage").attr("src", imageData);
//var d = new Date();
// drawingStart = d.getTime() - startTime;
}
//start of function that runs instructions screen
function RunInstructions(){
//Hides Practice screen Instruction
document.getElementById('instructionsPractice').hidden = true;
document.getElementById('drawingdisplay').hidden = true;
document.getElementById('practiceSubmit').hidden = true;
//Reveals instructions screen
document.getElementById(instructionText).hidden = false;
document.getElementById('startexp').hidden = false; // pressing this button starts function 'RunExperiment'
//document.getElementById('imagedisplay').innerHTML = '';
}
//this function runs for each trial of the experiment
//var trialStart, drawingStart;
function RunExperiment(){
//drawingStart = trialStart;
//+ stimTime;
console.log(Trialnumber); //trqacks trial number in console
//hides instructions text and previous canvas [will probably need to change]
document.getElementById(instructionText).hidden = true;
document.getElementById('startexp').hidden = true; // take away the start button
document.getElementById('drawSubmit').hidden = true; // Reveal the next button
document.getElementById('nextTrialButton').hidden = true;
//changeBack(Trialnumber-1);
//document.getElementById('instructionsSurprise').hidden = true;
//document.getElementById('instructionsNoDraw').hidden = true;
//reveals demographics screen (at end of experiment)
if(Trialnumber==Trialmax){
document.getElementById('drawingdisplay').hidden = true;
document.getElementById('otherquestions').hidden = false;
document.getElementById('drawSubmit').hidden = true; // Hide the next button
document.getElementById('submitButton').hidden = false; // Reveal the submit button
}
//else runs next trial
else{
displayImage(Trialnumber-1);
drawCount+=1; //adds number ahead of drawing trial
// var d = new Date();
// drawingStart = d.getTime() - startTime;
// Show the image for stimtime
// document.getElementById('drawingdisplay').hidden = false;
//displayImage(Trialnumber-1);
//$("#wPain").wPaint('image', imgURLs[1]);
//var imageData = $("#wPain").wPaint("image");
// $("#canvasImage").attr('src', imageData);
//document.getElementById('drawSubmit').hidden = false;
//if there is a delay between trials, you might be able to keep this code structure
//and have display image show a white square (the equivalent of a blank screen)
//displayImage(Trialnumber-1); // Show Current image based on index value entered in funnction
//changeBack(Trialnumber-1);
// wait the stimtime, then go to the next phase of the experiment
//setTimeout(waitItOut,stimTime);
}
} //end of function
//function waitItOut(){
//document.getElementById('imagedisplay').innerHTML = ''; // hide the image
// document.getElementById('drawingdisplay').hidden = true; //reveal
// document.getElementById('drawSubmit').hidden = true; // Reveal the next button
//document.getElementById('instructionsSurprise').hidden = false; ;//can comment out this line if no text appears
// }
//for (let im = 0; im < 13; im++) {
// $('#wPain').wPaint(
// 'image', "./images/Image"+(im+1).toString()+".png");
// }
function displayImage(imagenumber){
// You pass this function an image number and it displays it in the experiment
//document.getElementById('drawSubmit').hidden = false; // hide the Next button so they can't skip around
// $('#wPain').attr('src', imgURLs[imagenumber]);
//var code = "<img src='" + imgURLs[imagenumber] + "' width=500 height=500>"; // The code to insert into the HTML for the experiment. It displays the image at the same dimensions as the drawing interface.
//document.getElementById('imagedisplay').hidden = false;
// $('#wPain').wPaint({image: './images/Image1.png'});
//$('#wPain').wPaint('image', code);
//var imageData = $("#wPain").wPaint("image");
//$("#canvasImage").attr('src', imageData);
// document.getElementById('imagedisplay').innerHTML = code;
$('#wPain').wPaint('image', imgURLs[imagenumber]);
var d = new Date();
startTime = d.getTime();
//var imageData = $("#wPain").wPaint("image");
//$("#canvasImage").attr('src', imageData);
document.getElementById('drawingdisplay').hidden = false;
document.getElementById('drawSubmit').hidden = false;
//$('#wPain').wPaint({image: imgURLs[imagenumber]});
//sleep(200);
//document.getElementById('imagedisplay').hidden = false;
}
//these are functions that track partiicpant activity (i.e., if they click a button or move their mouse)
//if specified activity happens, a function is run