Yes, the basic idea is here: Demonstration: Day and Night World Clock
Now, to use the images, create an alpha channel using the computed the day-night curve--called "terminator" curve (rasterize it in grayscale), and compose two images using ImageComposeImageCompose
with the generated alpha channels (SetAlphaChannelSetAlphaChannel
to the second image).
Try the following code:
a = Image[ConstantArray[{255, 0, 0}, {200, 300}]];
b = Image[ConstantArray[{0, 255, 0}, {200, 300}]];
(* This is just a made-up mask. Don't mind the Plot[] part *)
mask = Rasterize[
Plot[Sin[x], {x, -Pi/2, 3 Pi/2}, PlotRangePadding->0,
Filling->-1, FillingStyle->Black, Frame->False,
Axes->False, ImageSize->{300, 200}, AspectRatio->2/3],
"Image", ColorSpace->"GrayScale"];
ImageCompose[a, SetAlphaChannel[b, mask]]
You should get an image with green and red mixed as below. Now you can replace a
and b
with your day and night textures.
I have to tell you that although the code there computes pretty close approximation of the actual terminator curve, it is not exact. To compute it accurately (or based on actual data), see: NOAA: Day Night Terminator
The following code and output is for the actual images (again the mask is fake):
day = ImageResize[day, {2048, 1024}]; (* Match the dimensions *)
mask = Rasterize[
Plot[Sin[x], {x, -Pi/2, 3 Pi/2}, PlotRangePadding -> 0,
Filling -> -1, FillingStyle -> Black, Frame -> False,
Axes -> False, ImageSize -> {2048, 1024},
AspectRatio -> 1024/2048], "Image", ColorSpace -> "GrayScale"];
ImageCompose[night, SetAlphaChannel[day, mask]]