⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 juliaframe.java

📁 通过线程控制来打印出julia集
💻 JAVA
字号:
import java.awt.*;public class JuliaFrame {	// PARAMETERS TO THE SYSTEM - PLEASE CHANGE THESE TO SUIT YOUR SYSTEM	// This is this number of threads created to put data into the input buffer	// Alter this number to suit your system	public final static int NO_OF_DATA_GENERATORS = 200;// 20	// This is the number of threads initially created by the ThreadController	// to	// process data in the input buffer	public final static int NO_OF_INITIAL_THREADS = 200;// 20	// This is the number of iterations used to calculate whether a point lies	// in the Julia Set. Increase this for more accuracy in calculations at the	// expense of speed	public final static int NO_OF_ITERATIONS = 16;	// This is the delay (in milliseconds) between changes in the value of K	// which causes a new Julia Set to be calculated.	public final static int KDELAY = 9000;//30000	// This is the delay (in milliseconds) between samples of the input Data	// Buffer	// to check its size.	public final static int THREAD_MONITOR_DELAY = 300;//500	// This is the delay (in milliseconds) between starting the thread	// controller	// and the data generators	public final static int INITIALISATION_DELAY = 1000;//5000	// Image size - make this smaller to make the program run faster	// or make it larger to improve resolution of image	public final static int ImageWidth = 400;// 200	public final static int ImageHeight = 350;// 150	// initial default values of K - change these to start with a different	// Julia Set	public final static double K_RE_DEFAULT = 0.353;// 0.353	public final static double K_IM_DEFAULT = 0.288;// 0.288	// PARAMETERS TO THIS SYSTEM WHICH YOU SHOULDN'T NEED TO CHANGE	public final static int NO_OF_COLOURS = 8;	// Region of the complex plane represented in the drawing area	public final static double MinRe = -2.0;	public final static double MaxRe = 2.0;	public final static double MinIm = -1.6;	public final static double MaxIm = 1.6;	// Gui compents used outside of main method	static Label displayLabel;	static Label Kre;	static Label Kim;	public static void main(String[] args) {		// Create the GUI		Frame juliaFrame = new Frame("Julia");		juliaFrame.setSize(ImageWidth + 50, ImageHeight + 150);		juliaFrame.addWindowListener(new CloseExit());		Canvas juliaCanvas = new Canvas();		juliaCanvas.setSize(ImageWidth, ImageHeight);		juliaCanvas.setBackground(Color.white);		juliaFrame.add(juliaCanvas, BorderLayout.CENTER);		Panel displayLabelPanel = new Panel();		displayLabelPanel.setLayout(new BorderLayout());		displayLabel = new Label("Active Threads: ");		displayLabel.setBackground(new Color(230, 230, 230));		displayLabelPanel.add(displayLabel, BorderLayout.NORTH);		Kre = new Label("K real: " + K_RE_DEFAULT);		Kre.setBackground(new Color(230, 230, 230));		displayLabelPanel.add(Kre, BorderLayout.CENTER);		Kim = new Label("K imag: " + K_IM_DEFAULT);		Kim.setBackground(new Color(230, 230, 230));		displayLabelPanel.add(Kim, BorderLayout.SOUTH);		juliaFrame.add(displayLabelPanel, BorderLayout.SOUTH);		juliaFrame.setVisible(true);		Graphics canvasGraphics = juliaCanvas.getGraphics();		draw(NO_OF_INITIAL_THREADS, NO_OF_INITIAL_THREADS);		// Create the colours for drawing the Julia Sets		// Please feel free to change these to suit your tastes		Color[] colours = new Color[NO_OF_COLOURS];		colours[0] = Color.white;		colours[1] = new Color(255, 160, 60);		colours[2] = new Color(230, 140, 50);		colours[3] = new Color(200, 120, 40);		colours[4] = new Color(170, 100, 30);		colours[5] = new Color(140, 80, 20);		colours[6] = new Color(110, 60, 10);		colours[7] = new Color(80, 40, 0);		// Create the System Objects		DataBuffer displayBuffer = new DataBuffer();		DataBuffer inputBuffer = new DataBuffer();		// Arbitrary starting value of K		Complex K = new Complex(K_RE_DEFAULT, K_IM_DEFAULT);		JuliaCalc juliaCalc = new JuliaCalc(ImageWidth, ImageHeight, K);		new Thread(new ThreadController(inputBuffer, displayBuffer, juliaCalc))				.start();		// allow a delay for starting the ThreadController and its threads		try {			Thread.sleep(INITIALISATION_DELAY);		} catch (InterruptedException e) {		}		// You can comment this line out to test before you have written		// KCHANGER		new Thread( new KChanger(K) ).start();		DataGenerator[] dataGenerators = new DataGenerator[NO_OF_DATA_GENERATORS];		Thread dataGeneratorThread;		for (int i = 0; i < NO_OF_DATA_GENERATORS; i++) {			dataGenerators[i] = new DataGenerator(ImageWidth, ImageHeight,					inputBuffer);			dataGeneratorThread = new Thread(dataGenerators[i]);			dataGeneratorThread.start();		}		// Main loop: fetch calculated DataPackets from the displayBuffer and		// draw them on the display area in the appropriate colour		DataPacket dataPacket;		while (true) {			dataPacket = displayBuffer.get();			canvasGraphics.setColor(colours[dataPacket.col]);			canvasGraphics.drawRect(dataPacket.X, dataPacket.Y, 1, 1);		}	}	// public method to be called by the ThreadController to update the display	// labels	// It should always be called with two integer arguments where `active'	// represents	// the number of currently active threads and	// `total' represents the total number of threads created.	public static void draw(int i, int j) {		displayLabel.setText("Active threads: " + i + " / " + j);	}	// public method called by KChanger to display the current value of the	// parameter K	public static void drawK(double r, double i) {		Kre.setText("K real: " + r);		Kim.setText("K imag: " + i + "i");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -