Html canvas(pattern with an image)

Im writing this code but i don’t know why the pattern is wrong. Thank’s.

var mycanvas = myfunc();

function myfunc(){
			this.canvas = document.createElement('canvas');
			this.canvas.setAttribute("ID","mycanvas");
			this.canvas.width = "500";
			this.canvas.height = "500";
			this.img = new Image(); 		
			this.img.src = 'img-gioco/gattino.png';
			this.ctx = this.canvas.getContext('2d');
			this.img.addEventListener("load",myDraw);
			document.body.appendChild(this.canvas);
		}
	
function myDraw(){
	
	var tileX = 0;
	var tileY = 0;
	var w = 100;
	var h = 100;
		
	var myarray = [];	
	
		for(var i=0; i<5; i++){
			myarray.push(tileX);
			myarray.push(tileY);				
			tileX += w;
			tileY = 0;
		}
	
		for(var i=0; i<myarray.length; i++){
			ctx.drawImage(img,myarray[i],myarray[i+1]);
			console.log(myarray[i]);
		}
}

Please define “wrong”.

I would create a pattern whit a single image. In my code there is a console.log but i dont understand i see the erroneous pattern

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.