Thread: Canvas Problem
View Single Post
Old 12-05-2012, 02:44 AM   PM User | #38
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
What the heck...
Code:
var cellWidth = 25;
var cellHeight = 25;

var grass=new Image();
var cement=new Image();
grass.src="new/grass.png";
grass.width = cellWidth; grass.height = cellHeight;
cement.src="new/cement.jpg";
cement.width = cellWidth; cement.height = cellHeight;

for( row=0; row < map.length; ++row)
{
    var line = map[row];
    for( column=0; column < line.length; ++column )
    {
	context.drawImage( line[column] == "1" ? grass : cement,
                           column*cellWidth, 
                           row*cellHeight 
        );
    }
}
That's actually getting readable.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote