-
Notifications
You must be signed in to change notification settings - Fork 2
/
DEMO_RT.pde
111 lines (91 loc) · 3.15 KB
/
DEMO_RT.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
108
109
110
111
/* This is a sub-sketch that draws in a PGraphics ( demo_rt ),
* instead of drawing in the viewport.
* Do not forget that this code is part of FlatMapper class,
* be sure not to overwrite methods or parameters.
* To achieve a basic level of security, all parameters and
* methods here have been prefixed with 'demo_rt'.
* 'update_demo_rt()' have to be called explicitly in
* FlatMapper.draw().
*/
/* Image used as texture in the mapping.
*/
PGraphics demo_rt;
/* Thumbnail for the configuration panel.
* Generated by calling texture_thumb( demo_rt )
* after the first update.
*/
PImage demo_thumb;
int demo_rt_pts = 4;
float demo_rt_angle = 0;
float demo_rt_radius = 99;
float demo_rt_length = 95;
PVector demo_rt_vertices[][];
boolean demo_rt_isPyramid = false;
float demo_rt_angleInc = PI/300.0;
void setup_demo_rt() {
demo_rt = createGraphics( 1024, 1024, P3D );
demo_rt_radius = demo_rt.width/5;
demo_rt_length = demo_rt.width/6;
demo_thumb = null;
}
void update_demo_rt() {
demo_rt.beginDraw();
demo_rt_pts = int( 10 + sin( frameCount * 0.03 ) * 7 );
demo_rt_radius = demo_rt.width / ( 10 + sin( frameCount * 0.063421 ) * 8 );
demo_rt.background(
128 + sin( frameCount * 0.02 ) * 100,
128 + sin( frameCount * 0.01089 ) * 100,
128 + sin( frameCount * 0.024 ) * 100);
demo_rt.lights();
demo_rt.fill(255, 200, 200);
demo_rt.translate(demo_rt.width/2, demo_rt.height/2);
demo_rt.rotateX(frameCount * demo_rt_angleInc);
demo_rt.rotateY(frameCount * demo_rt_angleInc);
demo_rt.rotateZ(frameCount * demo_rt_angleInc);
// initialize vertex arrays
demo_rt_vertices = new PVector[2][demo_rt_pts+1];
// fill arrays
for (int i = 0; i < 2; i++){
demo_rt_angle = 0;
for(int j = 0; j <= demo_rt_pts; j++){
demo_rt_vertices[i][j] = new PVector();
if (demo_rt_isPyramid){
if (i==1){
demo_rt_vertices[i][j].x = 0;
demo_rt_vertices[i][j].y = 0;
}
else {
demo_rt_vertices[i][j].x = cos(radians(demo_rt_angle)) * demo_rt_radius;
demo_rt_vertices[i][j].y = sin(radians(demo_rt_angle)) * demo_rt_radius;
}
}
else {
demo_rt_vertices[i][j].x = cos(radians(demo_rt_angle)) * demo_rt_radius;
demo_rt_vertices[i][j].y = sin(radians(demo_rt_angle)) * demo_rt_radius;
}
demo_rt_vertices[i][j].z = demo_rt_length;
// the .0 after the 360 is critical
demo_rt_angle += 360.0/demo_rt_pts;
}
demo_rt_length *= -1;
}
// draw cylinder tube
demo_rt.beginShape(QUAD_STRIP);
for(int j = 0; j <= demo_rt_pts; j++){
demo_rt.vertex(demo_rt_vertices[0][j].x, demo_rt_vertices[0][j].y, demo_rt_vertices[0][j].z);
demo_rt.vertex(demo_rt_vertices[1][j].x, demo_rt_vertices[1][j].y, demo_rt_vertices[1][j].z);
}
demo_rt.endShape();
//draw cylinder ends
for (int i = 0; i < 2; i++){
demo_rt.beginShape();
for(int j = 0; j < demo_rt_pts; j++){
demo_rt.vertex(demo_rt_vertices[i][j].x, demo_rt_vertices[i][j].y, demo_rt_vertices[i][j].z);
}
demo_rt.endShape(CLOSE);
}
demo_rt.endDraw();
if ( demo_thumb == null ) {
demo_thumb = texture_thumb( demo_rt );
}
}