Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 108 lines (84 sloc) 1.953 kB
0e64507 initial
Max Henstell authored
1 class Pixel
2 {
3 float x;
4 float y;
5 float z;
6 float w;
7 float h;
8 int sides;
513ad3b @mhenstell almost working test sign
authored
9 color c;
0e64507 initial
Max Henstell authored
10
513ad3b @mhenstell almost working test sign
authored
11 float DEFAULT_WIDTH = 3;
12 float DEFAULT_HEIGHT = 10;
13 int DEFAULT_SIDES = 20;
14
15 public Pixel(float x_, float y_, float z_, float w_, float h_, int sides_) {
0e64507 initial
Max Henstell authored
16 x = x_;
17 y = y_;
18 z = z_;
19 w = w_;
20 h = h_;
21 sides = sides_;
22 }
23
513ad3b @mhenstell almost working test sign
authored
24 public Pixel(int x_, int y_) {
25 x = int(x_);
26 y = int(y_);
27 w = DEFAULT_WIDTH;
28 h = DEFAULT_HEIGHT;
29 sides = DEFAULT_SIDES;
30 c = color(255, 255, 255);
31 }
32
239b349 @mhenstell works
authored
33 public Pixel(int x_, int y_, float h_) {
34 x = int(x_);
35 y = int(y_);
36 w = DEFAULT_WIDTH;
37 h = h_;
38 sides = DEFAULT_SIDES;
39 c = color(255, 255, 255);
40 }
41
0e64507 initial
Max Henstell authored
42 void draw() {
513ad3b @mhenstell almost working test sign
authored
43 fill(c);
0e64507 initial
Max Henstell authored
44
45 pushMatrix();
513ad3b @mhenstell almost working test sign
authored
46 translate(x * 10, 0, y * 10);
0e64507 initial
Max Henstell authored
47 cylinder(w, h, sides);
48 popMatrix();
49
50 }
51
513ad3b @mhenstell almost working test sign
authored
52 void update(color c_) {
53 c = c_;
239b349 @mhenstell works
authored
54
513ad3b @mhenstell almost working test sign
authored
55 }
56
0e64507 initial
Max Henstell authored
57 /**
58 cylinder taken from http://wiki.processing.org/index.php/Cylinder
59 @author matt ditton
60 */
61
62 void cylinder(float w, float h, int sides)
63 {
64 float angle;
65 float[] x = new float[sides+1];
66 float[] z = new float[sides+1];
67
68 //get the x and z position on a circle for all the sides
69 for(int i=0; i < x.length; i++){
70 angle = TWO_PI / (sides) * i;
71 x[i] = sin(angle) * w;
72 z[i] = cos(angle) * w;
73 }
74
75 //draw the top of the cylinder
76 beginShape(TRIANGLE_FAN);
77
78 vertex(0, -h/2, 0);
79
80 for(int i=0; i < x.length; i++){
81 vertex(x[i], -h/2, z[i]);
82 }
83
84 endShape();
85
86 //draw the center of the cylinder
87 beginShape(QUAD_STRIP);
88
89 for(int i=0; i < x.length; i++){
90 vertex(x[i], -h/2, z[i]);
91 vertex(x[i], h/2, z[i]);
92 }
93
94 endShape();
95
96 //draw the bottom of the cylinder
97 beginShape(TRIANGLE_FAN);
98
99 vertex(0, h/2, 0);
100
101 for(int i=0; i < x.length; i++){
102 vertex(x[i], h/2, z[i]);
103 }
104
105 endShape();
106 }
107 }
Something went wrong with that request. Please try again.