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

33
LINES

< > BotCompany Repo | #1034866 // blendMultipleColorsToInt

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5431L/30K).

1  
static int blendMultipleColorsToInt(LPair<Color, Double> colors) {
2  
  double sum = doubleSum(pairsB(colors));
3  
  double r = 0, g = 0, b = 0;
4  
  
5  
  for (color, weight : unpair colors) {
6  
    r += color.getRed()*weight;
7  
    g += color.getGreen()*weight;
8  
    b += color.getBlue()*weight;
9  
  }
10  
  
11  
  ret rgbInt(
12  
    roundedRatio(r, sum),
13  
    roundedRatio(g, sum),
14  
    roundedRatio(b, sum));
15  
}
16  
17  
static int blendMultipleColorsToInt(Color[] colors, double[] weights) {
18  
  double sum = doubleSum(weights);
19  
  double r = 0, g = 0, b = 0;
20  
  
21  
  for i over colors: {
22  
    Color color = colors[i];
23  
    double weight = weights[i];
24  
    r += color.getRed()*weight;
25  
    g += color.getGreen()*weight;
26  
    b += color.getBlue()*weight;
27  
  }
28  
  
29  
  ret rgbInt(
30  
    roundedRatio(r, sum),
31  
    roundedRatio(g, sum),
32  
    roundedRatio(b, sum));
33  
}

Author comment

Began life as a copy of #1034859

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034866
Snippet name: blendMultipleColorsToInt
Eternal ID of this version: #1034866/5
Text MD5: 7d2a0d95dcf7b8bd768ad99373b2ad11
Transpilation MD5: 61f775f13df16faf753e7beecb48fd23
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-12 20:40:34
Source code size: 840 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 142 / 211
Version history: 4 change(s)
Referenced in: [show references]