Skip to content

Commit

Permalink
chore: add background variants and blob layers (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgonzalezra authored Feb 3, 2024
1 parent 3928052 commit db23d86
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 40 deletions.
23 changes: 19 additions & 4 deletions packages/contracts/src/LucidOrigins.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(
'<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" width="400" height="400">',
Expand Down Expand Up @@ -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);
}
}
78 changes: 45 additions & 33 deletions packages/contracts/src/layers/Background.sol
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
'<g id="bg" opacity="0.4"><rect width="100" height="100" fill="',
colors[0],
'" />',
'<path d="',
paths[0],
'" fill="',
colors[1],
colors[2],
'" /><path d="',
paths[1],
'" fill="',
colors[2],
colors[3],
'" /><path d="',
paths[2],
'" fill="',
colors[0],
'" />'
colors[1],
'" /></g>'
);
}

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);
}
}
6 changes: 5 additions & 1 deletion packages/contracts/src/layers/Blob.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -107,13 +108,16 @@ contract Blob {
pure
returns (string memory)
{
uint256 strokeWidth = id == 1 ? 3 : 0;
return string.concat(
colorDefs,
'<path id="',
id.toString(),
'" d="',
h1,
'Z" stroke-width="2" stroke="black" transform-origin="center" fill="',
'Z" stroke-width="',
strokeWidth.toString(),
'" stroke="black" transform-origin="center" fill="',
fillColor,
'">',
'<animate attributeName="d" values="',
Expand Down
9 changes: 7 additions & 2 deletions packages/contracts/src/layers/Blush.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// SPDX-License-Identifier: GNU GPLv3
pragma solidity 0.8.23;
import { LibString } from "solmate/utils/LibString.sol";

contract Blush {
function blush() internal pure returns (string memory) {
using LibString for uint256;

function blush(uint256 layerId) internal pure returns (string memory) {
return string.concat(
'<circle id="circle-blush" r="6" fill="rgba(255,255,255,0.4)" />',
'<animateMotion href="#circle-blush" dur="30s" begin="0s" ',
'fill="freeze" repeatCount="indefinite" rotate="auto-reverse" ',
'><mpath href="#1" /></animateMotion>'
'><mpath href="#',
layerId.toString(),
'" /></animateMotion>'
);
}
}

0 comments on commit db23d86

Please sign in to comment.