-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_paint.js
52 lines (42 loc) · 1.09 KB
/
demo_paint.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
/* Super minimal paint program
* Copyright (c) 2016 Crystalline Emerald
* This software is distrbuted under MIT license, see LICENSE for details
*/
noClearScreen = true;
screenWidth = 640;
screenHeight = 480;
function init() {
print("Init");
}
mouseDown = false;
function setpix(x, y, red, green, blue) {
var offset = ((y*screenWidth)+x)<<2;
screen[offset] = red;
screen[offset+1] = green;
screen[offset+2] = blue;
screen[offset+3] = 255;
}
function draw(x, y) {
setpix(x,y, 0x33, 0xFF, 0);
}
function update(events) {
if (events) {
for (var i=0; i<events.length; i++) {
var event = events[i];
if (event.type == SDL_MOUSEBUTTONDOWN) {
mouseDown = true;
draw(event.x, event.y);
}
if (event.type == SDL_MOUSEBUTTONUP) {
mouseDown = false;
draw(event.x, event.y);
}
if (event.type == SDL_MOUSEMOTION && mouseDown) {
draw(event.x, event.y);
}
}
}
}
function exit() {
print("Exit");
}