Skip to content

Commit

Permalink
Touchups (#84)
Browse files Browse the repository at this point in the history
* body touchups

* traits touchups

* change count_

* metadata, polarity touchups

* mouth touchups

* motes touchups

* face touchups

* eyes touchups

* svg touchups

* bibos touchups

* add all headers
  • Loading branch information
mshrieve authored Aug 4, 2022
1 parent c797f9b commit 05f2c75
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 237 deletions.
18 changes: 7 additions & 11 deletions src/Bibos.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import {ERC721} from "solmate/tokens/ERC721.sol";
import {Owned} from "solmate/auth/Owned.sol";
import {Render} from "libraries/Render.sol";

error InsufficentValue();
error MintedOut();
error InvalidTokenId();
error AmountNotAvailable();

contract Bibos is ERC721, Owned {
/*//////////////////////////////////////////////////////////////
STATE
Expand All @@ -32,15 +37,6 @@ contract Bibos is ERC721, Owned {
uint256 public totalSupply;
mapping(uint256 => bytes32) public seeds; // (tokenId => seed)

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

error InsufficentValue();
error MintedOut();
error InvalidTokenId();
error AmountNotAvailable();

/*//////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -78,7 +74,7 @@ contract Bibos is ERC721, Owned {
}

/*//////////////////////////////////////////////////////////////
MINTING
MINT
//////////////////////////////////////////////////////////////*/

function mint() public payable OnlyIfNotMintedOut OnlyIfYouPayEnough(1) {
Expand All @@ -94,7 +90,7 @@ contract Bibos is ERC721, Owned {
{
for (; _amount > 0; ) {
_mint(msg.sender);
_amount--;
--_amount;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/libraries/Background.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {Palette} from "./Palette.sol";
import {SVG} from "./SVG.sol";

library Background {
/*//////////////////////////////////////////////////////////////
RENDER
//////////////////////////////////////////////////////////////*/

function render(bytes32 _seed, uint256 _tokenId) internal pure returns (string memory) {
return
SVG.element(
Expand Down
108 changes: 58 additions & 50 deletions src/libraries/Body.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,24 @@ import {Util} from "./Util.sol";
import {SVG} from "./SVG.sol";

library Body {
uint256 constant circlesCount = 7;

/*//////////////////////////////////////////////////////////////
RENDER
//////////////////////////////////////////////////////////////*/

function render(bytes32 _seed, uint256 _tokenId) internal pure returns (string memory) {
string memory bodyGroupChildren;
string[7] memory radii = ["64", "64", "64", "56", "48", "32", "24"];

string memory backgroundFill = Palette.backgroundFill(_seed, _tokenId);
string memory mixBlendMode = Traits.polarityType(_seed) == PolarityType.POSITIVE ? "lighten" : "multiply";

bodyGroupChildren = string.concat(bodyGroupChildren, _bodyBackground(backgroundFill));

uint256 length = Data.length;
// uint256 circlesCount = 7;

for (uint8 i = 0; i < 7; i++) {
uint256 bodySeed = uint256(keccak256(abi.encodePacked(_seed, "body", i)));
string memory bodyFill = Palette.bodyFill(_seed, i, _tokenId);
string memory bodyFill2 = Palette.bodyFill(_seed, i + 7, _tokenId);

string memory radius = radii[i];

string memory dur = Data.shortTimes(bodySeed);
bodySeed /= length;

string[2] memory coords = (i == 0) ? ["150", "150"] : Data.bodyPoints(bodySeed);
bodySeed /= length;

bool reverse = bodySeed % 2 == 0;
bodySeed /= 2;

string memory maybeGenesis = _tokenId == 0
? string.concat(
'<animate attributeName="fill" repeatCount="indefinite" values="',
bodyFill,
";",
bodyFill2,
";",
bodyFill,
'" dur="',
dur,
'"/>'
)
: "";
string memory bodyGroupChildren = _bodyBackground(backgroundFill);

for (uint8 index = 0; index < circlesCount; ++index) {
bodyGroupChildren = string.concat(
bodyGroupChildren,
'<circle fill="',
bodyFill,
'" r="',
radius,
'" cx="',
coords[0],
'" cy="',
coords[1],
'" style="mix-blend-mode: ',
mixBlendMode,
'">',
SVG.element("animateMotion", SVG.animateMotionAttributes(reverse, dur, "linear"), Data.mpathJitterLg()),
maybeGenesis,
"</circle>"
// _bodyCircle(radius, coords, bodyFill, bodyFill2, dur, reverse, mixBlendMode)
_bodyCircle(_seed, index, _tokenId, radii[index], mixBlendMode)
);
}
return
Expand All @@ -81,6 +36,59 @@ library Body {
);
}

/*//////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////*/

function _bodyCircle(
bytes32 _seed,
uint256 _index,
uint256 _tokenId,
string memory _radius,
string memory _mixMode
) internal pure returns (string memory) {
uint256 bodySeed = uint256(keccak256(abi.encodePacked(_seed, "body", _index)));
string memory bodyFill1 = Palette.bodyFill(_seed, _index, _tokenId);
string memory bodyFill2 = Palette.bodyFill(_seed, _index + circlesCount, _tokenId);
string memory dur = Data.shortTimes(bodySeed /= Data.length);
string[2] memory coords = (_index == 0) ? ["150", "150"] : Data.bodyPoints(bodySeed /= 2);
bool reverse = bodySeed % 2 == 0;

return
SVG.element(
"circle",
SVG.circleAttributes({
_radius: _radius,
_coords: coords,
_fill: bodyFill1,
_opacity: "1",
_mixMode: _mixMode,
_attributes: ""
}),
SVG.element("animateMotion", SVG.animateMotionAttributes(reverse, dur, "linear"), Data.mpathJitterLg()),
(_tokenId == 0) ? _genesis(bodyFill1, bodyFill2, dur) : ""
);
}

function _genesis(
string memory _bodyFill1,
string memory _bodyFill2,
string memory _dur
) internal pure returns (string memory) {
return
string.concat(
'<animate attributeName="fill" repeatCount="indefinite" values="',
_bodyFill1,
";",
_bodyFill2,
";",
_bodyFill1,
'" dur="',
_dur,
'"/>'
);
}

function _bodyBackground(string memory _fill) internal pure returns (string memory) {
return
SVG.element("rect", SVG.rectAttributes({_width: "100%", _height: "100%", _fill: _fill, _attributes: ""}));
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Eyes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ enum EyeType {
}

library Eyes {
string constant fill = "black";

/*//////////////////////////////////////////////////////////////
RENDER
//////////////////////////////////////////////////////////////*/

function render(bytes32 _seed) internal pure returns (string memory) {
string memory fill = "black";

EyeType eyeType = Traits.eyeType(_seed);

if (eyeType == EyeType.OPEN) return _open(fill);
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/Face.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ library Face {

function render(bytes32 _seed) internal pure returns (string memory) {
uint256 faceSeed = uint256(keccak256(abi.encodePacked(_seed, "face")));
bool reverse = faceSeed % 2 == 0;
faceSeed /= 2;
bool reverse = (faceSeed /= 2) % 2 == 0;
string memory rotation = ["1", "2", "4", "6", "-1", "-2", "-4", "-6"][faceSeed % 8];

string memory circleFilterId = "bibo-blur-lg";
Expand Down
8 changes: 8 additions & 0 deletions src/libraries/Glints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {Util} from "./Util.sol";
import {SVG} from "./SVG.sol";

library Glints {
/*//////////////////////////////////////////////////////////////
RENDER
//////////////////////////////////////////////////////////////*/

function render(bytes32 _seed) internal pure returns (string memory) {
string memory glintsGroupChildren;
uint256 glintCount = Traits.glintCount(_seed);
Expand Down Expand Up @@ -37,6 +41,10 @@ library Glints {
return SVG.element("g", "id='glints'", glintsGroupChildren);
}

/*//////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////*/

function _glint(
string memory _durationShort,
string memory _durationShorter,
Expand Down
10 changes: 2 additions & 8 deletions src/libraries/Metadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ library Metadata {
string constant JSON_BASE64_HEADER = "data:application/json;base64,";
string constant SVG_XML_BASE64_HEADER = "data:image/svg+xml;base64,";

/// @notice base64 encode json metadata for the token
/// @param _id, the tokenId
/// @param _name, the name of the token
/// @param _description, the description of the token
/// @param _svg, the svg image
/// @return string, the name of the color
function encodeMetadata(
uint256 _id,
uint256 _tokenId,
string memory _name,
string memory _description,
string memory _attributes,
Expand All @@ -24,7 +18,7 @@ library Metadata {
) internal pure returns (string memory) {
string memory metadata = string.concat(
"{",
Util.keyValue("tokenId", Util.uint256ToString(_id)),
Util.keyValue("tokenId", Util.uint256ToString(_tokenId)),
",",
Util.keyValue("name", _name),
",",
Expand Down
24 changes: 14 additions & 10 deletions src/libraries/Motes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ enum MoteType {
library Motes {
uint256 constant GLINT_COUNT = 20;

/*//////////////////////////////////////////////////////////////
RENDER
//////////////////////////////////////////////////////////////*/

function render(bytes32 _seed) internal pure returns (string memory) {
string memory motesChildren;

Expand All @@ -27,17 +31,13 @@ library Motes {
for (uint8 i = 0; i < GLINT_COUNT; i++) {
uint256 moteSeed = uint256(keccak256(abi.encodePacked(_seed, "mote", i)));

string memory dur = Data.longTimes(moteSeed);
moteSeed = moteSeed / Data.length;
string memory delay = Data.shorterTimes(moteSeed);
moteSeed = moteSeed / Data.length;
string[2] memory coords = Data.motePoints(moteSeed);
moteSeed = moteSeed / Data.length;
string memory radius = moteSeed % 2 == 0 ? "1" : "2";
moteSeed = moteSeed / 2;
string memory opacity = Palette.opacity(moteSeed, _seed);
moteSeed /= Palette.opacityLength;
string memory dur = Data.longTimes(moteSeed /= Data.length);
string memory delay = Data.shorterTimes(moteSeed /= Data.length);
string[2] memory coords = Data.motePoints(moteSeed /= Data.length);
string memory radius = (moteSeed /= 2) % 2 == 0 ? "1" : "2";
string memory opacity = Palette.opacity(moteSeed /= Palette.opacityLength, _seed);
bool reverse = moteSeed % 2 == 0;

if (moteType == MoteType.FLOATING)
motesChildren = string.concat(motesChildren, _floatingMote(radius, coords, opacity, dur, reverse));
else if (moteType == MoteType.RISING)
Expand All @@ -54,6 +54,10 @@ library Motes {
return SVG.element({_type: "g", _attributes: "", _children: motesChildren});
}

/*//////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////*/

function _risingMote(
string memory _radius,
string[2] memory _coords,
Expand Down
12 changes: 11 additions & 1 deletion src/libraries/Mouth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity >=0.8.0;

import {Palette} from "./Palette.sol";
import {Traits} from "./Traits.sol";

enum MouthType {
SMILE,
MEDIUM_SMILE,
Expand All @@ -18,8 +19,13 @@ enum MouthType {
}

library Mouth {
string constant fill = "black";

/*//////////////////////////////////////////////////////////////
RENDER
//////////////////////////////////////////////////////////////*/

function render(bytes32 _seed) internal pure returns (string memory) {
string memory fill = "black";
MouthType mouthType = Traits.mouthType(_seed);

if (mouthType == MouthType.SMILE) return _smile(fill);
Expand All @@ -35,6 +41,10 @@ library Mouth {
return _smirk(fill);
}

/*//////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////*/

function _smile(string memory _fill) internal pure returns (string memory) {
return
string.concat(
Expand Down
Loading

0 comments on commit 05f2c75

Please sign in to comment.