-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwheel.js
128 lines (95 loc) · 3.02 KB
/
wheel.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
116
117
118
119
120
121
122
123
124
125
126
127
128
const spokeType = {
SINGLE: 'single', //
DOUBLE: 'double'
}
class Wheel{
constructor(x, y, axleRadius, hubWidth, spokeWidth, rimWidth, tireWidth, treadWidth, spokeSetCount, treadCount, spokeNubWidth, spokeNubLength){
// Center
this.x = x;
this.y = y;
// Parts of the wheel sizes
this.axleRadius = axleRadius; // where do we start
this.hubWidth = hubWidth;
this.spokeWidth = spokeWidth;
this.rimWidth = rimWidth;
this.tireWidth = tireWidth;
this.treadWidth = treadWidth;
// Spokes
this.spokeSetCount = spokeSetCount; // how many sets of single/double spokes?
this.treadCount = treadCount; // how many treads...
this.spokeNubWidth=spokeNubWidth;
this.spokeNubLength=spokeNubLength;
this.thetaSpokeOffset = 0;
}
draw(){
push();
translate(this.x, this.y); //
this.drawHub();
this.drawSpokes();
this.drawRim();
this.drawTire();
this.drawTreads();
pop();
}
drawHub(){
push();
stroke('black');
for(let i=this.axleRadius; i<=(this.axleRadius + this.hubWidth);i++){
ellipse(0,0,2*i,2*i);
}
pop();
}
drawSpokes(){
let spokeSeparation = 2*PI/this.spokeSetCount; // in radians
console.log(spokeSeparation);
let innerR = (this.axleRadius + this.hubWidth);
let outerR = innerR + this.spokeWidth;
// single spokes
push();
rotate(random(0,2*PI));
for(let i=0; i<this.spokeSetCount; i++){
push();
fill('black');
rotate(i*spokeSeparation);
console.log(i, i*spokeSeparation);
line(innerR,0, outerR*cos(this.thetaSpokeOffset), outerR*sin(this.thetaSpokeOffset));
lineRect(outerR-this.spokeNubWidth,this.spokeNubLength,outerR,-this.spokeNubLength);
//lineRect(outerR*cos(this.thetaSpokeOffset)-this.spokeNubWidth,outerR*sin(this.thetaSpokeOffset)+this.spokeNubLength,outerR*cos(this.thetaSpokeOffset),outerR*sin(this.thetaSpokeOffset)-this.spokeNubLength);
pop();
}
pop();
}
drawDoubledSpokes(){
let spokeSetSeparation = 2*PI/this.spokeSetCount; // in radians
}
drawRim(){
let innerR = this.axleRadius + this.hubWidth + this.spokeWidth;
ellipse(0,0,2*innerR, 2*innerR);
}
drawTire(){
let innerR = (this.axleRadius + this.hubWidth + this.spokeWidth + this.rimWidth);
for(let i=0; i < this.tireWidth; i++){
ellipse(0,0,2*(innerR+i), 2*(innerR+i));
}
}
drawTreads(){
let innerR = (this.axleRadius + this.hubWidth + this.spokeWidth + this.rimWidth + this.tireWidth);
let treadSeparation = PI/(this.treadCount) // each tread has same width and separation...
push();
rotate(random(0,2*PI));
for(let i=0; i < this.treadCount; i++){
let thetaStart = i*2*treadSeparation;
let thetaEnd = thetaStart + treadSeparation;
for(let j=0; j < this.treadWidth;j++){
arc(0,0,2*(innerR+j), 2*(innerR+j), thetaStart, thetaEnd,OPEN);
}
}
pop();
}
}
function lineRect(x1,y1,x2,y2){
let numLines = x2-x1;
for(i=0;i<numLines;i++){
line(x1+i,y1, x1+i,y2);
}
}