FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/java/examples/Topics/Interaction/Reach2/Reach2.pde at master · whyi/processing · GitHub
whyi
processing
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
java
/
examples
/
Topics
/
Interaction
/
Reach2
/
Reach2.pde
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (52 loc) · 1.31 KB
Breadcrumbs
processing
/
java
/
examples
/
Topics
/
Interaction
/
Reach2
/
Reach2.pde
Copy path
File metadata and controls
59 lines (52 loc) · 1.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
* Reach 2
* based on code from Keith Peters.
*
* The arm follows the position of the mouse by
* calculating the angles with atan2().
*/
int
numSegments
=
10
;
float
[] x
=
new
float
[numSegments];
float
[] y
=
new
float
[numSegments];
float
[] angle
=
new
float
[numSegments];
float
segLength
=
26
;
float
targetX, targetY;
void
setup
() {
size
(
640
,
360
);
strokeWeight
(
20.0
);
stroke
(
255
,
100
);
x[x
.
length
-
1
]
=
width
/
2
;
//
Set base x-coordinate
y[x
.
length
-
1
]
=
height
;
//
Set base y-coordinate
}
void
draw
() {
background
(
0
);
reachSegment(
0
,
mouseX
,
mouseY
);
for
(
int
i
=
1
; i
<
numSegments; i
++
) {
reachSegment(i, targetX, targetY);
}
for
(
int
i
=
x
.
length
-
1
; i
>=
1
; i
--
) {
positionSegment(i, i
-
1
);
}
for
(
int
i
=
0
; i
<
x
.
length; i
++
) {
segment(x[i], y[i], angle[i], (i
+
1
)
*
2
);
}
}
void
positionSegment
(
int
a
,
int
b
) {
x[b]
=
x[a]
+
cos
(angle[a])
*
segLength;
y[b]
=
y[a]
+
sin
(angle[a])
*
segLength;
}
void
reachSegment
(
int
i
,
float
xin
,
float
yin
) {
float
dx
=
xin
-
x[i];
float
dy
=
yin
-
y[i];
angle[i]
=
atan2
(dy, dx);
targetX
=
xin
-
cos
(angle[i])
*
segLength;
targetY
=
yin
-
sin
(angle[i])
*
segLength;
}
void
segment
(
float
x
,
float
y
,
float
a
,
float
sw
) {
strokeWeight
(sw);
pushMatrix
();
translate
(x, y);
rotate
(a);
line
(
0
,
0
, segLength,
0
);
popMatrix
();
}
Back
|
FazBrowse Home
|
New Git URL