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

30
LINES

< > BotCompany Repo | #1020194 // Names Of Colors

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (17746L/133K).

1  
!7
2  
3  
concept ColorName {
4  
  S color, name, comment;
5  
}
6  
7  
module ColorNames > DynCRUD<ColorName> {
8  
  *() { super(ColorName); }
9  
  
10  
  start {
11  
    onConceptsChangeAndNow(r { setModuleName("Names Of Colors (" + countConcepts(ColorName) + ")") });
12  
  }
13  
  
14  
  // API
15  
  
16  
  void addColorName(Color color, S name, S comment) {
17  
    uniq_sync(ColorName, color := colorToHex(color), +name, +comment);
18  
  }
19  
  
20  
  S getClosestColorName(Color color) {
21  
    ret pairA(getClosestColor(color));
22  
  }
23  
  
24  
  Pair<S, Double> getClosestColor(Color color) {
25  
    new Lowest<S> best;
26  
    for (ColorName cn)
27  
      best.put(cn.name, colorDiff(color, colorFromHex(cn.color)));
28  
    ret pair(best!, best.score());
29  
  }
30  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020194
Snippet name: Names Of Colors
Eternal ID of this version: #1020194/9
Text MD5: daaa9385bd0f78cf024370d9a661e3d4
Transpilation MD5: ac981d1f83cf012c344cfe7f74adc891
Author: stefan
Category: javax / stefan's os / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-13 17:34:42
Source code size: 706 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 314 / 1702
Version history: 8 change(s)
Referenced in: [show references]