Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

25
LINES

< > BotCompany Repo | #1006906 // makeClickPuzzle

JavaX fragment (include)

1  
static Puzzle makeClickPuzzle(S instruction, L<RGBImage> images, L<Rect> solutions) {
2  
  ret makeClickPuzzle(instruction, null, images, solutions);
3  
}
4  
5  
static Puzzle makeClickPuzzle(S instruction, S nullAnswer,
6  
  L<RGBImage> images, L<Rect> solutions) {
7  
  // select image
8  
  int i = random(l(images));
9  
  RGBImage mainImage = images.get(i);
10  
  Rect solution = solutions.get(i);
11  
  
12  
  Rect clip;
13  
  if (solution != null) {
14  
    // select random portion
15  
    clip = selectRandomPartContaining(mainImage, solution, w, h);
16  
    solution = translateRect(solution, -clip.x, -clip.y);
17  
  } else {
18  
    clip = selectRandomPart(mainImage, w, h);
19  
    if (clip == null) fail("No fit: " + w + "/" + h + " vs " + mainImage.w() + "/" + mainImage.h());
20  
  }
21  
  RGBImage img = mainImage.clip(clip);
22  
  
23  
  // return puzzle
24  
  ret new Puzzle(instruction, nullAnswer, img, llNonNulls(solution));
25  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006906
Snippet name: makeClickPuzzle
Eternal ID of this version: #1006906/5
Text MD5: d6e2f0907b6dc059f2f03666a9dd21b0
Author: stefan
Category: javax / a.i. games
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-03 01:46:04
Source code size: 886 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 438 / 441
Version history: 4 change(s)
Referenced in: [show references]