-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphicBuilder.java
49 lines (42 loc) · 1.47 KB
/
GraphicBuilder.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
/*
*Author @Kurt Kelly
*
*Published February 26th, 2019
*/
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class GraphicBuilder extends JPanel {
private final int WIDTH = 800;
private final int HEIGHT = WIDTH;
private int lengthOfPixel;
private StringToHexadecimalGraphic Converter;
/**Constuctor gets necessary methods from JPanel object and variables from,
*object 'StringToHexadecimalGraphic'
*
*@params 'StringToHexadecimalGraphic' object
*/
public GraphicBuilder(StringToHexadecimalGraphic Converter) {
super();
this.Converter = Converter;
lengthOfPixel = WIDTH/Converter.getNumOfPixels();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D rectangle = (Graphics2D) g;
for(int i = 0; i < Converter.getColorsInHex().size(); i++)
System.out.println(Converter.getColorsInHex().get(i));
for(int y = 0; y < Converter.getNumOfPixels(); y++)
for(int x = 0; x < Converter.getNumOfPixels(); x++) {
if(y*Converter.getNumOfPixels()+x>=Converter.getColorsInHex().size())
rectangle.setColor(Color.WHITE);
else rectangle.setColor(Color.decode(Converter.getColorsInHex().get(y*Converter.getNumOfPixels()+x)));
rectangle.fillRect(x*lengthOfPixel, y*lengthOfPixel, lengthOfPixel, lengthOfPixel);
}
}
public int getSizeOfGraphic() {
return HEIGHT;
}
}