Libraryless. Click here for Pure Java version (1538L/8K).
// adapted for Java from https://codepen.io/tculda/pen/pogwpOw sclass MultiPointGradient is MakesBufferedImage { LPair<DoublePt, Color> gradientPoints; int w, h; int[] pixels; double[] gradientPointArray; Color[] colors; bool hasRun; *(LPair<DoublePt, Color> *gradientPoints, int *w, int *h) {} *(int *w, int *h, LPair<DoublePt, Color> *gradientPoints) {} public int getWidth() { ret w; } public int getHeight() { ret h; } public BufferedImage getBufferedImage() { this.run(); ret intArrayToBufferedImageWithoutAlpha(pixels, w, h); } void init { if (pixels == null) pixels = new int[w*h]; if (gradientPointArray == null) gradientPointArray = doublePtsToDoubleArray(pairsA(gradientPoints)); if (colors == null) colors = toArray Color(pairsB(gradientPoints)); } run { if (hasRun) ret; set hasRun; init(); int n = l(colors); double[] colorRatios = new[n]; int iPixel = 0; for y to h: for x to w: { fillArray(colorRatios, 1); for i to n: for j to n: if (i != j) { var d = getProjectionDistance2( gradientPointArray[i*2], gradientPointArray[i*2+1], gradientPointArray[j*2], gradientPointArray[j*2+1], x, y); colorRatios[i] *= clampZeroToOne(d); } pixels[iPixel++] = blendMultipleColorsToInt(colors, colorRatios); } } } do not include function getWidth. do not include function getHeight. do not include function get. do not include function set. !include early #1034869 // Include for exporting Java code
Began life as a copy of #1034865
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034870 |
Snippet name: | MultiPointGradient for export |
Eternal ID of this version: | #1034870/8 |
Text MD5: | 4b8b892c297294494fc0797e22e910d8 |
Transpilation MD5: | b9e3a08432737cd766a3c5055cb8a5f1 |
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 22:55:37 |
Source code size: | 1717 bytes / 61 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 713 / 862 |
Version history: | 7 change(s) |
Referenced in: | -