-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupport.js
More file actions
105 lines (87 loc) · 3.54 KB
/
support.js
File metadata and controls
105 lines (87 loc) · 3.54 KB
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
// Support variables & functions (DO NOT CHANGE!)
let student_ID_form, display_size_form, start_button; // Initial input variables
let student_ID, display_size; // User input parameters
// Prints the initial UI that prompts that ask for student ID and screen size
function drawUserIDScreen()
{
background(color(0,0,0)); // sets background to black
// Text prompt
main_text = createDiv("Insert your student number and display size");
main_text.id('main_text');
main_text.position(10, 10);
// Input forms:
// 1. Student ID
let student_ID_pos_y_offset = main_text.size().height + 40; // y offset from previous item
student_ID_form = createInput(''); // create input field
student_ID_form.position(200, student_ID_pos_y_offset);
student_ID_label = createDiv("Student number (int)"); // create label
student_ID_label.id('input');
student_ID_label.position(10, student_ID_pos_y_offset);
// 2. Display size
let display_size_pos_y_offset = student_ID_pos_y_offset + student_ID_form.size().height + 20;
display_size_form = createInput(''); // create input field
display_size_form.position(200, display_size_pos_y_offset);
display_size_label = createDiv("Display size in inches"); // create label
display_size_label.id('input');
display_size_label.position(10, display_size_pos_y_offset);
// 3. Start button
start_button = createButton('START');
start_button.mouseReleased(startTest);
start_button.position(width/2 - start_button.size().width/2, height/2 - start_button.size().height/2);
}
// Verifies if the student ID is a number, and within an acceptable range
function validID()
{
if(parseInt(student_ID_form.value()) < 200000 && parseInt(student_ID_form.value()) > 1000) return true
else
{
alert("Please insert a valid student number (integer between 1000 and 200000)");
return false;
}
}
// Verifies if the display size is a number, and within an acceptable range
function validSize()
{
if (parseInt(display_size_form.value()) < 50 && parseInt(display_size_form.value()) > 10) return true
else
{
alert("Please insert a valid display size (between 10 and 50)");
return false;
}
}
// Starts the test (i.e., target selection task)
function startTest()
{
if (validID() && validSize())
{
// Saves student and display information
student_ID = parseInt(student_ID_form.value());
display_size = parseInt(display_size_form.value());
// Deletes UI elements
main_text.remove();
student_ID_form.remove();
student_ID_label.remove();
display_size_form.remove();
display_size_label.remove();
start_button.remove();
// Goes fullscreen and starts test
fullscreen(!fullscreen());
testStartTime = millis();
}
}
// Randomize the order in the targets to be selected
function randomizeTrials()
{
for (var i = 0; i < 18; i++) // 4 rows times 4 columns = 16 targets
for (var k = 0; k < 3; k++) // each target will repeat 3 times (16 times 3 = 48 trials)
trials.push(i);
shuffle(trials, true); // randomize the trial order
print("trial order: " + trials); // prints trial order - for debug purposes
}
// Verifies if (x,y) -- typically a mouse click -- is inside the input area defined
function insideInputArea(x, y)
{
if (x > inputArea.x && x < inputArea.x + inputArea.w)
return y > inputArea.y && y < inputArea.y + inputArea.h
return false
}