From db23d86fa1050fd066dfab8ceb7bd7d2ebdbc49e Mon Sep 17 00:00:00 2001 From: jpgonzalezra Date: Sat, 3 Feb 2024 13:57:56 -0300 Subject: [PATCH] chore: add background variants and blob layers (#7) --- packages/contracts/src/LucidOrigins.sol | 23 +++++- packages/contracts/src/layers/Background.sol | 78 +++++++++++--------- packages/contracts/src/layers/Blob.sol | 6 +- packages/contracts/src/layers/Blush.sol | 9 ++- 4 files changed, 76 insertions(+), 40 deletions(-) diff --git a/packages/contracts/src/LucidOrigins.sol b/packages/contracts/src/LucidOrigins.sol index f4465f7..411ea91 100644 --- a/packages/contracts/src/LucidOrigins.sol +++ b/packages/contracts/src/LucidOrigins.sol @@ -22,13 +22,29 @@ contract LucidOrigins is Owned, ERC721A, Background, Face, Blob, Blush, Colors { function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { uint16[] memory dna = getDna(uint256(keccak256(abi.encodePacked(tokenId)))); string memory name = string.concat("LucidOrigins #", tokenId.toString()); - string memory background = background(normalizeToRange(dna[Constants.BACKGROUND_INDEX], 0, 16)); + int256[6] memory backgroundShapeMatrix = [ + int256(normalizeToRange(dna[1], 0, 100)), + int256(normalizeToRange(dna[2], 0, 100)), + int256(normalizeToRange(dna[3], 0, 100)), + int256(normalizeToRange(dna[4], 0, 100)), + int256(normalizeToRange(dna[5], 0, 100)), + int256(normalizeToRange(dna[6], 0, 100)) + ]; + string[4] memory backgroundColorMatrix = [ + colors[normalizeToRange(dna[1], 0, 71)], + colors[normalizeToRange(dna[2], 0, 71)], + colors[normalizeToRange(dna[3], 0, 71)], + colors[normalizeToRange(dna[4], 0, 71)] + ]; + + string memory background = background(backgroundShapeMatrix, backgroundColorMatrix, normalizeToRange(dna[Constants.BASE_INDEX], 0, 100)); string memory layers = ""; + uint256 layersLength = normalizeToRange(dna[Constants.BASE_INDEX], 2, 6); uint256 size = normalizeToRange(dna[Constants.SIZE_INDEX], 125, 135); string memory colorDefs; string memory fillColor; - for (uint256 i = 1; i <= 3; i++) { + for (uint256 i = 1; i <= layersLength; i++) { (colorDefs, fillColor) = resolveDefsAndFillColor( normalizeToRange(dna[Constants.COLOR1_INDEX] * i, 0, 71), normalizeToRange(dna[Constants.COLOR2_INDEX] * i, 0, 71), @@ -49,7 +65,7 @@ contract LucidOrigins is Owned, ERC721A, Background, Face, Blob, Blush, Colors { normalizeToRange(dna[Constants.EYE_PUPIL_RADIUS_INDEX], 0, 6), fillColor ); - string memory svgContent = string.concat(layers, face, blush()); + string memory svgContent = string.concat(layers, face, blush(normalizeToRange(dna[Constants.SIZE_INDEX], 2, layersLength))); uint256 rotation = normalizeToRange(dna[Constants.SIZE_INDEX], 0, 3); string memory svg = string.concat( '', @@ -146,7 +162,6 @@ contract LucidOrigins is Owned, ERC721A, Background, Face, Blob, Blush, Colors { ); string memory fillColor = isPlain ? colors[color1] : "url(#linear-grad)"; - return (colorDefs, fillColor); } } diff --git a/packages/contracts/src/layers/Background.sol b/packages/contracts/src/layers/Background.sol index 760c3fc..850bdc7 100644 --- a/packages/contracts/src/layers/Background.sol +++ b/packages/contracts/src/layers/Background.sol @@ -1,35 +1,11 @@ // SPDX-License-Identifier: GNU GPLv3 pragma solidity 0.8.23; -import { console2 } from "forge-std/console2.sol"; import { LibString } from "solmate/utils/LibString.sol"; contract Background { using LibString for int256; - string[20] internal bgColors = [ - "#F8F8F8", - "#F0F0F0", - "#E8E8E8", - "#E0E0E0", - "#D8D8D8", - "#D0D0D0", - "#C8C8C8", - "#C0C0C0", - "#B8B8B8", - "#B0B0B0", - "#A8A8A8", - "#A0A0A0", - "#989898", - "#909090", - "#888888", - "#808080", - "#787878", - "#707070", - "#686868", - "#606060" - ]; - function generatePath(int256 curveVal, int256 pos, int256 index) internal pure returns (string memory) { int256 cVal = curveVal % 100; int256 bigC = 100 - cVal; @@ -69,28 +45,64 @@ contract Background { ); } - function hydrateBlog(string[3] memory paths, string[3] memory colors) internal pure returns (string memory) { + function hydrateBlog(string[3] memory paths, string[4] memory colors) internal pure returns (string memory) { return string.concat( + '', '' + colors[1], + '" />' ); } - function background(uint256 dnaBgLayer) internal view returns (string memory) { - string[3] memory paths = [generatePath(68, 23, 2), generatePath(11, 70, 1), generatePath(38, 67, 0)]; - string[3] memory colors = ["#27b4f6", "#D84B09", "#F67094"]; - console2.log(hydrateBlog(paths, colors)); + function background( + int256[6] memory backgroundShapeMatrix, + string[4] memory backgroundColorMatrix, + uint256 base + ) internal pure returns (string memory) { + bool isPlain = base < 55; + bool isBiTone = base < 70; + + string[3] memory paths = [ + generatePath( + backgroundShapeMatrix[0], + backgroundShapeMatrix[1], + 2 + ), + generatePath( + backgroundShapeMatrix[2], + backgroundShapeMatrix[3], + 1 + ), + generatePath( + backgroundShapeMatrix[4], + backgroundShapeMatrix[5], + 0 + )]; + + string[4] memory colors = isPlain ? [ + backgroundColorMatrix[0], + backgroundColorMatrix[0], + backgroundColorMatrix[0], + backgroundColorMatrix[0] + ] : isBiTone ? [ + backgroundColorMatrix[0], + backgroundColorMatrix[3], + backgroundColorMatrix[0], + backgroundColorMatrix[3] + ] : backgroundColorMatrix; + return hydrateBlog(paths, colors); } } diff --git a/packages/contracts/src/layers/Blob.sol b/packages/contracts/src/layers/Blob.sol index 946dca5..101bcc3 100644 --- a/packages/contracts/src/layers/Blob.sol +++ b/packages/contracts/src/layers/Blob.sol @@ -4,6 +4,7 @@ pragma solidity 0.8.23; // import { console2 } from "forge-std/console2.sol"; import { LibString } from "solmate/utils/LibString.sol"; import { Trigonometry } from "solidity-trigonometry/Trigonometry.sol"; +import { Constants } from "../utils/constants.sol"; contract Blob { struct Point { @@ -107,13 +108,16 @@ contract Blob { pure returns (string memory) { + uint256 strokeWidth = id == 1 ? 3 : 0; return string.concat( colorDefs, '', '', '' + '>' ); } }