-
Notifications
You must be signed in to change notification settings - Fork 0
/
PuzzleBox.pde
44 lines (37 loc) · 911 Bytes
/
PuzzleBox.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
Board board;
int boardSize = 4;
String imagePath = "./apple.jpg";
void settings() {
size(800, 800);
}
void setup() {
board = new Board(boardSize);
String[] args = new String[] {"Helper"};
Helper helper = new Helper(loadImage(imagePath), 400, 400);
PApplet.runSketch(args,helper);
}
void mousePressed() {
board.click(mouseX, mouseY);
}
void keyPressed() {
if (key == 'r' || key == 'R') {
board.shuffle();
}
}
void draw() {
board.show();
}
PImage[] processImage(String path) {
int size = boardSize * boardSize;
int blockwidth = width / boardSize;
PImage[] result = new PImage[size];
PImage img = loadImage(path);
img.resize(width, height);
for (int j = 0; j < boardSize; ++j) {
for (int i = 0; i < boardSize; ++i) {
int idx = j * boardSize + i;
result[idx] = img.get(i * blockwidth, j * blockwidth, blockwidth, blockwidth);
}
}
return result;
}