-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage8画布.html
103 lines (90 loc) · 2.47 KB
/
page8画布.html
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
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio">
<title>123</title>
</head>
<body>
<style type="text/css">
body {
padding: 0;
margin: 0;
background: rgb(230, 230, 230);
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
<script src="./p5.js"></Script>
<script type="text/javascript">
function keyPressed() {
clear();
text("brush size = " + size, 53, 85);
if (key == char(32)) { // spacebar
clear();
text("brush size = " + size, 53, 85);
}
if (keyCode == UP_ARROW) {
size++;
//zoom ++;
diff = size / size;
}
if (keyCode == DOWN_ARROW) {
if (size >= 1) {
size--;
diff = size / size;
}
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
distance = 10;
spring = 0.5;
friction = 0.5;
size = 10;
diff = size / size;
x = y = ax = ay = a = r = f = 0;
//
fill(265, 123, 18);
textSize(20);
text("brush size = " + size, 53, 85);
}
function draw() {
oldR = r;
if (mouseIsPressed) {
mX = mouseX;
mY = mouseY;
if (!f) {
f = 1;
x = mX;
y = mY;
}
ax += (mX - x) * spring;
ay += (mY - y) * spring;
ax *= friction;
ay *= friction;
a += sqrt(ax * ax + ay * ay) - a;
a *= 0.6;
r = size - a;
for (i = 0; i < distance; ++i) {
oldX = x;
oldY = y;
x += ax / distance;
y += ay / distance;
oldR += (r - oldR) / distance;
if (oldR < 1) oldR = 1;
strokeWeight(oldR + diff);
line(x, y, oldX, oldY);
strokeWeight(oldR);
line(x + diff * 2, y + diff * 2, oldX + diff * 2, oldY + diff * 2);
line(x - diff, y - diff, oldX - diff, oldY - diff);
}
} else if (f) {
ax = ay = f = 0;
}
}
</script>
画布page8
</body>
</html>