文件 1 的 1:mytest.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
function fromHex(string memory c) internal pure returns (uint256) {
string memory s1 = Strings.substr(c,0,1);
string memory s2 = Strings.substr(c,1,2);
uint a;
uint b;
if (bytes1(bytes(s1)) >= bytes1('0') && bytes1(bytes(s1)) <= bytes1('9')) {
a = strToUint(s1);
}
if (bytes1(bytes(s1)) >= bytes1('a') && bytes1(bytes(s1)) <= bytes1('f')) {
a = 10 + uint256(uint8(bytes1(bytes(s1)))) - uint256(uint8(bytes1('a')));
}
if (bytes1(bytes(s2)) >= bytes1('0') && bytes1(bytes(s2)) <= bytes1('9')) {
b = strToUint(s2);
}
if (bytes1(bytes(s2)) >= bytes1('a') && bytes1(bytes(s2)) <= bytes1('f')) {
b = 10 + uint256(uint8(bytes1(bytes(s2)))) - uint256(uint8(bytes1('a')));
}
return b + 16 * a;
}
function toString(uint256 value) internal pure returns (string memory) {
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);
}
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, 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 Strings.substr(string(buffer), 2,4);
}
function strToUint(string memory s) internal pure returns (uint256) {
bytes memory b = bytes(s);
uint256 result = 0;
for (uint256 i = 0; i < b.length; i++) {
if (b[i] >= 0x30 && b[i] <= 0x39) {
result = result * 10 + (uint(uint8((b[i]))) - 48);
}
}
return result;
}
function substr(
string memory str,
uint256 startIndex,
uint256 endIndex
) internal pure returns (string memory) {
bytes memory strBytes = bytes(str);
bytes memory result = new bytes(endIndex - startIndex);
for (uint256 i = startIndex; i < endIndex; i++) {
result[i - startIndex] = strBytes[i];
}
return string(result);
}
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_setOwner(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
interface IERC721Metadata is IERC721 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);
}
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) private pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
string private _name;
string private _symbol;
mapping(uint256 => uint256) public scenes;
mapping(uint256 => address) private _owners;
mapping(address => uint256) private _balances;
mapping(uint256 => address) private _tokenApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
function _baseURI() internal view virtual returns (string memory) {
return "";
}
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
if (_balances[to] < 10) {
scenes[tokenId] = _balances[to];
} else {
scenes[tokenId] = uint256(keccak256(abi.encodePacked(string(abi.encodePacked(MLB.t(tokenId)))))) % 10;
}
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
interface IERC721Enumerable is IERC721 {
function totalSupply() external view returns (uint256);
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
function tokenByIndex(uint256 index) external view returns (uint256);
}
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
mapping(uint256 => uint256) private _ownedTokensIndex;
uint256[] private _allTokens;
mapping(uint256 => uint256) private _allTokensIndex;
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId;
_ownedTokensIndex[lastTokenId] = tokenIndex;
}
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId;
_allTokensIndex[lastTokenId] = tokenIndex;
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
contract GMGN is ERC721Enumerable, ReentrancyGuard, Ownable {
using Strings for string;
using MLB for *;
uint256 public constant MINT_PRICE = 30000000000000000;
uint256 public constant MAX_PER_TX = 10;
uint256 public MAX_TOKENS = 5000;
bool public saleIsActive = true;
string[] public TYPES = [
"sunrise",
"day",
"dayClouds",
"sunset",
"nightStars"
"nightCres",
"nightMoon",
"mars",
"marsSunset",
"halloween"
];
function getScene(uint tokenId) public view returns (string memory) {
require(tokenId < totalSupply(), "Scene not minted yet.");
uint lp = scenes[tokenId];
MLB.chartCoords memory cr;
MLB.layerSettings memory ls;
MLB.layout memory out;
MLB.colorSettings memory cs;
MLB.draw memory d;
uint[13] memory rands = MLB.getRand(tokenId, lp);
cr.sx = 0;
cr.sy = 5050;
cr.x = cr.sx;
cr.xold = cr.x;
cr.n = 12;
cr.xstep = 40 * 12 / cr.n;
cr.y = [cr.sy, cr.sy, cr.sy, cr.sy, cr.sy];
cr.yold = [cr.sy, cr.sy, cr.sy, cr.sy, cr.sy];
cr.sunOffset = rands[10] % 101;
ls.kHighs = [10, 7, 5, 4, 3];
ls.maxHighs = [80, 100, 140, 160, 200];
ls.probMove = [6,5,4,4,4];
ls.moveThres = [4,5,5,5,5];
ls.layersAmount = 2 + rands[11] % 4;
if (lp == 9 && ls.layersAmount > 3) ls.layersAmount = 3;
if (lp == 3 && ls.layersAmount < 4) ls.layersAmount = 4;
cs.delta[0] = 0; cs.delta[1] = 0; cs.delta[2] = 0;
cs.delta[rands[6] % 3] = 5 + rands[7] % 8;
out.o = "";
out.pathCloud = "";
out.paths = ["", "", "", "", ""];
for (uint i = 0; i < cr.n; i++) {
cr.x += cr.xstep;
for (uint k = 0; k < ls.layersAmount; k++) {
d.move = Strings.strToUint(Strings.substr(MLB.t(rands[k]), i, i + 1));
d.direction = d.move > ls.moveThres[k] ? 1 : 0;
if (i == cr.n - 2) d.direction = 0;
d.offset = 20 + k * 10 + k * 5 * (1+d.move % 4);
if (i == 0) {
cr.y[k] = cr.y[k] - d.offset;
cr.yold[k] = cr.y[k];
out.paths[k] = string(abi.encodePacked(out.paths[k], " L", MLB.t(cr.sx), ",", MLB.t(cr.y[k])));
}
if (d.direction > 0) {
cr.y[k] = cr.y[k] - (1+d.move % ls.probMove[k]) * ls.kHighs[k];
} else {
cr.y[k] = cr.y[k] + (1+d.move % ls.probMove[k]) * ls.kHighs[k];
}
if (cr.y[k] < cr.sy - ls.maxHighs[k]) cr.y[k] = cr.sy - ls.maxHighs[k];
if (cr.y[k] > cr.sy - d.offset) cr.y[k] = cr.sy - d.offset;
if (i == cr.n - 1) {
cr.y[k] = cr.sy - d.offset;
}
d.flipflag = 1;
d.kflip = 1 + d.move % 3;
d.pointsMax = 4 + d.move % 4;
d.y1old = cr.yold[k];
for (uint j = 1; j <= d.pointsMax; j++) {
d.x1 = cr.xold + (cr.x - cr.xold) / d.pointsMax * j;
if (d.flipflag == 1) {
if (cr.y[k] > cr.yold[k]) {
d.y1 = cr.yold[k] + (cr.y[k] - cr.yold[k]) / d.pointsMax * j + d.kflip * ((d.move * j) % 11 > 4 ? 1 : 0);
} else {
d.y1 = cr.yold[k] - (cr.yold[k] - cr.y[k]) / d.pointsMax * j + d.kflip * ((d.move * j) % 11 > 4 ? 1 : 0);
}
} else {
if (cr.y[k] > cr.yold[k]) {
d.y1 = cr.yold[k] + (cr.y[k] - cr.yold[k]) / d.pointsMax * j - d.kflip * ((d.move * j) % 11 > 4 ? 1 : 0);
} else {
d.y1 = cr.yold[k] - (cr.yold[k] - cr.y[k]) / d.pointsMax * j - d.kflip * ((d.move * j) % 11 > 4 ? 1 : 0);
}
}
if (j < d.pointsMax - 1) {
if (d.flipflag == 1) {
d.flipflag = 0;
} else {
d.flipflag = 1;
}
}
if (d.move > 7 && k < 3) {
if (j < d.pointsMax) {
if (d.direction > 0) {
d.y1 = d.y1 + d.move;
} else {
d.y1 = d.y1 - d.move;
}
}
out.paths[k] = string(abi.encodePacked(out.paths[k], " L",MLB.t(cr.xold + (cr.x - cr.xold) / d.pointsMax * (j-1)),",",MLB.t(d.y1)));
} else {
out.paths[k] = string(abi.encodePacked(out.paths[k], " C", MLB.t(cr.xold + (cr.x - cr.xold) / d.pointsMax * (j-1)),","));
out.paths[k] = string(abi.encodePacked(out.paths[k], MLB.t(d.y1old)," ",MLB.t(d.x1),",",MLB.t(d.y1)," "));
out.paths[k] = string(abi.encodePacked(out.paths[k],MLB.t((cr.xold + (cr.x - cr.xold) / d.pointsMax * (2*j-1)/2)),",",MLB.t((d.y1+d.y1old)/2)));
}
d.y1old = d.y1;
}
if (i == cr.n - 1) {
out.paths[k] = string(abi.encodePacked(out.paths[k], " L",MLB.t(cr.x),",",MLB.t(cr.y[k])," L",MLB.t(cr.x),",",MLB.t(cr.sy)));
}
cr.yold[k] = cr.y[k];
}
cr.xold = cr.x;
d.move = rands[5];
d.direction = d.move > 4 ? 1 : 0;
if (lp == 2) {
if (i == 0) {
d.yc = cr.sy - 200;
} else if(i == cr.n - 1) {
d.yc = cr.sy - 200;
} else {
if (d.direction > 0) {
d.yc = cr.sy - 200 - (d.move%3) * 30;
} else {
d.yc = cr.sy - 200 + (d.move%3) * 30;
}
if (d.yc < cr.sy - 300) d.yc = cr.sy - 300;
if (d.yc > cr.sy) d.yc = cr.sy + 50;
}
} else {
if (i == 0) {
d.yc = cr.sy - 100;
} else if(i == cr.n - 1) {
d.yc = cr.sy - 100;
} else {
if (d.direction > 0) {
d.yc = cr.sy - 100 - (d.move%7) * 20;
} else {
d.yc = cr.sy - 100 + (d.move%7) * 20;
}
if (d.yc < cr.sy - 300) d.yc = cr.sy - 300;
if (d.yc > cr.sy) d.yc = cr.sy + 50;
}
}
out.pathCloud = string(abi.encodePacked(out.pathCloud," L",MLB.t(cr.x),",",MLB.t(d.yc)));
}
cs.fillopacity = "30%";
if (lp == 2 || lp == 0 || lp == 3 || lp == 8 ) cs.fillopacity = "10%";
if (lp >= 0 && lp <= 9) out.o = string(abi.encodePacked(MLB.getLP(tokenId, lp, cs, cr, ls)));
out.o = string(abi.encodePacked(out.o,'<filter id="farBlur"><feGaussianBlur stdDeviation="2"/></filter><filter id="farBlur2"><feGaussianBlur stdDeviation="1"/></filter>'));
if (ls.layersAmount == 4) out.o = string(abi.encodePacked(out.o, '<path d="M',MLB.t(cr.sx),',',MLB.t(cr.sy),out.paths[4],' z" stroke="none" fill-opacity="',cs.fillopacity,'%" fill="url(#gradient5)" filter="url(#farBlur)"></path>'));
if (ls.layersAmount >= 3) out.o = string(abi.encodePacked(out.o, '<path d="M',MLB.t(cr.sx),',',MLB.t(cr.sy),out.paths[3],' z" stroke="none" fill="url(#gradient4)" filter="url(#farBlur2)"></path>'));
if (ls.layersAmount >= 2) out.o = string(abi.encodePacked(out.o, '<path d="M',MLB.t(cr.sx),',',MLB.t(cr.sy),out.paths[2],' z" stroke="none" fill="url(#gradient3)"></path>'));
if (lp == 2) {
out.o = string(abi.encodePacked(out.o, '<filter id="clouds2" height="300%" width="200%" x="-50%" y="-100%"><feTurbulence type="fractalNoise" baseFrequency=".05" numOctaves="10" /><feDisplacementMap in="SourceGraphic" scale="120" result="cloud"/><feGaussianBlur in="cloud" stdDeviation="8" /></filter>'));
out.o = string(abi.encodePacked(out.o, '<path d="M',MLB.t(cr.sx),',',MLB.t(cr.sy-200),out.pathCloud,' L',MLB.t(cr.sx),',',MLB.t(cr.sy-200),' z" stroke="#000" filter="url(#clouds2)" fill="#888" fill-opacity="40%"><animateMotion dur="240s" repeatCount="indefinite" path="M0,0 L480,0 L0,0z" /></path>'));
} else {
out.o = string(abi.encodePacked(out.o, '<filter id="clouds" height="1000%" width="400%" x="-200%" y="-500%"><feTurbulence type="fractalNoise" baseFrequency=".005" numOctaves="10" /><feDisplacementMap in="SourceGraphic" scale="240" result="cloud"/><feGaussianBlur in="cloud" stdDeviation="15" /></filter>'));
out.o = string(abi.encodePacked(out.o, '<path d="M',MLB.t(cr.sx),',',MLB.t(cr.sy-100),out.pathCloud,' L',MLB.t(cr.sx),',',MLB.t(cr.sy-100),' z" stroke="#000" filter="url(#clouds)" fill="#fff" fill-opacity="30%"><animateMotion dur="180s" repeatCount="indefinite" path="M0,0 L480,0 L0,0z" /></path>'));
}
if (ls.layersAmount >= 1) out.o = string(abi.encodePacked(out.o, '<path d="M',MLB.t(cr.sx),',',MLB.t(cr.sy),out.paths[1],' z" stroke="none" fill="url(#gradient2)"></path>'));
out.o = string(abi.encodePacked(out.o, '<path d="M',MLB.t(cr.sx),',',MLB.t(cr.sy),out.paths[0],' z" stroke="none" fill="url(#gradient1)" ></path>'));
return string(abi.encodePacked('<svg id="lps" xmlns="http://www.w3.org/2000/svg" viewBox="0 4750 480 300"><style>text { font-family: arial }.t{font-size: 10px; fill: #adadad}.at{font-size: 10px; fill:#f6cb27} rect { width:10px; stroke: none}</style><rect x="0" y="4750" style="width:480px;height:100%;fill:url(#lsstyle',MLB.t(lp),'); stroke:none"/>',out.o,'</svg>'));
}
function tokenURI(uint256 tokenId) override public view returns (string memory) {
require(tokenId < totalSupply(), "Scene not minted yet.");
string memory o = getScene(tokenId);
string memory json = Base64.encode(bytes(string(abi.encodePacked('{"name": "Mountains #', MLB.t(tokenId), '", "description": "5000 beautiful animated mountain views. Generated and stored completely on-chain. No IPFS.", "image": "data:image/svg+xml;base64,', Base64.encode(bytes(o)), '"}'))));
o = string(abi.encodePacked('data:application/json;base64,', json));
return o;
}
function flipSaleState() external onlyOwner {
saleIsActive = !saleIsActive;
}
function mint(uint256 amount) external nonReentrant payable {
require(saleIsActive, "Sale inactive");
require(amount <= MAX_PER_TX, "Mint up to 10 per tx.");
require(totalSupply() + amount <= MAX_TOKENS, "Max supply reached");
require(msg.value >= MINT_PRICE * amount || owner() == _msgSender(), "Try 0.03 eth per scene");
uint256 index;
for (uint256 i = 0; i < amount; i++) {
index = totalSupply();
_safeMint(_msgSender(), index);
}
}
function withdrawFunds() external onlyOwner {
uint balance = address(this).balance;
payable(msg.sender).transfer(balance);
}
constructor() ERC721("On-Chain Mountains", "GMGN") Ownable() {}
}
library MLB {
struct draw {
uint move;
uint direction;
uint offset;
uint flipflag;
uint kflip;
uint pointsMax;
uint y1old; uint y1; uint x1;
uint yc;
}
struct chartCoords {
uint n;
uint sx; uint sy;
uint x; uint xold; uint xstep;
uint[5] y;
uint[5] yold;
uint sunOffset;
}
struct layerSettings {
uint layersAmount;
uint8[5] kHighs;
uint8[5] maxHighs;
uint8[5] probMove;
uint8[5] moveThres;
}
struct layout {
string[5] paths;
string o;
string pathCloud;
}
struct colorSettings{
uint256[3] delta;
string sc;
string sc2;
string offset_canvas;
string bottomcolor;
string fillopacity;
string[6] bc;
}
function getLP(uint tokenId, uint lp, colorSettings memory cs, chartCoords memory cr, layerSettings memory ls) public pure returns (string memory) {
uint[13] memory rands = getRand(tokenId, lp);
string memory dummy;
cs.offset_canvas = "30%";
string memory aer = string(abi.encodePacked('<g transform="translate(100,4720) scale(0.04,0.04)"><path style="fill-opacity:10%" fill="#264823" d="M',t(cr.sx + 150),',',t(cr.sy - 100),'.32c2.97-9.83,9.83-15.37,19.46-18.19c4.14-1.22,9.64-2.21,11.62-5.21c2.09-3.18,0.81-8.63,0.84-13.09c0.06-8.85-0.01-17.71,0.03-26.56c0.04-8.7,3.91-12.62,12.48-12.64c11.97-0.02,23.95,0.08,35.92-0.05c4.3-0.05,7.69,1.34,10.63,4.44c4.97,5.25,10.21,10.26,15.12,15.57c2.06,2.22,3.71,2.7,6.7,1.53c27.01-10.59,53.76-21.94,81.23-31.19c60.14-20.25,115.01-9.4,162.86,32.23c36.03,31.34,34.98,87.11-1.01,118.55c-12.77,11.16-26.8,20.3-42.42,26.93c-2.17,0.92-3.22,2.24-3.86,4.5c-2.9,10.3-5.99,20.56-9.07,30.81c-2.09,6.96-5.32,9.4-12.46,9.4c-27.44,0.02-54.88,0.02-82.31,0c-7.08-0.01-10.41-2.57-12.39-9.49c-3.11-10.89-6.08-21.83-9.36-32.67c-0.48-1.6-2.07-3.44-3.6-4.06c-22.97-9.27-46.04-18.32-69.03-27.55c-2.27-0.91-3.53-0.46-5.11,1.2c-5.05,5.35-10.33,10.49-15.41,15.8c-2.84,2.97-6.12,4.44-10.28,4.41c-12.22-0.1-24.44,0-36.67-0.05c-7.83-0.03-11.91-4.13-11.96-12.06c-0.07-12.47-0.08-24.94,0.03-37.41c0.02-2.46-0.54-3.85-3.08-4.65c-3.55-1.11-6.87-2.98-10.43-4.06c-9.4-2.86-15.83-8.57-18.47-18.2Cz"/><animateMotion dur="1800s" repeatCount="indefinite" path="M0,0 A 600,150 1 0 1 600,100 A 600,150 0 0 1 -600,150z" /></g>'));
if (lp == 0) {
cs.bottomcolor = "#474747";
cs.bc[1] = "#676767";
cs.sc = "#e1866f";
cs.sc2 = "#f7e68c";
for (uint i = 1; i<=4; i++) {
cs.bc[i+1] = rgbTint(cs.bc[i], i, 1);
}
cs.sc = rgbShift(cs.sc, cs.delta[0]*2, cs.delta[1]*2, cs.delta[2]*2, 1);
dummy = string(abi.encodePacked('<filter id="sun"><feGaussianBlur stdDeviation="3"/></filter>', stars(4, cr.sx, cr.sy - 300, cr.sx + 400, cr.sy - 100, tokenId),'<circle r="40" cx="',t(cr.sx + 200 + cr.sunOffset),'" cy="',t(cr.sy - 100),'" filter="url(#sun)" fill-opacity="100%" fill="#ffffaa"><animate attributeName="cy" begin="0s" dur="90s" repeatCount="0" from="',t(cr.sy - 100),'" to ="',t(cr.sy - 150),'" fill="freeze"/><animate attributeName="r" begin="0s" dur="15s" repeatCount="0" from="40" to="34" fill="freeze"/></circle>'));
}
if (lp == 1) {
cs.bottomcolor = "#163042";
cs.bc[1] = "#356382";
cs.sc = "#0487e2";
cs.sc2 = "#afafaf";
cs.bottomcolor = rgbShift(cs.bottomcolor, cs.delta[0], cs.delta[1], cs.delta[2], 1);
cs.bc[1] = rgbShift(cs.bc[1], cs.delta[0], cs.delta[1], cs.delta[2], 1);
for (uint i = 1; i<=4; i++) {
cs.bc[i+1] = rgbTint(cs.bc[i], i, 1);
}
dummy = string(abi.encodePacked('<filter id="sun" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="3"/></filter><circle r="20" cx="',t(cr.sx+100),'" cy="',t(cr.sy-200),'" filter="url(#sun)" fill="#ffffaa"><animateMotion dur="3600s" repeatCount="indefinite" path="M0,0 A 600,150 1 0 1 600,100 A 600,150 0 0 1 -600,150z" /></circle>'));
}
if (lp == 2) {
cs.bottomcolor = "#111111";
cs.bc[1] = "#333333";
cs.sc = "#cccccc";
cs.sc2 = "#8f8f8f";
if (cs.delta[0] > 5) cs.delta[0] -=4;
if (cs.delta[1] > 5) cs.delta[1] -=4;
if (cs.delta[2] > 5) cs.delta[2] -=4;
cs.bottomcolor = rgbShift(cs.bottomcolor, cs.delta[0],cs.delta[1],cs.delta[2], 1);
cs.bc[1] = rgbShift(cs.bc[1], cs.delta[0],cs.delta[1],cs.delta[2], 1);
for (uint i = 1; i<=4; i++) {
cs.bc[i+1] = rgbTint(cs.bc[i], i, 1);
}
dummy = string(abi.encodePacked('<filter id="sun" x="-200%" y="-200%" width="400%" height="400%"><feGaussianBlur stdDeviation="8"/></filter><circle r="20" cx="',t(cr.sx+100),'" cy="',t(cr.sy-200),'" filter="url(#sun)" fill-opacity="60%" fill="#ffffff"><animateMotion dur="3600s" repeatCount="indefinite" path="M0,0 A 600,150 1 0 1 600,100 A 600,150 0 0 1 -600,150z" /></circle>','<circle r="80" cx="',t(cr.sx+100),'" cy="',t(cr.sy-200),'" filter="url(#sun)" fill-opacity="20%" fill="#ffffff"><animateMotion dur="3600s" repeatCount="indefinite" path="M0,0 A 600,150 1 0 1 600,100 A 600,150 0 0 1 -600,150z" /></circle>'));
}
if (lp == 3) {
cs.bottomcolor = "#241818";
cs.bc[1] = "#4d3535";
cs.sc = "#0487e2";
cs.sc2 = "#d44e41";
cs.offset_canvas = "10%";
cs.bc[1] = rgbTint(cs.bc[1], 2, 1);
cs.bc[2] = rgbTint(cs.bc[1], 1, 1);
cs.bc[3] = rgbTint(cs.bc[1], 2, 1);
cs.bc[4] = "#8a5047";
cs.bc[5] = rgbTint(cs.bc[1], 4, 1);
cs.sc = rgbShift(cs.sc, cs.delta[0]*2, cs.delta[1]*2, cs.delta[2]*2, 1);
dummy = string(abi.encodePacked('<filter id="sun"><feGaussianBlur stdDeviation="3"/></filter><linearGradient id="sungrad" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="30%" stop-color="#ffff88"/><stop offset="90%" stop-color="#cf4b3e"/><animate attributeName="y2" begin="0s" dur="90s" repeatCount="0" from="100%" to="0%" fill="freeze"></animate></linearGradient>'));
dummy = string(abi.encodePacked(dummy, stars(6, cr.sx, cr.sy - 300, cr.sx + 400, cr.sy - 150, tokenId),'<circle id="suncircle" r="34" cx="',t(cr.sx + 200 + cr.sunOffset),'" cy="',t(cr.sy - 150),'" filter="url(#sun)" fill-opacity="100%" fill="url(#sungrad)"><animate attributeName="cy" begin="0s" dur="90s" repeatCount="0" from="',t(cr.sy - 150),'" to ="',t(cr.sy - 50),'" fill="freeze"/><animate attributeName="r" begin="0s" dur="15s" repeatCount="0" from="34" to="40" fill="freeze"/></circle>'));
}
if (lp == 4) {
cs.sc = "#000000";
cs.sc2 = "#99a0b4";
cs.bottomcolor = "#272823";
cs.bc[1] = "#292927";
for (uint i = 1; i<=4; i++) {
cs.bc[i+1] = rgbTint(cs.bc[1], i, 1);
}
dummy = string(abi.encodePacked(stars(100, cr.sx, cr.sy-300, cr.sx+400, cr.sy, tokenId)));
}
if (lp == 5) {
cs.sc = "#000000";
cs.sc2 = "#99a0b4";
cs.bottomcolor = "#272823";
cs.bc[1] = "#292927";
for (uint i = 1; i<=4; i++) {
cs.bc[i+1] = rgbTint(cs.bc[1], i, 1);
}
dummy = string(abi.encodePacked('<radialGradient id="half_moon" fx="15%" fy="40%" r="100%" spreadMethod="pad"><stop offset="50%" stop-color="#000"/><stop offset="100%" stop-color="#ffffdd"/></radialGradient>'));
dummy = string(abi.encodePacked(dummy, '<filter id="moon"><feGaussianBlur stdDeviation="1"/></filter>', stars(20, cr.sx, cr.sy - 300, cr.sx + 400, cr.sy, tokenId)));
dummy = string(abi.encodePacked(dummy, '<circle r="20" cx="',t(cr.sx + 100),'" cy="',t(cr.sy - 200),'" filter="url(#moon)" fill-opacity="100%" fill="url(#half_moon)"><animateMotion dur="3600s" repeatCount="indefinite" path="M0,0 A 600,150 1 0 1 600,100 A 600,150 0 0 1 -600,150z" /></circle>'));
}
if (lp == 6) {
cs.sc = "#000000";
cs.sc2 = "#99a0b4";
cs.bottomcolor = "#272823";
cs.bc[1] = "#292927";
for (uint i = 1; i<=4; i++) {
cs.bc[i+1] = rgbTint(cs.bc[1], i, 1);
}
dummy = string(abi.encodePacked('<filter id="moon"><feGaussianBlur stdDeviation="1"/></filter>', stars(20, cr.sx, cr.sy - 300, cr.sx + 400, cr.sy, tokenId)));
dummy = string(abi.encodePacked(dummy, '<circle r="20" cx="',t(cr.sx + 100),'" cy="',t(cr.sy - 200),'" filter="url(#moon)" fill-opacity="100%" fill="#c8c0b9"><animateMotion dur="3600s" repeatCount="indefinite" path="M0,0 A 600,150 1 0 1 600,100 A 600,150 0 0 1 -600,150z" /></circle>'));
}
if (lp == 7) {
cs.bottomcolor = "#413023";
cs.bc[1] = "#754f33";
cs.sc = "#f1e0c4";
cs.sc2 = "#907c55";
cs.bottomcolor = rgbShift(cs.bottomcolor, cs.delta[0], 0, 0, 1);
cs.bc[1] = rgbShift(cs.bc[1], cs.delta[0], 0, 0, 1);
for (uint i = 1; i<=4; i++) {
cs.bc[i+1] = rgbTint(cs.bc[i], i, 1);
}
dummy = string(abi.encodePacked('<filter id="sun" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="2"/></filter><circle r="10" cx="',t(cr.sx + 100),'" cy="',t(cr.sy - 200),'" filter="url(#sun)" fill="#ffffff"><animateMotion dur="3600s" repeatCount="indefinite" path="M0,0 A 600,150 1 0 1 600,100 A 600,150 0 0 1 -600,150z" /></circle>'));
}
if (lp == 8) {
cs.bottomcolor = "#000000";
cs.bc[1] = "#33394d";
cs.sc = "#51698c";
cs.sc2 = "#4d4240";
cs.offset_canvas = "10%";
cs.bc[1] = rgbTint(cs.bc[1], 2, 0);
cs.bc[2] = rgbTint(cs.bc[1], 1, 1);
cs.bc[3] = rgbTint(cs.bc[1], 2, 1);
cs.bc[4] = "#33394d";
cs.bc[5] = rgbTint(cs.bc[1], 4, 1);
dummy = string(abi.encodePacked('<filter id="sun" x="-200%" y="-200%" width="400%" height="400%"><feGaussianBlur stdDeviation="2"/></filter><filter id="sunhalo" x="-200%" y="-200%" width="400%" height="400%"><feGaussianBlur stdDeviation="18"/></filter><ellipse rx="70" ry="100" cx="',t(cr.sx + 200 + cr.sunOffset),'" cy="',t(cr.sy - 120),'" filter="url(#sunhalo)" fill-opacity="50%" fill="#a6b9dc"><animate attributeName="cy" begin="0s" dur="85s" repeatCount="0" from="',t(cr.sy - 120),'" to ="',t(cr.sy - 20),'" fill="freeze"/></ellipse>'));
dummy = string(abi.encodePacked(dummy, '<circle id="suncircle" r="10" cx="',t(cr.sx + 200 + cr.sunOffset),'" cy="',t(cr.sy - 150),'" filter="url(#sun)" fill-opacity="100%" fill="#fff"><animate attributeName="cy" begin="0s" dur="90s" repeatCount="0" from="',t(cr.sy - 150),'" to ="',t(cr.sy - 50),'" fill="freeze"/><animate attributeName="r" begin="0s" dur="15s" repeatCount="0" from="10" to="14" fill="freeze"/></circle>'));
}
if (lp == 9) {
cs.sc = "#000000";
cs.sc2 = "#99a0b4";
cs.bottomcolor = "#000000";
cs.bc[1] = "#4f1511";
cs.bc[2] = rgbTint(cs.bc[1], 1, 1);
cs.bc[3] = rgbTint(cs.bc[1], 2, 1);
dummy = string(abi.encodePacked('<filter x="-200%" y="-200%" width="400%" height="400%" id="pumpkin"><feColorMatrix type="matrix" result="color" values="1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0"></feColorMatrix><feGaussianBlur in="color" stdDeviation="40" result="blur"></feGaussianBlur><feOffset in="blur" dx="0" dy="0" result="offset"></feOffset><feMerge><feMergeNode in="bg"></feMergeNode><feMergeNode in="offset"></feMergeNode><feMergeNode in="SourceGraphic"></feMergeNode></feMerge></filter>',stars(20, cr.sx, cr.sy - 300, cr.sx + 400, cr.sy, tokenId)));
uint trx; uint trxy;
trx = rands[8] % 101;
trxy = 50 + rands[9] % 251;
dummy = string(abi.encodePacked(dummy , '<g transform="translate(100,4700) scale(0.04,0.04)"><animateMotion dur="600s" repeatCount="indefinite" path="M0,0 C',t(trx),',-100 200,',t(trxy),' 200,50 C200-100 20,',t(trxy),' ',t(trx),',50 z" />'));
dummy = string(abi.encodePacked(dummy, '<path filter="url(#pumpkin)" style="stroke:none;fill:#c9782c;" d="M ',t(cr.sx + 400),' ',t(cr.sy - 100),'l-4,13l-4,12l-5,13l-5,12l-5,12l-8,11l-8,11l-8,10l-9,10l-8,11l-8,10l-10,9l-10,10l-10,9l-10,-14l-9,-14l-10,-13l-3,15l-4,15l-3,16l-3,15l-13,3l-13,3l-12,3l-13,2l-13,0l-13,1l-12,-1l-13,-3l-13,-1l-12,-4l-12,-3l-12,-4l-4,-15l-4,-14l-3,-15l-4,-15l-8,13l-7,14l-8,13l-12,-11l-12,-10l-11,-10l-10,-13l-10,-12l-10,-12l-8,-14l-8,-14l-7,-14l-5,-14l-6,-15l-6,-15l13,9l14,8l13,8l14,7l15,5l14,7l3,14l3,13l3,14l3,14l7,-11l8,-10l7,-11l6,-11l14,2l13,3l13,2l13,2l13,1l14,1l13,0l14,0l13,-1l13,-1l14,-2l13,-1l13,-4l13,-3l14,-1l9,13l9,14l9,14l4,-14l2,-13l3,-14l3,-13l13,-8l14,-7l13,-9l14,-7l13,-9l13,-9zm-420,-94l8,-20l11,-19l14,-15l15,-16l12,17l13,16l12,16l13,15l15,14l13,15l15,14l-22,3l-21,0l-21,0l-21,-2l-21,-5l-21,-5l-20,-8zm9,-66l8,-12l10,-13l9,-12l10,-10l6,-4l9,17l9,12l9,12l9,11l9,12l10,12l11,12l11,11l10,12l1,2l-1,-1l-13,-11l-13,-10l-12,-11l-9,-9l-9,-9l-9,-9l-6,-6l-9,-13l-11,-12l-13,9l-12,11l-15,11zm147,124l11,4l11,1l10,3l11,1l11,-2l10,-4l11,-3l10,-4l9,-5l-12,17l-9,18l-10,18l-8,18l-8,19l-10,-18l-11,-17l-11,-17l-12,-17l-12,-16zm102,-39l12,-16l13,-16l12,-16l12,-16l11,-17l10,-18l18,14l14,16l12,17l10,19l7,20l-19,10l-20,7l-21,5l-21,3l-21,3l-21,1l-21,-1zm-12,-18l9,-14l9,-13l9,-14l8,-15l8,-15l9,-14l5,-13l6,-13l5,-13l0,0l16,10l11,11l11,10l11,11l3,3l-3,-1l-10,-7l-12,-5l-11,-6l-10,-4l-8,14l-9,13l-8,14l-8,10l-7,11l-9,11l-8,10l-9,10l-9,11zm234,-133c-1,-1,-2,-2,-3,-2c2,6,3,14,5,18c4,8,8,15,11,19c3,4,6,23,5,43c-1,20,-5,30,-10,41c-1,-3,2,-19,2,-27c0,-8,0,-32,-1,-37c-3,-15,-24,-55,-36,-69c-6,-2,-12,-4,-18,-7c-16,-9,-22,-21,-49,-27c-18,-5,-34,-1,-46,1c2,3,10,9,10,9c5,6,9,13,13,20c1,5,3,10,3,13c0,3,9,16,13,21c7,10,3,26,4,36c-6,-8,-8,-18,-9,-25c-1,-7,-12,-20,-17,-30c-6,-10,-15,-16,-16,-20c1,-8,-4,-13,-7,-14c-3,-2,-14,-6,-21,-8c-4,-8,-14,-12,-44,-11c0,-7,-2,-10,-10,-12c-9,-4,-16,7,-23,-23c-7,-30,-52,-71,-67,-92c-15,-21,-32,17,-18,34c39,48,19,79,-3,78c-12,0,-16,6,-17,11c-9,0,-17,-2,-26,1c-4,1,-8,4,-9,6c-2,4,-18,24,-22,30c-2,12,-9,20,-15,28c1,-15,2,-25,6,-39c4,-7,9,-14,15,-20c-19,0,-30,-5,-58,-1c-14,3,-26,8,-36,14c-6,4,-13,11,-14,14c-1,2,-23,16,-24,28c-1,10,-6,25,-10,32c-6,12,-7,44,-7,44c0,0,-4,-23,-4,-23c1,-12,3,-24,4,-36c0,0,4,-18,9,-22c2,-2,5,-12,8,-19c-8,4,-17,9,-23,14c-53,43,-81,110,-84,188c-3,105,35,202,123,263c15,10,36,20,57,28c-17,-14,-36,-33,-51,-52c-5,-19,-10,-37,-11,-57c-1,-15,1,-26,6,-39c1,50,3,63,24,102c13,8,13,15,27,23c9,12,19,22,29,31c10,2,20,3,29,4c9,5,17,9,25,13c18,2,31,-1,49,-3c-8,-5,-17,-11,-20,-10c-8,3,-30,-26,-30,-31c-1,-9,-3,-23,-7,-36c12,16,21,36,24,45c4,5,11,8,24,12c9,9,18,20,28,25c10,2,86,8,102,-1c3,-6,14,-13,16,-18c4,-8,11,-14,16,-22c5,-7,9,-15,12,-24c5,-5,6,-13,14,-18c-4,11,-8,22,-13,33c0,8,-1,17,-4,24c-10,10,-18,19,-28,26c5,0,12,-1,18,-3c15,-3,42,-9,49,-12c3,-6,5,-12,7,-18c6,-5,13,-10,18,-16c9,-7,17,-15,24,-24c6,-7,12,-15,17,-23c5,-11,10,-24,14,-37c0,17,-2,34,-5,50c-9,11,-18,21,-27,30c-4,7,-8,12,-13,18c-3,4,-6,8,-9,12c10,-4,20,-9,30,-15c83,-55,142,-154,146,-253c3,-81,5,-146,-71,-206 "/></g>'));
}
if (rands[12] % 337 < 110 && lp < 4) dummy = string(abi.encodePacked(aer, dummy));
dummy = string(abi.encodePacked(dummy, '<linearGradient id="lsstyle',t(lp),'" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="',cs.offset_canvas,'" stop-color="',cs.sc,'"/><stop offset="',(lp == 3 ? '60' : '100'),'%" stop-color="',cs.sc2,'"/>',(lp == 3 ? '<stop offset="70%" stop-color="#974638"/><animate attributeName="y2" begin="0s" dur="15s" repeatCount="0" from="100%" to="90%" fill="freeze"></animate>' : ''),'</linearGradient>'));
for (uint layer = 1; layer <= ls.layersAmount; layer++) {
dummy = string(abi.encodePacked(dummy, '<linearGradient id="gradient',t(layer),'" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="',(layer == 3 ? "40%" : (layer == 2 ? "60%" : "20%")),'" stop-color="',cs.bc[layer],'"/><stop offset="100%" stop-color="',(layer == 1 ? cs.bottomcolor : cs.bc[5]),'"/></linearGradient>'));
}
return dummy;
}
function bytesToUint(bytes memory b) internal pure returns (uint256) {
uint256 number;
for(uint i=0;i<b.length;i++){
number = number + uint(uint8(b[i])*(2**(8*(b.length-(i+1)))));
}
return number;
}
function t(uint256 value) internal pure returns (string memory) {
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);
}
function getRand(uint tokenId, uint lp) public pure returns(uint[13] memory) {
string memory tid = t(tokenId);
string memory lid = t(lp);
return [
random(abi.encodePacked("FIRST", tid, lid)),
random(abi.encodePacked("SECOND", tid, lid)),
random(abi.encodePacked("THIRD", tid, lid)),
random(abi.encodePacked("FOURTH", tid, lid)),
random(abi.encodePacked("FIFTH", tid, lid)),
random(abi.encodePacked("CLOUDS", tid, lid)),
random(abi.encodePacked("CHANNEL", tid, lid)),
random(abi.encodePacked("RGBVALUE", tid, lid)),
random(abi.encodePacked("TR1X", tid, lid)),
random(abi.encodePacked("TR1Y", tid, lid)),
random(abi.encodePacked("SUNOFFSET", tid, lid)),
random(abi.encodePacked("LAYERS", tid, lid)),
random(abi.encodePacked("AEROSTAT", tid, lid))
];
}
function random(bytes memory input) public pure returns (uint256) {
return uint256(keccak256(abi.encodePacked(string(input))));
}
function hexToRGB(string memory rgb) public pure returns (uint[3] memory) {
return [
Strings.fromHex(Strings.substr(rgb, 1, 3)),
Strings.fromHex(Strings.substr(rgb, 3, 5)),
Strings.fromHex(Strings.substr(rgb, 5, 7))
];
}
function rgbTint(string memory rgb, uint k, uint sig) public pure returns (string memory) {
return rgbShift(rgb, k*10, k*10, k*10, sig);
}
function rgbShift(string memory rgb, uint dr, uint dg, uint db, uint sig) public pure returns (string memory) {
uint[3] memory rgbarr = hexToRGB(rgb);
uint[3] memory rgbres;
if (sig == 1) {
rgbres = [rgbarr[0] + (255 - rgbarr[0]) * dr / 100, rgbarr[1] + (255 - rgbarr[1]) * dg / 100, rgbarr[2] + (255 - rgbarr[2]) * db / 100];
} else {
rgbres = [rgbarr[0] - (255 - rgbarr[0]) * dr / 100, rgbarr[1] - (255 - rgbarr[1]) * dg / 100, rgbarr[2] - (255 - rgbarr[2]) * db / 100];
}
if (rgbres[0] > 255) rgbres[0] = 255;
if (rgbres[1] > 255) rgbres[1] = 255;
if (rgbres[2] > 255) rgbres[2] = 255;
return rgbToHex(rgbres);
}
function rgbToHex(uint[3] memory rgbres) public pure returns (string memory) {
return string(abi.encodePacked("#",Strings.toHexString(rgbres[0]),Strings.toHexString(rgbres[1]),Strings.toHexString(rgbres[2])));
}
function stars(uint n, uint fromx, uint fromy, uint tox, uint toy, uint tokenId) public pure returns (string memory) {
require(toy != fromy, "Error toy and fromy");
string memory result = "";
uint x; uint y; uint opacity; uint offsetx; uint offsety;
for (uint i = 1; i<=n; i++) {
offsetx = random(abi.encodePacked("XFAEB", t(tokenId * i))) % 201;
offsety = random(abi.encodePacked("YF24C", t(tokenId * i))) % 201;
x = (fromx * 100 + (tox * 100 - fromx * 100) / 200 * offsetx) / 100;
y = (fromy * 100 + (toy * 100 - fromy * 100) / 200 * offsety) / 100;
if (y < fromy && toy >= fromy) {
opacity = 0;
} else if (toy < fromy && y >= fromy) {
opacity = 0;
} else {
opacity = 100 - 100 * (y-fromy) / (toy-fromy);
}
result = string(abi.encodePacked(result, '<circle cx="',t(x),'" cy="',t(y),'" r="0.5" fill="#fff" fill-opacity="',t(opacity),'%"></circle>'));
}
return result;
}
}
library Base64 {
bytes internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function encode(bytes memory data) internal pure returns (string memory) {
uint256 len = data.length;
if (len == 0) return "";
uint256 encodedLen = 4 * ((len + 2) / 3);
bytes memory result = new bytes(encodedLen + 32);
bytes memory table = TABLE;
assembly {
let tablePtr := add(table, 1)
let resultPtr := add(result, 32)
for {
let i := 0
} lt(i, len) {
} {
i := add(i, 3)
let input := and(mload(add(data, i)), 0xffffff)
let out := mload(add(tablePtr, and(shr(18, input), 0x3F)))
out := shl(8, out)
out := add(out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF))
out := shl(8, out)
out := add(out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF))
out := shl(8, out)
out := add(out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF))
out := shl(224, out)
mstore(resultPtr, out)
resultPtr := add(resultPtr, 4)
}
switch mod(len, 3)
case 1 {
mstore(sub(resultPtr, 2), shl(240, 0x3d3d))
}
case 2 {
mstore(sub(resultPtr, 1), shl(248, 0x3d))
}
mstore(result, encodedLen)
}
return string(result);
}
}