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

15
LINES

< > BotCompany Repo | #1034859 // blendMultipleColors

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

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

1  
static Color blendMultipleColors(LPair<Color, Double> colors) {
2  
  double sum = doubleSum(pairsB(colors))*255;
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 new Color(
12  
    (float) clampZeroToOne(doubleRatio(r, sum)),
13  
    (float) clampZeroToOne(doubleRatio(g, sum)),
14  
    (float) clampZeroToOne(doubleRatio(b, sum)));
15  
}

Author comment

Began life as a copy of #1007920

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1034859
Snippet name: blendMultipleColors
Eternal ID of this version: #1034859/3
Text MD5: c0b4af3bc23123db91b673b742aeef9c
Transpilation MD5: 46271e52090222bf0e58604bd657e28b
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:22:37
Source code size: 469 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 69 / 116
Version history: 2 change(s)
Referenced in: [show references]