Skip to content

Commit

Permalink
Day 12 - wet sand
Browse files Browse the repository at this point in the history
  • Loading branch information
floriancargoet committed May 20, 2012
1 parent 317e013 commit b68db20
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions 365.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -218,13 +218,35 @@ Beach.prototype.draw = function(){


ctx.save(); ctx.save();


var waterHeight = (this.ySand - this.yWater);

// sand // sand
ctx.fillStyle = '#F0C479'; ctx.fillStyle = '#F0C479';
ctx.fillRect(0, this.yWater, 500, 500 - this.yWater); ctx.fillRect(0, this.yWater, 500, 500 - this.yWater);


// water // wet sand
var waterHeight = (this.ySand - this.yWater); ctx.beginPath();
ctx.fillStyle = '#e0b576';
ctx.translate(0, this.ySand + this.amplitude2 * 100 + 10);
ctx.scale(1, this.amplitude2);
ctx.arc(0, 0, 50, Math.PI, 0, false);
ctx.arc(100, 0, 50, Math.PI, 0, true);
ctx.arc(200, 0, 50, Math.PI, 0, false);
ctx.arc(300, 0, 50, Math.PI, 0, true);
ctx.arc(400, 0, 50, Math.PI, 0, false);
ctx.arc(500, 0, 50, Math.PI, 0, true);
ctx.scale(1, 1/this.amplitude2);
ctx.translate(0, -this.amplitude2 * 100 - 10);
ctx.lineTo(500, -waterHeight);
ctx.lineTo( 0, -waterHeight);
ctx.closePath();


ctx.fill();

ctx.restore();
ctx.save();

// water
ctx.fillStyle = '#6AB8DF'; ctx.fillStyle = '#6AB8DF';


ctx.beginPath(); ctx.beginPath();
Expand All @@ -241,7 +263,7 @@ Beach.prototype.draw = function(){
ctx.scale(1, 1/this.amplitude); ctx.scale(1, 1/this.amplitude);
ctx.translate(0, -this.amplitude * 100); ctx.translate(0, -this.amplitude * 100);


//foam // foam
ctx.lineWidth = 10; ctx.lineWidth = 10;
ctx.strokeStyle = 'white'; ctx.strokeStyle = 'white';
ctx.stroke(); ctx.stroke();
Expand All @@ -250,11 +272,14 @@ Beach.prototype.draw = function(){
ctx.lineTo( 0, -waterHeight); ctx.lineTo( 0, -waterHeight);
ctx.closePath(); ctx.closePath();
ctx.fill(); ctx.fill();


ctx.restore(); ctx.restore();
}; };
Beach.prototype.update = function(){ Beach.prototype.update = function(){
this.t += 0.01; this.t += 0.01;
this.amplitude = 0.25*(1 + Math.sin(this.t)); this.amplitude = 0.25*(1 + Math.sin(this.t));
this.amplitude2 = 0.25*(1 + Math.sin(this.t - Math.PI/6));
}; };


var Sun = function(ctx, config){ var Sun = function(ctx, config){
Expand Down

0 comments on commit b68db20

Please sign in to comment.