Message Boards Message Boards

1
|
6638 Views
|
6 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Cellular Automaton Vector Export

Posted 10 years ago

This started as a quest to produce a vector SVG export of an ArrayPlot of a cellular automaton. However, it quickly became apparent that this would be more complicated than Export["vectorca.svg",ArrayPlot[CellularAutomaton[30,{{1},0},20]]], because ArrayPlots are actually raster objects, and I wanted little rectangles for each cell. I ended up with this code, which works for any two-dimensional binary array:

Export["~/Documents/jesse.ws/blog/rule30.svg",
MapIndexed[If[#1 == 1, Rectangle[#2 + .25], Nothing] &,
Reverse[Transpose@CellularAutomaton[30, {{1}, 0}, 30], 2], {2}]//Graphics]

Hopefully it might help somebody else in the future!

POSTED BY: Jesse Friedman
6 Replies
MapIndexed[If[#1 == 1, Rectangle[#2 + 0.05]] &,  Reverse[Transpose@CellularAutomaton[30, {{1}, 0}, 100],  2], {2}] // Graphics

enter image description here

POSTED BY: Simon Cadrin
ArrayPlot[CellularAutomaton[30, {{1}, 0}, 90]]

enter image description here

POSTED BY: Simon Cadrin

Nothing is a new feature introduced in Mathematica 10.2. I probably should have noted that in my post.

You can change it to Missing[] and add a DeleteMissing.

POSTED BY: Jesse Friedman

If you examine the SVG outputted by that, you will notice that it isn't actually vector, but a raster bitmap embedded in the file. This is why I made my code in the first place, as indicated in the second sentence of my original post.

POSTED BY: Jesse Friedman
MapIndexed[If[#1==1,Rectangle[#2+0.15]]&,Reverse[Transpose@CellularAutomaton[30,{{1},0},90],2],{2}]//Graphics

enter image description here

POSTED BY: Simon Cadrin

That works as well, although I would argue that it is bad practice to feed Graphics a list containing null values.

POSTED BY: Jesse Friedman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract