-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenger_fractal_sponge.pde
50 lines (43 loc) · 1.24 KB
/
menger_fractal_sponge.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
int numberOfHoles;
PVector rotationAngle;
ArrayList<Box> spongeBoxes;
public void setup()
{
size(800, 750, P3D);
rotationAngle = new PVector(0, 0, 0);
spongeBoxes = new ArrayList<Box>();
spongeBoxes.add(new Box(new PVector(0, 0, 0), new PVector(200, 200, 200)));
}
public void draw()
{
background(51);
lights();
textSize(20);
fill(225, 175, 60);
text("Menger Fractal Sponge", 10, 30);
fill(225);
text("Wikipedia Link: ", 10, 60);
fill(0, 105, 205);
text("https://en.wikipedia.org/wiki/Menger_sponge", 15 + textWidth("Wikipedia Link: "), 60);
fill(225);
text("Number of holes: ", 10, 90);
fill(225, 0, 0);
text(numberOfHoles, 15 + textWidth("Number of holes: "), 90.5f);
translate(width / 2, height / 2 + 100);
rotateX(rotationAngle.x);
rotateY(rotationAngle.y);
rotateZ(rotationAngle.z);
for (Box spongeBox : spongeBoxes)
spongeBox.Update();
rotationAngle = new PVector(rotationAngle.x + 0.01f, rotationAngle.y + 0.01f, rotationAngle.z + 0.01f);
}
public void mousePressed()
{
ArrayList<Box> smallerBoxes = new ArrayList<Box>();
for (Box spongeBox : spongeBoxes)
{
ArrayList<Box> tempSmallerBoxes = spongeBox.OnBoxClicked();
smallerBoxes.addAll(tempSmallerBoxes);
}
spongeBoxes = smallerBoxes;
}