-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe.js
100 lines (78 loc) · 2.58 KB
/
frame.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
class Frame{
constructor(
// Key locations
frontVec,
rearVec,
chainVec,
// Rest
thetaFrontFork,
lenFrontFork,
thetaSeatTube,
lenSeatTube,
// Proportions
downTubeFrontConnectionP, // Ps are proportions and in 0,1
topTubeFrontConnectionP,
topTubeSeatConnectionP,
//
tubeRadius,
fillColor
){
// key locations
this.frontVec = frontVec;
this.rearVec = rearVec;
this.chainVec = chainVec;
// Rest
this.thetaFrontFork = thetaFrontFork;
this.lenFrontFork = lenFrontFork;
this.thetaSeatTube = thetaSeatTube;
this.lenSeatTube = lenSeatTube;
this.downTubeFrontConnectionP = downTubeFrontConnectionP;
this.topTubeFrontConnectionP = topTubeFrontConnectionP;
this.topTubeSeatConnectionP = topTubeSeatConnectionP;
this.tubeRadius = tubeRadius;
this.fillColor = fillColor;
}
draw(){
push();
fill(this.fillColor);
noStroke();
this.drawFrontFork();
this.drawSeatTube();
this.drawDownTube();
this.drawTopTube();
console.log(this.rearVec);
this.drawBackStays();
pop();
}
drawFrontFork(){
let endVec = this.getVectorByAngleDist(this.frontVec, this.thetaFrontFork, this.lenFrontFork);
let ff = new FrameComponent(this.tubeRadius, this.frontVec, endVec);
ff.draw();
}
drawSeatTube(){
let endVec = this.getVectorByAngleDist(this.chainVec, this.thetaSeatTube, this.lenSeatTube);
let st = new FrameComponent(this.tubeRadius, this.chainVec, endVec);
st.draw();
}
drawTopTube(){
let endVec = this.getVectorByAngleDist(this.chainVec, this.thetaSeatTube, this.lenSeatTube*this.topTubeSeatConnectionP);
let startVec = this.getVectorByAngleDist(this.frontVec, this.thetaFrontFork, this.lenFrontFork*this.topTubeFrontConnectionP);
let tt = new FrameComponent(this.tubeRadius, startVec, endVec);
tt.draw();
}
drawDownTube(){
let endVec = this.getVectorByAngleDist(this.frontVec, this.thetaFrontFork, this.lenFrontFork*this.downTubeFrontConnectionP);
let dt = new FrameComponent(this.tubeRadius, this.chainVec, endVec);
dt.draw();
}
drawBackStays(){
let setFrontConn = this.getVectorByAngleDist(this.chainVec, this.thetaSeatTube, this.lenSeatTube*this.topTubeSeatConnectionP);
let bs1 = new FrameComponent(this.tubeRadius, this.chainVec, this.rearVec);
let bs2 = new FrameComponent(this.tubeRadius, setFrontConn, this.rearVec);
bs1.draw();
bs2.draw();
}
getVectorByAngleDist(startVec, theta,length){
return(createVector(startVec.x-length*sin(theta), startVec.y-length*cos(theta)));
}
}