An infinite set that with zero lengthWe're now going to use Java to implement some classic examples of fractal geometry. We'll do three of these. We begin with a one-dimensional set with an infinite number of points that covers zero length. Then we'll investigate the Koch snowflake. Finally in the next chapter we'll delve into the most famous fractal of all, the Mandelbrot set.The middle third set is defined by starting with all the real numbers between zero and one inclusive. Then we cut out the middle third of that set (exclusive of the endpoints). i.e. everything between one third and two thirds exclusive. Next we cut the middle third of the two line segments that remain, i.e. everything between one ninth and two ninths and between seven ninths and eight ninths. We continue this process indefinitely. Was that confusing? Good. A picture is worth a thousand words and a good Java program is worth a thousand pictures. We now proceed to show you a Java program that draws successive pictures to demonstrate the middle third set. import java.applet.Applet; import java.awt.*; import java.util.Vector; public class MiddleThird extends Applet { int Applet; int Applet; Vector endpoints = new Vector(); public void init() { Dimension d = size(); Applet = d.; Applet = d.; endpoints.addElement(new Float(0.0f)); endpoints.addElement(new Float(1.0f)); } public void paint(Graphics g) { float x1, x2; Float tempFloat; for (int i = 0; i < Applet; i+= 5) { // draw the lines for (int j=0; j < endpoints.size(); j += 2) { tempFloat = (Float) endpoints.elementAt(j); x1 = tempFloat.floatValue(); tempFloat = (Float) endpoints.elementAt(j+1); x2 = tempFloat.floatValue(); g.drawLine( Math.round(x1*Applet), i, Math.round(x2*Applet), i); } //remove the middle third of the lines CutSegments(); // Now check to see if we've exceeded the resolution of our screen tempFloat = (Float) endpoints.elementAt(0); x1 = tempFloat.floatValue(); tempFloat = (Float) endpoints.elementAt(1); x2 = tempFloat.floatValue(); if (Math.round(x1*Applet) == Math.round(x2*Applet)) break; } } private void CutSegments() { int index = 0; float gap; float x1, x2; Float tempFloat1, tempFloat2; int stop = endpoints.size(); for (int i=0; i < stop; i+=2) { CutMiddleThird(index, index+1); index += 4; } } private void CutMiddleThird(int left, int right) { float gap; float x1, x2; Float tempFloat1, tempFloat2; tempFloat1 = (Float) endpoints.elementAt(left); tempFloat2 = (Float) endpoints.elementAt(right); gap = tempFloat2.floatValue() - tempFloat1.floatValue(); x1 = tempFloat1.floatValue() + gap/3.0f; x2 = tempFloat2.floatValue() - gap/3.0f; endpoints.insertElementAt(new Float(x2), right); endpoints.insertElementAt(new Float(x1), right); } } Compile and load this applet. Is that clearer? Of course this isn't a perfect representation of the middle third set since we have to deal with points of finite size rather than with genuine mathematical points. Depending on how large a window you give your applet, you will probably only see about six to twelve iterations before we need to start working with fractional pixels.
|
Bhopal news
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