Created
February 8, 2020 08:10
-
-
Save enebo/f01f0606326bb5c4a38984d21a4691f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| java_import java.awt.image.BufferedImage | |
| java_import javax.swing.JFrame | |
| class Mandelbrot < JFrame | |
| MAX_ITER = 570; | |
| ZOOM = 150.0; | |
| def initialize | |
| super("Mandelbrot Set") | |
| setBounds(100, 100, 800, 600); | |
| setResizable(false); | |
| setDefaultCloseOperation(EXIT_ON_CLOSE); | |
| @image = BufferedImage.new(getWidth(), getHeight(), BufferedImage::TYPE_INT_RGB); | |
| height.times do |y| | |
| width.times do |x| | |
| zx = 0.0; | |
| zy = 0.0; | |
| cX = (x - 400) / ZOOM; | |
| cY = (y - 300) / ZOOM; | |
| iter = MAX_ITER; | |
| while (zx * zx + zy * zy < 4 && iter > 0) | |
| tmp = zx * zx - zy * zy + cX | |
| zy = 2.0 * zx * zy + cY | |
| zx = tmp | |
| iter -= 1 | |
| end | |
| @image.setRGB(x, y, iter | (iter << 8)) | |
| end | |
| end | |
| end | |
| def paint(g) | |
| g.drawImage(@image, 0, 0, self); | |
| end | |
| end | |
| Mandelbrot.new.setVisible(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment