pragma solidity ^0.4.24; // pragma experimental ABIEncoderV2; contract A { string [] private colors = [ "#C91619","#BE1C24","#D03718","#EB4B11","#D4501E", "#C54514","#E16503","#F98400","#F4A000","#F9AB00", "#A87C2A","#DC9A0F","#DCA215","#A49F4F","#51222F", "#E3C7AC","#E9E2C0","#F6C103","#E5BC00","#EBCC2A", "#33762F","#309153","#44C073","#35A066","#00BB70", "#49C293","#41B797","#0F7963","#589286","#02ACA5", "#008C36","#0085C6","#1E95BB","#7098B7","#3E84BB", "#3979AC","#87B3D7","#4385BF","#23507F","#416D9B", "#6D97CE","#7A95C8","#B2BEE5","#4E4973","#584098", "#9986A5","#D063A6","#CB7788","#E1B8B9","#C98D92", "#D98E8E","#C67E81","#C4999D" ]; function stringToUint(string _amount) internal constant returns (uint result) { bytes memory b = bytes(_amount); uint i; uint counterBeforeDot; uint counterAfterDot; result = 0; uint totNum = b.length; totNum--; bool hasDot = false; for (i = 0; i < b.length; i++) { uint c = uint(b[i]); if (c >= 48 && c <= 57) { result = result * 10 + (c - 48); counterBeforeDot ++; totNum--; } if(c == 46){ hasDot = true; break; } } if(hasDot) { for (uint j = counterBeforeDot + 1; j < 18; j++) { uint m = uint(b[j]); if (m >= 48 && m <= 57) { result = result * 10 + (m - 48); counterAfterDot ++; totNum--; } if(totNum == 0){ break; } } } if(counterAfterDot < 18){ uint addNum = 18 - counterAfterDot; uint multuply = 10 ** addNum; return result = result * multuply; } return result; } function substring(string str, uint startIndex, uint endIndex) internal view returns (string) { bytes memory strBytes = bytes(str); bytes memory result = new bytes(endIndex-startIndex); for(uint i = startIndex; i < endIndex; i++) { result[i-startIndex] = strBytes[i]; } return string(result); } function uintToString(uint v) constant returns (string str) { uint maxlength = 100; bytes memory reversed = new bytes(maxlength); uint i = 0; while (v != 0) { uint remainder = v % 10; v = v / 10; reversed[i++] = byte(48 + remainder); } bytes memory s = new bytes(i + 1); for (uint j = 0; j <= i; j++) { s[j] = reversed[i - j]; } str = string(s); } function shadeColor(string str, uint256 percent) public view returns (string){ // uint percent = 80; uint256 R = stringToUint(substring(str,1,3)); uint256 G = stringToUint(substring(str,3,5)); uint256 B = stringToUint(substring(str,5,7)); R = R * (100 + (percent/100) / 100); G = G * (100 + (percent/100) / 100); G = G * (100 + (percent/100) / 100); R = (R<255)?R:255; G = (G<255)?G:255; B = (B<255)?B:255; string memory RR = uintToString(R); string memory GG = uintToString(G); string memory BB = uintToString(B); string memory output = string(abi.encodePacked('#',RR,GG,BB)); return output; } }
0.7.0