-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtamathing
77 lines (67 loc) · 1.53 KB
/
tamathing
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
<!DOCTYPE html>
<html>
<head>
<title>Canvas Tamagotchi</title>
<link rel='stylesheet' type='text/css' href='css/main.css'>
<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
<script src='js/core.js'></script>
</head>
<body>
<canvas height='289' width='289' id='screen' class='screen'>
</canvas>
</body>
</html>
var screen,lastCommand="";
$(document).on('ready',function() {
screen = new Screen('#screen');
}).on('keydown',function(evt) {
if(evt.ctrlKey===true) {
if(evt.which===82) {
command();
}
}
});
function command() {
lastCommand = prompt("Command: ",lastCommand);
try {
eval(lastCommand);
}
catch(err) {
alert("Error: " + err.description);
}
}
function Screen(screenEl) {
var self = this;
this.sizeX = 25;
this.sizeY = 25;
this.pixelSize = 10;
this.pixelSpacing = 1.5;
this.startX = 1.5;
this.startY = 1.5;
this.screenEl = $(screenEl)[0];
this.fillScreen = function() {
var screen = self.getScreen();
var ts=0,tc=0;
for(var i=self.startX;tc<self.sizeX;i+=(self.pixelSize+self.pixelSpacing)) {
for(var x=self.startY;ts<self.sizeY;x+=(self.pixelSize+self.pixelSpacing)) {
screen.fillRect(i,x,self.pixelSize,self.pixelSize);
ts++;
}
ts=0;
tc++;
}
}
this.clearScreen = function() {
var screen = self.getScreen();
screen.fillStyle = "rgb(255,255,255)";
screen.fillRect(0,0,self.screenEl.width,self.screenEl.height);
}
this.getScreen = function() {
return self.screenEl.getContext("2d");
}
}
.screen {
border-style:solid;
border-width:2px;
border-color:black;
}