Source Code Cross Referenced for MandelbrotPlot.java in  » Science » JSci » examples » Chaos » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » JSci » examples.Chaos 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        import java.applet.*;
002:        import java.awt.*;
003:        import java.awt.event.*;
004:        import java.awt.image.MemoryImageSource;
005:        import JSci.maths.Complex;
006:        import JSci.maths.chaos.*;
007:
008:        /**
009:         * Plot of the Mandelbrot set.
010:         * @author Mark Hale
011:         * @version 1.1
012:         */
013:        public final class MandelbrotPlot extends Applet {
014:            private final int colorTable[] = new int[22];
015:            private final int range[] = { 1, 10, 20, 30, 40, 50, 60, 70, 80,
016:                    90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };
017:            private final int N = 2000;
018:            private Image mandelbrotImage;
019:            private Image imageBuffer;
020:
021:            /**
022:             * Initialise the applet.
023:             */
024:            public void init() {
025:                // create colour palette
026:                for (int i = 0; i < colorTable.length; i++)
027:                    colorTable[i] = grey(255 - 10 * i);
028:                // draw Mandelbrot set to an image buffer
029:                mandelbrotImage = drawMandelbrot();
030:                // mouse listener
031:                addMouseListener(new MouseAdapter() {
032:                    public void mouseClicked(MouseEvent evt) {
033:                        if (imageBuffer == mandelbrotImage) {
034:                            final int width = getSize().width;
035:                            final int height = getSize().height;
036:                            final Complex z = new Complex(evt.getX() * 3.0
037:                                    / width - 2.0, 1.25 - evt.getY() * 2.5
038:                                    / height);
039:                            imageBuffer = drawJulia(z);
040:                            System.err.println(z.toString());
041:                            showStatus("Click to return to Mandelbrot set");
042:                        } else {
043:                            imageBuffer = mandelbrotImage;
044:                            showStatus("Click to generate a Julia set");
045:                        }
046:                        repaint();
047:                    }
048:                });
049:            }
050:
051:            public void start() {
052:                imageBuffer = mandelbrotImage;
053:                showStatus("Click to generate a Julia set");
054:            }
055:
056:            public void paint(Graphics g) {
057:                g.drawImage(imageBuffer, 0, 0, this );
058:            }
059:
060:            private Image drawMandelbrot() {
061:                final int width = getSize().width;
062:                final int height = getSize().height;
063:                final MandelbrotSet set = new MandelbrotSet();
064:                double x, y;
065:                int pixels[] = new int[width * height];
066:                int index = 0;
067:                for (int j = 0; j < height; j++) {
068:                    for (int i = 0; i < width; i++) {
069:                        x = i * 3.0 / width - 2.0;
070:                        y = 1.25 - j * 2.5 / height;
071:                        pixels[index++] = colorLookup(set.isMember(x, y, N));
072:                    }
073:                }
074:                return createImage(new MemoryImageSource(width, height, pixels,
075:                        0, width));
076:            }
077:
078:            private Image drawJulia(Complex z) {
079:                final int width = getSize().width;
080:                final int height = getSize().height;
081:                final JuliaSet set = new JuliaSet(z);
082:                double x, y;
083:                int pixels[] = new int[width * height];
084:                int index = 0;
085:                for (int j = 0; j < height; j++) {
086:                    for (int i = 0; i < width; i++) {
087:                        x = i * 4.0 / width - 2.0;
088:                        y = 1.25 - j * 2.5 / height;
089:                        pixels[index++] = colorLookup(set.isMember(x, y, N));
090:                    }
091:                }
092:                return createImage(new MemoryImageSource(width, height, pixels,
093:                        0, width));
094:            }
095:
096:            /**
097:             * Returns a RGBA value.
098:             */
099:            private int colorLookup(int n) {
100:                if (n == 0) {
101:                    return 0xff000000; // black
102:                } else {
103:                    for (int i = 0; i < range.length - 1; i++) {
104:                        if (n >= range[i] && n < range[i + 1])
105:                            return colorTable[i];
106:                    }
107:                    return 0xffffffff; // white
108:                }
109:            }
110:
111:            /**
112:             * Returns a grey RGBA value.
113:             */
114:            private static int grey(int n) {
115:                return 0xff000000 | n << 16 | n << 8 | n;
116:            }
117:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.