-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelpScreenEasing.pde
83 lines (73 loc) · 2.11 KB
/
HelpScreenEasing.pde
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
public class HelpScreenEasing extends Screen {
private int frameWidth = 120;
private int frameHeight = 90;
private int spacing = 8;
private int margin = width/8;
private PGraphics[] frames;
HelpScreenEasing() {
frames = new PGraphics[Animation.interpolationNamesSimp.length];
int i = 0;
for (String interpolationName : Animation.interpolationNamesSimp) {
Interpolation fn = Animation.getInterpolation(interpolationName);
frames[i++] = createInterpolationFrame(frameWidth, frameHeight, fn, interpolationName);
}
}
PGraphics createInterpolationFrame(int w, int h, Interpolation fn, String name) {
PGraphics pg = createGraphics(w, h);
pg.beginDraw();
pg.background(#FFC500);
float prev = h * (0.8f * fn.apply(0f) + 0.1f);
float val;
float penX;
float stepX = 2f;
pg.stroke(0);
for (penX=stepX; penX<w; penX+=stepX) {
val = h * (0.8f * fn.apply(penX/w) + 0.1f);
pg.line(penX-stepX, h-prev, penX, h-val);
prev = val;
}
val = h * (0.8f * fn.apply(1f) + 0.1f);
pg.line(penX-stepX, h-prev, w, h-val);
pg.fill(0, 127);
pg.textFont(defaultFontSmall);
pg.text(name, w-pg.textWidth(name)-4, h-4);
pg.endDraw();
return pg;
}
@Override
public void draw() {
background(255);
fill(100);
textFont(titleFont);
int offset = floor(textWidth("Easing functions"));
text("Easing functions", (width/2)-offset/2, -20+height/6);
int posX = margin;
int posY = height/5;
for (PGraphics frame : frames) {
image(frame, posX, posY);
posX += frameWidth + spacing;
if (posX + frameWidth + spacing > width-margin) {
posX = margin;
posY += frameHeight + spacing;
}
}
}
@Override
void keyPressed(KeyEvent event) {
if (avatar != null) {
mainScreen.showUI();
currentScreen = mainScreen;
} else {
currentScreen = welcomeScreen;
}
}
@Override
void mouseClicked(MouseEvent event) {
if (avatar != null) {
mainScreen.showUI();
currentScreen = mainScreen;
} else {
currentScreen = welcomeScreen;
}
}
}