import java.awt.*; import java.awt.image.*; import javax.imageio.*; import java.io.*; /* Autore : Marco 'RootkitNeo' Descrizione: Classe che si occupa della creazione del frattale Dipendenza : http://pastebin.com/jfTDFE8W */ class Fractal { // Variabili // ----------------------------------------------------------------------------------------------------------- private Image img; // Frattale private double X0,X1, Y0, Y1, modulo, x, y; // [X0,Y0][X0,Y1] punti luce; modulo: valore temporaneo abs(); x,y valori temporanei pixel immagine private int cicli,profondita, width, height; // profondita: dettaglio immagine private Complex c1, c2; // Numeri complessi // ----------------------------------------------------------------------------------------------------------- Fractal(int width, int height, double X0, double X1, double Y0, double Y1, int profondita) { this.width = width; this.height= height; this.X0 = X0; this.X1 = X1; this.Y0 = Y0; this.Y1 = Y1; this.profondita = profondita; } void generaFrattale() { int[] pixels = new int[width*height]; int k = 0; img = null; for(int i=0; i 4.0) break; } if(modulo<=4.0) { pixels[k++] = (255 << 24) | 0; } else { int r, g, b; r = (cicli>>2); g = (cicli>>1); b = 10+(cicli<<2); r = (r>128) ? 128 : r; g = (g>128) ? 128 : g; b = (b>255) ? 255 : b; pixels[k++] = (255 << 24) | (r << 16) | (g << 8) | b; } } } try { Toolkit tk = Toolkit.getDefaultToolkit(); img = tk.createImage(new MemoryImageSource(width, height,pixels,0,width)); } catch(Exception e) { e.printStackTrace(); } } void salvaImmagine(String name) { if(img == null) return; BufferedImage b = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB); Graphics g = b.getGraphics(); try { g.drawImage(img.getScaledInstance(width,height,Image.SCALE_SMOOTH),0,0,null); ImageIO.write(b,"PNG",new File(name+".png")); } catch(Exception e) {e.printStackTrace();} } Image getImage() { return img; } }