domenica 28 dicembre 2014

Cielo stellato e variazioni.

Seguiamo pedissequamente...

C'era il fatto di disegnare 50 stelle casuali.
Bene, adesso ho fatto un po' di variazioni e ho disegnato un cielo stellato più ampio, con stelle gialle.
<!DOCTYPE html>
<html>
<head>
<script>
function canvasSpaceGame(){
	canvas=document.getElementById("myCanvas");
	
	ctx=canvas.getContext("2d");
	
	
	ctx.fillStyle="black";
	ctx.rect(0,0,1000,600);
	ctx.fill();
	
	stars();     
}

function stars(){
	for(var i=0;i<6000;i++){
		x=Math.floor(Math.random()*999);
		y=Math.floor(Math.random()*999);
		
		ctx.fillStyle="yellow"
		
		ctx.beginPath();
		ctx.arc(x,y,1,Math.PI*2,false);
		ctx.closePath();
		ctx.fill();
	}
}
		

window.addEventListener("load",function(){canvasSpaceGame()});
</script>
</head>
<body>
	<canvas id="myCanvas" width="1000" height="600">
	</canvas>
</body>
</html> 
Come posso fare per fare alcune stelle gialle e altre bianche?
<!DOCTYPE html>
<html>
<head>
<script>
function canvasSpaceGame(){
	canvas=document.getElementById("myCanvas");
	
	ctx=canvas.getContext("2d");
	
	
	ctx.fillStyle="black";
	ctx.rect(0,0,1000,600);
	ctx.fill();
	
	stars();     
}

function stars(){
	for(var i=0;i<3000;i++){
		x=Math.floor(Math.random()*999);
		y=Math.floor(Math.random()*999);
		
		ctx.fillStyle="yellow"
		
		ctx.beginPath();
		ctx.arc(x,y,1,Math.PI*2,false);
		ctx.closePath();
		ctx.fill();
		
		x=Math.floor(Math.random()*999);
		y=Math.floor(Math.random()*999);
		
		ctx.fillStyle="white"
		
		ctx.beginPath();
		ctx.arc(x,y,1,Math.PI*2,false);
		ctx.closePath();
		ctx.fill();
	}
	
}
		

window.addEventListener("load",function(){canvasSpaceGame()});
</script>
</head>
<body>
	<canvas id="myCanvas" width="1000" height="600">
	</canvas>
</body>
</html> 

Nessun commento:

Posta un commento