forked from mhenstell/elsignSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixel.pde
107 lines (84 loc) · 1.91 KB
/
Pixel.pde
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
class Pixel
{
float x;
float y;
float z;
float w;
float h;
int sides;
color c;
float DEFAULT_WIDTH = 3;
float DEFAULT_HEIGHT = 10;
int DEFAULT_SIDES = 20;
public Pixel(float x_, float y_, float z_, float w_, float h_, int sides_) {
x = x_;
y = y_;
z = z_;
w = w_;
h = h_;
sides = sides_;
}
public Pixel(int x_, int y_) {
x = int(x_);
y = int(y_);
w = DEFAULT_WIDTH;
h = DEFAULT_HEIGHT;
sides = DEFAULT_SIDES;
c = color(255, 255, 255);
}
public Pixel(int x_, int y_, float h_) {
x = int(x_);
y = int(y_);
w = DEFAULT_WIDTH;
h = h_;
sides = DEFAULT_SIDES;
c = color(255, 255, 255);
}
void draw() {
fill(c);
pushMatrix();
translate(x * 10, 0, y * 10);
cylinder(w, h, sides);
popMatrix();
}
void update(color c_) {
c = c_;
}
/**
cylinder taken from http://wiki.processing.org/index.php/Cylinder
@author matt ditton
*/
void cylinder(float w, float h, int sides)
{
float angle;
float[] x = new float[sides+1];
float[] z = new float[sides+1];
//get the x and z position on a circle for all the sides
for(int i=0; i < x.length; i++){
angle = TWO_PI / (sides) * i;
x[i] = sin(angle) * w;
z[i] = cos(angle) * w;
}
//draw the top of the cylinder
beginShape(TRIANGLE_FAN);
vertex(0, -h/2, 0);
for(int i=0; i < x.length; i++){
vertex(x[i], -h/2, z[i]);
}
endShape();
//draw the center of the cylinder
beginShape(QUAD_STRIP);
for(int i=0; i < x.length; i++){
vertex(x[i], -h/2, z[i]);
vertex(x[i], h/2, z[i]);
}
endShape();
//draw the bottom of the cylinder
beginShape(TRIANGLE_FAN);
vertex(0, h/2, 0);
for(int i=0; i < x.length; i++){
vertex(x[i], h/2, z[i]);
}
endShape();
}
}