-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.pde
More file actions
172 lines (147 loc) · 5.15 KB
/
Square.pde
File metadata and controls
172 lines (147 loc) · 5.15 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
COMP 3490 Fall 2022
Assignment 3
Tara Boulanger
7922331
Square
This is the file containing the code to create each of the individual
squares within a grid. Whether it's textured or just a random color.
*/
public class Square {
final float MAX_EDGE = width/20; //Size of it
//Top left of the square
int x;
int y;
int z;
//Colors needed for drawing each square
color fillColor;
color shadeColor;
//Texture stuff
int textureType;
PImage texture;
//Constructor taking in the position of the square, the fill and shade
//color of the square for the random grid.
Square ( int x, int y, color fillColor, color shadeColor, int z ) {
this.x = x;
this.y = -y;
this.fillColor = fillColor;
this.z = z;
this.shadeColor = shadeColor;
}//end constructor
//Constructor taking in the position of the square, the fill and shade
//color of the square for the texture grid.
Square ( int x, int y, int z, PImage texture ) {
this.x = x;
this.y = -y;
this.z = z;
this.texture = texture;
}//end constructor
//Used for drawing the square in 2D. Takes in nothing, returns nothing.
//It'll either draw with a texture or without one.
void drawSquare2D() {
if ( !doTextures ) {
beginShape(QUAD);
strokeWeight(0);
fill(fillColor);
vertex(x, y); //Top left
vertex(x+MAX_EDGE, y); //Top right
vertex(x+MAX_EDGE, y-MAX_EDGE); //Bottom right
vertex(x, y-MAX_EDGE); //Bottom left
endShape();
} else {
image( texture, x, y-MAX_EDGE, MAX_EDGE, MAX_EDGE );
}//end if-else
}//end draw
//Used for drawing the square in 3D. Takes in nothing, returns nothing.
//It'll either draw with a texture or without one. It'll draw the
//columns accordingly as well.
void drawSquare3D() {
if ( !doTextures ) {
beginShape(QUAD);
fill(fillColor);
vertex(x, y, z); //Top left
vertex(x+MAX_EDGE, y, z); //Top right
vertex(x+MAX_EDGE, y-MAX_EDGE, z); //Bottom right
vertex(x, y-MAX_EDGE, z); //Bottom left
endShape();
} else {
//Needs to be translated in order to show at the right position
push();
translate(0, 0, z);
image( texture, x, y-MAX_EDGE, MAX_EDGE, MAX_EDGE );
pop();
}//end if-else
//Different column modes, textured or just shades
if ( !doTextures ) {
drawColumns();
} else {
drawColumnTextures();
}//end if-else
}//end draw
//Used for drawing the columns of the square without textures. Takes in nothing, returns nothing.
void drawColumns() {
beginShape(QUAD);
fill(shadeColor);
vertex(x+MAX_EDGE, y-MAX_EDGE, z); //Top right of column
vertex(x+MAX_EDGE, y-MAX_EDGE, FAR); //Bottom right of column
vertex(x, y-MAX_EDGE, FAR); //Bottom left of column
vertex(x, y-MAX_EDGE, z); //Top left of column
endShape();
beginShape(QUAD);
fill(shadeColor);
vertex(x+MAX_EDGE, y-MAX_EDGE, z); //Top left of column
vertex(x+MAX_EDGE, y-MAX_EDGE, FAR); //Bottom left of column
vertex(x+MAX_EDGE, y, FAR); //Bottom right of column
vertex(x+MAX_EDGE, y, z); //Top right of column
endShape();
beginShape(QUAD);
fill(shadeColor);
vertex(x, y-MAX_EDGE, z); //Top right of column
vertex(x, y-MAX_EDGE, FAR); //Bottom right of column
vertex(x, y, FAR); //Bottom left of column
vertex(x, y, z); //Top left of column
endShape();
beginShape(QUAD);
fill(shadeColor);
vertex(x, y, z); //Top right of column
vertex(x, y, FAR); //Bottom right of column
vertex(x+MAX_EDGE, y, FAR); //Bottom left of column
vertex(x+MAX_EDGE, y, z); //Top left of column
endShape();
}//end drawColumns
//Used for drawing the columns of the square with textures. Takes in nothing, returns nothing.
void drawColumnTextures() {
beginShape();
texture(texture);
vertex(x+MAX_EDGE, y-MAX_EDGE, z, 1, 0); //Top right of column
vertex(x+MAX_EDGE, y-MAX_EDGE, FAR, 1, 1); //Bottom right of column
vertex(x, y-MAX_EDGE, FAR, 0, 1); //Bottom left of column
vertex(x, y-MAX_EDGE, z, 0, 0); //Top left of column
endShape();
beginShape();
texture(texture);
vertex(x+MAX_EDGE, y-MAX_EDGE, z, 0, 0); //Top left of column
vertex(x+MAX_EDGE, y-MAX_EDGE, FAR, 0, 1); //Bottom left of column
vertex(x+MAX_EDGE, y, FAR, 1, 1); //Bottom right of column
vertex(x+MAX_EDGE, y, z, 1, 0); //Top right of column
endShape();
beginShape();
texture(texture);
vertex(x, y-MAX_EDGE, z, 1, 0); //Top right of column
vertex(x, y-MAX_EDGE, FAR, 1, 1); //Bottom right of column
vertex(x, y, FAR, 0, 1); //Bottom left of column
vertex(x, y, z, 0, 0); //Top left of column
endShape();
beginShape();
texture(texture);
vertex(x, y, z, 1, 0); //Top right of column
vertex(x, y, FAR, 1, 1); //Bottom right of column
vertex(x+MAX_EDGE, y, FAR, 0, 1); //Bottom left of column
vertex(x+MAX_EDGE, y, z, 0, 0); //Top left of column
endShape();
}//end drawColumnTextures
//Used for moving the location of the square. Takes in the y value to move it by, returns nothing.
void moveSquare ( int moveY ) {
y += moveY;
}//end moveSquare
}//end Square class