Skip to content

Commit

Permalink
Re-optimized blending algorithms, release version 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidArthurCole committed Jul 23, 2021
1 parent 346da43 commit e8ca3e4
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions src/main/java/com/Blend.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,19 @@ public static String blendTwo(String hexOne, String hexTwo, String input){
float hexTwoGVal = Integer.parseInt(hexTwo.substring(2, 4),16);
float hexTwoBVal = Integer.parseInt(hexTwo.substring(4, 6),16);

/* //Adjusts the length so that steps are calculated with no spaces
int adjLength = 0;
for(int i = 0; i < input.length(); i++){
if(!input.substring(i, i+1).equals(" ")) adjLength++;
} */

//Calculates the amount of steps to take
float steps = (input.length() - 1);

//Vars for holding result colors
float resRed;
float resGreen;
float resBlue;

//Loop through each step
for(float j = 0; j <= steps; j++){
for(float j = 0; j <= (input.length() - 1); ++j){

//Calculate what percentage of the color should be faded
float percent = (j / steps);

//Add that fade to the result color
resRed = hexOneRVal + Math.round(percent * (hexTwoRVal - hexOneRVal));
resGreen = hexOneGVal + Math.round(percent * (hexTwoGVal - hexOneGVal));
resBlue = hexOneBVal + Math.round(percent * (hexTwoBVal - hexOneBVal));
float percent = (j / (input.length() - 1));

//Add leading zeros to all gex values
StringBuilder resRHex = new StringBuilder(padWithZeros(Integer.toHexString((int)resRed)));
//Combine into one
StringBuilder hexToAdd = new StringBuilder(
padWithZeros(Integer.toHexString((int)hexOneRVal + Math.round(percent * (hexTwoRVal - hexOneRVal))))
+ padWithZeros(Integer.toHexString((int)hexOneGVal + Math.round(percent * (hexTwoGVal - hexOneGVal))))
+ padWithZeros(Integer.toHexString((int)hexOneBVal + Math.round(percent * (hexTwoBVal - hexOneBVal)))));

StringBuilder resBHex = new StringBuilder(padWithZeros(Integer.toHexString((int)resBlue)));

StringBuilder resGHex = new StringBuilder(padWithZeros(Integer.toHexString((int)resGreen)));

StringBuilder hexToAdd = new StringBuilder(resRHex.toString() + resGHex.toString() + resBHex.toString());

//If the character isn't a space, append the code and the value
if(input.charAt((int)j) != ' '){
output.append("&#" + hexToAdd.toString().toUpperCase() + Character.toString(input.charAt((int)j)));
}
//Else, append a space
else output.append(" ");
output.append("&#" + hexToAdd.toString().toUpperCase() + Character.toString(input.charAt((int)j)));
}

return output.toString();
Expand Down

0 comments on commit e8ca3e4

Please sign in to comment.