<img id="moon" src="http://clipart-library.com/img/1669854.png" style="display: none;">
<img id="" src="http://clipart.info/images/ccovers/1495916688stars-png-with-transparent-background.png" style="display: none;">
<canvas id="a" width="1000" height="1000">
This text is displayed if your browser does not support HTML5 Canvas.
</canvas>
JavaScript
function draw_hor_line(stroke_color, x1, x2, y1, y2) {
context.strokeStyle = stroke_color;
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.stroke();
}
// Set up!
var a_canvas = document.getElementById("a");
var context = a_canvas.getContext("2d");
canvas_width = 1000;
canvas_height = 1000;
height_all = canvas_height;
width_all = canvas_width;
night_width = 25;
day_width = 50;
color_night = ['#001848', '#604878', '#301860'];
color_day = ['#AACEE2', '#59DBF1', '#B5F9D3'];
color_ground = ['#493829', '#668D3C', '404F24']
for (i = 0; i < 100000; i++) {
width_coordinate = Math.floor(Math.random() * width_all);
height_coordinate = Math.floor(Math.random() * height_all);
if (width_coordinate < canvas_width / 2 && height_coordinate < canvas_width*0.6) {
stroke_color = color_night[Math.floor(Math.random() * color_night.length)]
draw_hor_line(stroke_color, width_coordinate, width_coordinate + night_width, height_coordinate, height_coordinate);
} else if (width_coordinate > canvas_width / 2 && height_coordinate < canvas_width*0.6) {
stroke_color = color_day[Math.floor(Math.random() * color_day.length)]
draw_hor_line(stroke_color, width_coordinate, width_coordinate + night_width, height_coordinate, height_coordinate);
}
}
for (i = 0; i < 100000; i++) {
width_coordinate = Math.floor(Math.random() * width_all);
height_coordinate = Math.floor(Math.random() * height_all);
if (height_coordinate > canvas_width * 0.6) {
stroke_color = color_ground[Math.floor(Math.random() * color_night.length)]
draw_hor_line(stroke_color, width_coordinate, width_coordinate + night_width, height_coordinate, height_coordinate);
}
}
// Draw sun
context.fillStyle = "yellow";
context.beginPath();
context.arc(width_all - 100, 98, 55, 0, 2 * Math.PI); //units right, down, radius of circle, how much of a circle, it is, where the circle starts, where the cicle ends
context.closePath();
context.fill();
// Draw moon
var img...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.