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 uintToString(uint _i) internal pure returns (string memory _uintAsString) { if (_i == 0) { return "0"; } uint j = _i; uint len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (_i != 0) { bstr[k--] = byte(uint8(48 + _i % 10)); _i /= 10; } return string(bstr); } 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); B = B * (100 + (percent/100) / 100); if (R<255){ R = R;} else R=255; if (G<255){ G = G;} else G=255; if (B<255){ B = B;} else B=255; string memory RR = uintToString(R); string memory GG = uintToString(G); string memory BB = uintToString(B); if (RR.length=1) {RR=abi.encodePacked(0,RR);} else RR=RR; if (GG.length=1) {GG=abi.encodePacked(0,GG);} else GG=GG; if (BB.length=1) {BB=abi.encodePacked(0,BB);} else BB=BB; string memory output = string(abi.encodePacked('#',RR,GG,BB)); return output; } } library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
0.4.2