-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaper_script.js
115 lines (111 loc) · 3.04 KB
/
paper_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
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
106
107
108
109
110
111
112
113
114
115
var patternChoice = Math.floor(Math.random() * 3);
var x = 0;
var y = 0;
var size = 15;
var strokeWidth = 2;
var shape = {
backSlash: {
draw: function() {
new Path.Line({
from: [x, y],
to: [x+size, y+size],
strokeColor: "black",
strokeWidth: strokeWidth
});
}
},
forwardSlash: {
draw: function() {
new Path.Line({
from: [x+size, y],
to: [x, y+size],
strokeColor: "black",
strokeWidth: strokeWidth
});
}
},
leftLine: {
draw: function() {
new Path.Line({
from: [x, y],
to: [x, y+size],
strokeColor: "black",
strokeWidth: strokeWidth
});
}
},
rightLine: {
draw: function() {
new Path.Line({
from: [x+size, y+size],
to: [x+size, y],
strokeColor: "black",
strokeWidth: strokeWidth
});
}
},
upLine: {
draw: function() {
new Path.Line({
from: [x+size, y],
to: [x, y],
strokeColor: "black",
strokeWidth: strokeWidth
});
}
},
downLine: {
draw: function() {
new Path.Line({
from: [x, y+size],
to: [x+size, y+size],
strokeColor: "black",
strokeWidth: strokeWidth
});
}
}
};
var pattern = {
slashes: {
make: function() {
var randomNumber = Math.floor(Math.random() * 2);
if(randomNumber === 0) shape.backSlash.draw();
if(randomNumber === 1) shape.forwardSlash.draw();
}
},
lines: {
make: function() {
var randomNumber = Math.floor(Math.random() * 4);
if(randomNumber === 0) shape.leftLine.draw();
if(randomNumber === 1) shape.rightLine.draw();
if(randomNumber === 2) shape.upLine.draw();
if(randomNumber === 3) shape.downLine.draw();
}
},
linesAndSlashes: {
make: function() {
var randomNumber = Math.floor(Math.random() * 6);
if(randomNumber === 0) shape.leftLine.draw();
if(randomNumber === 1) shape.rightLine.draw();
if(randomNumber === 2) shape.upLine.draw();
if(randomNumber === 3) shape.downLine.draw();
if(randomNumber === 4) shape.backSlash.draw();
if(randomNumber === 5) shape.forwardSlash.draw();
}
}
};
function onFrame(event) {
if(x <= view.size.width && y <= view.size.height) {
if(patternChoice === 0) pattern.slashes.make();
if(patternChoice === 1) pattern.lines.make();
if(patternChoice === 2) pattern.linesAndSlashes.make();
next();
}
}
function next() {
x = x+size;
if(x > view.size.width) {
x = 0;
y = y+size;
}
}