Skip to content

Commit

Permalink
Genesis bibos things (#82)
Browse files Browse the repository at this point in the history
* use different approach to differentiating genesis

* Update src/libraries/Body.sol

Co-authored-by: mike <[email protected]>

* fix: code style

Co-authored-by: mike <[email protected]>
  • Loading branch information
g-a-v-i-n and mshrieve authored Aug 3, 2022
1 parent ac06faf commit f4bc50b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 69 deletions.
2 changes: 1 addition & 1 deletion lib/forge-std
2 changes: 1 addition & 1 deletion lib/solmate
4 changes: 2 additions & 2 deletions src/libraries/Background.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {Palette} from "./Palette.sol";
import {SVG} from "./SVG.sol";

library Background {
function render(bytes32 _seed) internal pure returns (string memory) {
function render(bytes32 _seed, uint256 _tokenId) internal pure returns (string memory) {
return
SVG.element(
"rect",
SVG.rectAttributes({
_width: "100%",
_height: "100%",
_fill: Palette.backgroundFill(_seed),
_fill: Palette.backgroundFill(_seed, _tokenId),
_attributes: ""
})
);
Expand Down
63 changes: 38 additions & 25 deletions src/libraries/Body.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ library Body {
RENDER
//////////////////////////////////////////////////////////////*/

function render(bytes32 _seed) internal pure returns (string memory) {
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);
string memory backgroundFill = Palette.backgroundFill(_seed, _tokenId);
string memory mixBlendMode = Traits.polarityType(_seed) == PolarityType.POSITIVE ? "lighten" : "multiply";

bodyGroupChildren = string.concat(bodyGroupChildren, _bodyBackground(backgroundFill));
Expand All @@ -26,7 +26,13 @@ library Body {

for (uint8 i = 0; i < 7; i++) {
uint256 bodySeed = uint256(keccak256(abi.encodePacked(_seed, "body", i)));
string memory bodyFill = Palette.bodyFill(_seed, 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);
Expand All @@ -38,9 +44,37 @@ library Body {
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,
'"/>'
)
: "";

bodyGroupChildren = string.concat(
bodyGroupChildren,
_bodyCircle(radius, coords, bodyFill, dur, reverse, mixBlendMode)
'<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)
);
}
return
Expand All @@ -51,27 +85,6 @@ library Body {
);
}

function _bodyCircle(
string memory _radius,
string[2] memory _coords,
string memory _fill,
string memory _dur,
bool _reverse,
string memory _mixBlendMode
) internal pure returns (string memory) {
string memory opacity = "1";
return
SVG.element(
"circle",
SVG.circleAttributes(_radius, _coords, _fill, opacity, _mixBlendMode, ""),
SVG.element(
"animateMotion",
SVG.animateMotionAttributes(_reverse, _dur, "linear"),
Data.mpathJitterLg()
)
);
}

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
27 changes: 0 additions & 27 deletions src/libraries/Misc.sol

This file was deleted.

12 changes: 10 additions & 2 deletions src/libraries/Palette.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ library Palette {
)[_glintSeed % opacityLength];
}

function bodyFill(bytes32 _seed, uint256 _i) internal pure returns (string memory) {
function bodyFill(
bytes32 _seed,
uint256 _i,
uint256 _tokenId
) internal pure returns (string memory) {
uint256 bodyFillValue = uint256(keccak256(abi.encodePacked(_seed, "bodyFill", _i)));

if (_tokenId == 0) return _light(bodyFillValue);

if (Traits.densityType(_seed) == DensityType.HIGH) {
if (Traits.polarityType(_seed) == PolarityType.POSITIVE) {
return _light(bodyFillValue);
Expand All @@ -44,9 +50,11 @@ library Palette {
}
}

function backgroundFill(bytes32 _seed) internal pure returns (string memory) {
function backgroundFill(bytes32 _seed, uint256 _tokenId) internal pure returns (string memory) {
uint256 backgroundFillValue = uint256(keccak256(abi.encodePacked(_seed, "backgroundFill")));

if (_tokenId == 0) return _darkest(backgroundFillValue);

if (Traits.densityType(_seed) == DensityType.HIGH) {
if (Traits.polarityType(_seed) == PolarityType.POSITIVE) {
return _darkest(backgroundFillValue);
Expand Down
10 changes: 4 additions & 6 deletions src/libraries/Render.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {Motes} from "./Motes.sol";
import {Glints} from "./Glints.sol";
import {Traits} from "./Traits.sol";
import {SVG} from "./SVG.sol";
import {Misc} from "./Misc.sol";

library Render {
string public constant description = "Bibos";
Expand All @@ -25,7 +24,7 @@ library Render {
_name: _name(_tokenId),
_description: description,
_attributes: Traits.attributes(_seed),
_backgroundColor: Palette.backgroundFill(_seed),
_backgroundColor: Palette.backgroundFill(_seed, _tokenId),
_svg: _svg(_seed, _tokenId)
});
}
Expand All @@ -36,12 +35,11 @@ library Render {
"svg",
SVG.svgAttributes(),
Data.defs(),
Background.render(_seed),
Body.render(_seed),
Background.render(_seed, _tokenId),
Body.render(_seed, _tokenId),
Motes.render(_seed),
Glints.render(_seed),
Face.render(_seed),
Misc.render(_tokenId)
Face.render(_seed)
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/scripts/local_render.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ contract local_render is Test {
vm.warp(unixTime);

// compute a random tokenId
uint256 tokenId = unixTime % 999;
uint256 tokenId = unixTime % 1111;

// set the total supply
// (in storage slot 7)
vm.store(address(bibos), bytes32(uint256(7)), bytes32(tokenId));

// mint
vm.deal(address(this), .111 ether);
bibos.mint{value: .111 ether}();
vm.deal(address(this), .1 ether);
bibos.mint{value: .1 ether}();
tokenURI = bibos.tokenURI(tokenId);
}

Expand All @@ -41,11 +41,11 @@ contract local_render is Test {

tokenURIs = new string[](_amount);

vm.deal(address(this), _amount * .111 ether);
vm.deal(address(this), _amount * .1 ether);
uint256 i;
for (; i < _amount; ++i) {
// mint
bibos.mint{value: .111 ether}();
bibos.mint{value: .1 ether}();
tokenURIs[i] = bibos.tokenURI(i);
}
}
Expand Down

0 comments on commit f4bc50b

Please sign in to comment.