-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
58 lines (47 loc) · 1.54 KB
/
Copy pathBlock.java
File metadata and controls
58 lines (47 loc) · 1.54 KB
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
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.awt.event.*;
public class Block{
private int val;
private BufferedImage img;
public Block(int val){
this(val,70);
}
public Block(int val, int rectSize){
img = new BufferedImage(80,80,BufferedImage.TYPE_INT_RGB);
Graphics2D g = img.createGraphics();
//add rectangle background to image
Shape rect = new Rectangle(40-rectSize/2,40-rectSize/2, rectSize,rectSize);
g.draw(rect);
if (val == 0){
g.setColor(Color.LIGHT_GRAY);
g.fill(rect);
} else{
int variant = (int) Math.log(val);
g.setColor(new Color(Math.max(255-variant*30,0),Math.min(255,variant*25),Math.min(variant*45,255)));
g.fill(rect);
//draw number
g.setColor(Color.BLACK);
g.setFont(new Font("Hiragino Kaku Gothic Pro", Font.PLAIN, 30));
if (val < 10){
g.drawString(val+"",31,50);
} else if (val < 100){
g.drawString(val+"",20,50);
} else if (val < 1000) {
g.drawString(val+"",10,50);
} else {
g.setFont(new Font(null, Font.BOLD, 25));
g.drawString(val+"",8,50);
}
}
g.dispose();
this.val = val;
}
public int getValue(){
return val;
}
public BufferedImage getImage(){
return img;
}
}