-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathUpdate.js
executable file
·60 lines (50 loc) · 1.94 KB
/
Update.js
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
/**
* Called at frequent interval, updates the Application State
*
* Should be used for things that are time dependent
*/
// Variables to determine state of the application
var drawingTran = false; // If a transition is being created
var pm = PlacementMode.STATE; // The placement mode
var animating = false; // If the application is animating the current machine
// Called at a set interval
function update(){
// animating is turned off when we want normal functionality, this will allow debug input to work
if(!animating){
// Clear the canvases
ctx.fillStyle="white";
ctx.fillRect(0,0,c.width,c.height);
ictx.fillStyle="#728C9A";
ictx.fillRect(0,0,inputCanvas.width,inputCanvas.height);
pctx.fillStyle="#EEE9E9";
pctx.fillRect(0,0,pointerCanvas.width,pointerCanvas.height);
// Draw the elements in their current state
displayInputs(input,false);
for(var i=0; i<Qstates.length; i++){
Qstates[i].display();
}
}
// Set the selected transitions attributes to those in the text boxes
if( Turing && selectedTran != null ){
selectedTran.character = document.getElementById('Read').value;
selectedTran.writeCharacter = document.getElementById('Write').value;
selectedTran.tapeShift = parseInt(document.getElementById('Shift').value);
}
// Draw a line simulating the transition being created
if( drawingTran == true && clickedState != null && pm == PlacementMode.TRANSITION ){
line(clickedState.x, clickedState.y, mouseX, mouseY+$(window).scrollTop(), ctx);
ctx.fillText(lastKeyCode,mouseX,mouseY+ $(window).scrollTop());
}
}
// The interval that update is called on (milliseconds)
var timeVar = setInterval(function(){update();},10);
// Placement mode control
function changePlacement(newPlacement){
pm = newPlacement;
// DEBUG
// console.log(pm + " " + pm.value);
if(selectedState != null){
selectedState.toggleSelect();
}
selectedState = null;
}