-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
57 lines (42 loc) · 1.08 KB
/
script.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
/*
YOUR SKETCH GOES HERE
*/
let cnv;
let zoomBy = 1;
let xOffset = 0;
let yOffset = 0;
let mx = 0;
let my = 0;
let w = 500;
let h = 500;
function setup() {
cnv = createCanvas(w, h);
cnv.parent('sketch-holder');
frameRate(30);
windowResized();
}
function draw() {
background(250)
ellipse(w/2,h/2,50,50);
line(0,my,h,my);
line(mx,0,mx,w);
}
function mouseClicked() {
mx = winMouseX / zoomBy - xOffset / zoomBy;
my = winMouseY / zoomBy - yOffset / zoomBy;
}
function mouseDragged() {
mx = winMouseX / zoomBy - xOffset / zoomBy;
my = winMouseY / zoomBy - yOffset / zoomBy;
}
function mouseMoved() {
mx = winMouseX / zoomBy - xOffset / zoomBy;
my = winMouseY / zoomBy - yOffset / zoomBy;
}
function windowResized() {
//zoomBy = (windowWidth / windowHeight + w/h < windowHeight / windowWidth) ? windowWidth / w : windowHeight / h;
zoomBy = windowWidth > windowHeight ? windowHeight / h : windowWidth / w;
cnv.style("zoom", zoomBy);
xOffset = document.getElementById("sketch-holder").offsetLeft;
yOffset = document.getElementById("sketch-holder").offsetTop;
}