Built with blockbuilder.org
Created
August 29, 2017 03:46
-
-
Save anonymous/8e6fd12c546d88e5dfb18429a01dcae5 to your computer and use it in GitHub Desktop.
fresh block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<script> | |
var width = 960 | |
var height = 500 | |
// Feel free to change or delete any of the code you see in this editor! | |
var svg = d3.select("body").append("svg") | |
.attr("width", 960) | |
.attr("height", 500) | |
var background = svg.append("rect") | |
.attr("width", width) | |
.attr("height", height) | |
.attr("fill", "#f0f000") | |
var testDefs = svg.append("defs") | |
var testMask = testDefs.append("mask") | |
.attr("id", "testMask") | |
.attr("x", 0) | |
.attr("y", 0) | |
.attr("width", width) | |
.attr("height", height) | |
testMask.append('circle') | |
.attr('r', 100) | |
.attr('cx', 960 / 2) | |
.attr('cy', 500 / 2) | |
var bottomLayer = svg.append('g') | |
var testRect = bottomLayer.append("rect") | |
.attr("width", width) | |
.attr("height", height) | |
.attr("fill", "#f00ff0") | |
// testRect.attr("mask", "url(#testMask)") | |
var limit = 0 | |
var recursivelyDrawLayers = (layer, i) => { | |
var rectFill = (i % 2 === 0) ? "#f0f" : "#000" | |
var rect = layer.append('rect') | |
.attr('width', 960) | |
.attr('height', 500) | |
.attr('fill', rectFill) | |
var defs = layer.append("defs") | |
var mask = defs.append("mask") | |
.attr("id", `mask-${i}`) | |
.attr("x", 0) | |
.attr("y", 0) | |
.attr("width", width) | |
.attr("height", height) | |
mask.append('circle') | |
.attr('r', 100) | |
.attr('cx', 960 / 2) | |
.attr('cy', 500 / 2) | |
.attr('fill', "#000000") | |
if (i < limit) { | |
var nextLayer = layer.append('g') | |
.attr("transform", `translate(0, 1)`) | |
.attr("mask", `url(#mask-${i})`) | |
recursivelyDrawLayers(nextLayer, i + 1) | |
} | |
} | |
// recursivelyDrawLayers(bottomLayer, 0) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment