Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.image.BufferStrategy;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.io.*;
- public class Application extends Thread {
- private Frame frame;
- private Fractal fractal;
- private BufferStrategy buffer;
- private int x;
- private int y;
- public Application(int x, int y, Frame frame, Fractal fractal, BufferStrategy buffer, int priority)
- {
- this.frame = frame;
- this.fractal = fractal;
- this.buffer = buffer;
- this.x = x;
- this.y = y;
- setPriority(priority);
- start();
- }
- public static void main(String args[]) {
- InputStreamReader Stream = new InputStreamReader(System.in);
- BufferedReader buffer_console = new BufferedReader(Stream);
- int[] priority_data = new int[10];
- System.out.print("[Priorytety animacji fraktali 1 - 10]\n");
- for (int j = 0; j < 10; j++) {
- System.out.print("Priorytet animacji #" + (j + 1) + ": ");
- priority_data[j] = setInteger(buffer_console);
- }
- Frame frame = new Frame("Aplikacja");
- Fractal fractal = new Fractal();
- Fractal fractal2 = new Fractal();
- BufferStrategy buffer = frame.getBufferStrategy();
- //for (int j = 0; j < 10; j++) {
- for (int i = 0; i < 1001; i += 250) {
- fractal = new Fractal();
- fractal.setA(((250 + i) / 250));
- new Application(i, 0, frame, fractal, buffer, priority_data[((250 + i) / 250) - 1]);
- fractal2 = new Fractal();
- fractal2.setA(((250 + i) / 250) + 5);
- new Application(i, 250, frame, fractal2, buffer, priority_data[((250 + i) / 250) + 3]);
- }
- //}
- }
- public void run()
- {
- if (this.buffer == null) {
- this.frame.createBufferStrategy(1);
- this.buffer = this.frame.getBufferStrategy();
- }
- Graphics graphic_new = buffer.getDrawGraphics();
- while (true) {
- graphic_new.setColor(Color.WHITE);
- graphic_new.clearRect(this.x, this.y, 250, 250);
- graphic_new.fillRect(this.x, this.y, 250, 250);
- graphic_new.setColor(Color.GREEN);
- this.fractal.begin(graphic_new, this.x, this.y);
- try {
- Application.sleep(500);
- this.buffer.show();
- } catch (InterruptedException error) { error.printStackTrace(); }
- }
- }
- public static int setInteger(BufferedReader buffer_console)
- {
- int value = 0;
- try {
- value = Integer.parseInt(buffer_console.readLine());
- } catch(IOException error) {
- error.printStackTrace();
- System.exit(0);
- }
- return value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement