-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderThread.java
67 lines (57 loc) · 1.77 KB
/
RenderThread.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.awt.image.BufferedImage;
import java.nio.file.Path;
public class RenderThread implements Runnable {
public Thread t;
public final Path cwd;
public final String tName;
// private BufferedImage img;
public final int width, height;
private int startX, endX, startY, endY;
private FractalRenderer controller;
public RenderThread(Path currentworkingdirectory, String threadName, BufferedImage i, int width, int height, FractalRenderer fr){
System.out.println("Thread created");
cwd = currentworkingdirectory;
tName = threadName;
// img = i;
this.width = width;
this.height = height;
controller = fr;
}
@Override
public void run() {
// System.out.println(tName + " Running"); //debug
threadRender();
}
public void start(){
// System.out.println(tName + " Starting"); //debug
if(t == null){
t = new Thread(this, tName);
t.start();
}else{
run();
}
}
public void threadRender(){
do{
// System.out.println("Thread " + t.getName() + " rendering"); //debug
for(int x = startX; x < endX; x++){
for(int y = startY; y < endY; y++){
controller.setPixel(x, y);
}
}
// System.out.println("Thread " + t.getName() + " finished rendering"); //debug
}while(controller.startNextSection(this));
}
public void setStartX(int x){
startX = x;
}
public void setEndX(int x){
endX = x;
}
public void setStartY(int y){
startY = y;
}
public void setEndY(int y){
endY = y;
}
}