An SVG rectangle with multiple holes using Snap.svg

145 views
Skip to first unread message

Georg Mierau

unread,
Mar 15, 2015, 7:26:09 AM3/15/15
to sna...@googlegroups.com

I'm trying to get a rectangle with many (transparent, not just of the same color as the background!) round holes, but my code does the opposite.

I know why, but I don know how to generate a suitable mask for this case.

var s = Snap(500, 500);

var rectangle = s.rect(10, 10, 250, 250, 0, 0).attr({'fill':'white', 'stroke':'white'});
var group = s.group();  

for (i = 0; i < 5; i++) {
 
for (j = 0; j < 5; j++) {
 s
.circle(25+i*25, 25+j*25, 10).attr({'fill':'black', 'stroke':'black'}).appendTo(group);      
 
}
}  

rectangle
.attr({'mask':group});

I'm using Snap.svg 0.3.0. http://codepen.io/anon/pen/PwxPMG

Ian

unread,
Mar 15, 2015, 9:12:55 AM3/15/15
to sna...@googlegroups.com
Just to clarify, what effect are you after, what colour do you want background, rect, circles to be ?

I suspect you may want to put an added rect into the group, but not sure from you description.

Georg Mierau

unread,
Mar 15, 2015, 9:18:04 AM3/15/15
to sna...@googlegroups.com
Background has to be as it is, the white rectangle has to be white and holes (black circles now) have to be transparent holes in the rectangle. 

Ian

unread,
Mar 15, 2015, 10:14:35 AM3/15/15
to sna...@googlegroups.com
Do you mean like this... http://codepen.io/anon/pen/yyQeEZ ?

GeMir

unread,
Mar 15, 2015, 10:30:17 AM3/15/15
to sna...@googlegroups.com
Yes! So simple. Thank you!
Reply all
Reply to author
Forward
0 new messages