-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExamples.java
More file actions
134 lines (112 loc) · 3.58 KB
/
Examples.java
File metadata and controls
134 lines (112 loc) · 3.58 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import com.github.afkbrb.avatar.Avatar;
import com.github.afkbrb.avatar.AvatarConfig;
import com.github.afkbrb.avatar.util.ImageExhibitor;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
public class Examples {
public static void main(String[] args) {
showExample();
//saveExample("E:/avatar.png");
//sizeConfigExample();
//cellCountConfigExample();
//transparentConfigExample();
//singleColorConfigExample();
//multiColorConfigExample1();
//multiColorConfigExample2();
}
/**
* Show default avatar.
*/
public static void showExample() {
Avatar avatar = new Avatar();
avatar.showAvatar();
}
/**
* Save avatar.
* @param filepath where to save the avatar
*/
public static void saveExample(String filepath) {
Avatar avatar = new Avatar();
avatar.saveAsPNG(filepath);
}
/**
* Set padding and cell size.
*/
public static void sizeConfigExample() {
AvatarConfig config = new AvatarConfig();
config.setPadding(16);
config.setCellSize(32);
Avatar avatar = new Avatar(config);
avatar.showAvatar();
}
/**
* Set the number of cells per row / column.
*/
public static void cellCountConfigExample() {
AvatarConfig config = new AvatarConfig();
config.setCellCount(8);
Avatar avatar = new Avatar(config);
avatar.showAvatar();
}
/**
* Set the avatar transparent.
*/
public static void transparentConfigExample() {
AvatarConfig config = new AvatarConfig();
config.setTransparent(true);
Avatar avatar = new Avatar(config);
avatar.showAvatar();
}
/**
* Set color.
*/
public static void singleColorConfigExample() {
AvatarConfig config = new AvatarConfig();
config.setForeColor(Color.MAGENTA);
// config.setBackColor(Color.LIGHT_GRAY);
Avatar avatar = new Avatar(config);
avatar.showAvatar();
}
/**
* Set foreground colors.
* Final color will be chosen at random in the given array.
*/
public static void multiColorConfigExample1() {
AvatarConfig config = new AvatarConfig();
config.setForeColors(Color.MAGENTA, Color.BLUE, Color.GREEN);
Avatar avatar = new Avatar(config);
multiImageExhibitor(avatar, config.getCellSize(), config.getCellSize(), 6);
}
/**
* Set foreground colors.
* Final color will be chosen at random in the given list.
*/
public static void multiColorConfigExample2() {
AvatarConfig config = new AvatarConfig();
List<Color> colors = new ArrayList<>();
colors.add(Color.YELLOW);
colors.add(Color.ORANGE);
colors.add(Color.CYAN);
config.setForeColors(colors);
Avatar avatar = new Avatar(config);
multiImageExhibitor(avatar, config.getCellSize(), config.getCellSize(), 6);
}
/**
* Tool for showing multi images together.
* @param avatar
* @param width
* @param height
* @param n
*/
public static void multiImageExhibitor(Avatar avatar,int width, int height, int n) {
BufferedImage image = new BufferedImage(n * width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
for(int i = 0; i < n; i++) {
g.drawImage(avatar.generateAndGetAvatar(), i * width, 0, width, height, null);
}
g.dispose();
ImageExhibitor.showImage(image);
}
}