There are a couple ways to do this! One is with ImageSize
, and one is with RasterSize
(probably recommended), and they have slightly different effects.
Specifying ImageSize
essentially scales up your graphics image first, and then rasterizes it for the PNG format. Since these lines in Mathematica have a width that is independent of the size of the image they're in, increasing the ImageSize
will not increase the line width, and so the lines will appear relatively thinner.
It's possible that's what you want, but more likely, you want to have a high-resolution version of the graphic as you see it! You could potentially "fix" the above problem by adding an explicit Thickness[0.0025],
(or some other number) in front of the Line
expression (which might be useful anyway, as it lets you control line thickness).
Or, you can simply use RasterSize
instead, which specifies how many pixels to break down the image into. RasterSize
can be specified in a couple different ways (see the Details section), but the easiest is probably by simply specifying the horizontal width in pixels as an integer. So, defining graphic
via your code:
raylengths = {2, 10};
graphic = Graphics[{Disk[{0, 0}, 1, {0, Pi}],
{Dashing[Riffle[RandomReal[.1, 25], RandomReal[.02, 25]]],
Line[{{0, 0}, (Last[raylengths = RotateLeft[raylengths]] /.
2 -> RandomReal[{2, 3}]) Through[{Cos, Sin}@#]}]} & /@
Subdivide[0, Pi, 60]},
PlotRange -> {{-3/2, 3/2}, {0, 4}},
Axes -> {True, False},
AxesStyle -> Directive[Thick, Black],
Ticks -> None];
Export["minimalSun4K.png", graphic, RasterSize -> 3000]
This will give an image with a pixel width of 3000 (and thus a height of 4000).
For the sake of example, I'm using png
, but there are other image formats you could use, e.g. .tiff
, and I believe the same RasterSize
option works for them as well (though I could be wrong about some of them).
To get it to be the right dimensions, you need to either fiddle with the value of PlotRange
, use a maximum height in RasterSize
, or crop it post-exporting.
To use PlotRange
, you might want something like {{-3/2,3/2},{0,3*pixelheight/pixelwidth}}
, or {{-d*3/2,d*3/2},{0,d*3*pixelheight/pixelwidth}}
where d
is a value around 1
that lets you fudge the "zoom" of the image.
I'm not exactly sure whether A4 is 297/210
or 11.75/8.25
, but if A4ratio = A4height/A4width
, you could use it in the same way: PlotRange -> {{-3/2,3/2}, {0, 3*A4ratio}}
.
However, this code uses Axes
to produce the horizon, and that produces some artifacts in the bottom corners.
So, instead, I recommend
raylengths = {2, 10};
graphic = Graphics[{Disk[{0, 0}, 1, {0, Pi}],
{Thickness[0.015], InfiniteLine[{{-1, 0}, {1, 0}}]},
{Dashing[Riffle[RandomReal[.1, 25], RandomReal[.02, 25]]],
Line[{{0, 0}, (Last[raylengths = RotateLeft[raylengths]] /.
2 -> RandomReal[{2, 3}]) Through[{Cos, Sin}@#]}]} & /@
Subdivide[0, Pi, 60]},
PlotRange -> {{-3/2, 3/2}, {0, 4}}];
Export["minimalSun4K.png", graphic, RasterSize -> 3000]
where you can change the number in Thickness
to your liking.
Let me know if there's any other way I can help!