PutPixel(x, y, r, g, b)

Monkey Forums/Monkey Programming/PutPixel(x, y, r, g, b)

therevills(Posted 2011) [#1]
Heres PutPixel for HTML5:

diddy.putPixel=function(x, y, r, g, b){
	//game_console.value = x +","+y+","+r+","+g+","+b;
	var tcanvas=document.getElementById("GameCanvas").getContext("2d")
	var imageData = tcanvas.createImageData(1, 1);
	var index = (x + y * imageData.width) * 4;

	imageData.data[0] = r;
	imageData.data[1] = g;
	imageData.data[2] = b;
	imageData.data[3] = 0xff; // 0xff opaque
	tcanvas.putImageData(imageData, x, y);
};


Monkey Code:

Extern

Function PutPixel:Int(x:Int, y:Int, r:Int, g:Int, b:Int)="diddy.putPixel"

Public

...
Method OnRender:Int()
	PutPixel(MouseX(), MouseY(), Rnd(255),Rnd(255),Rnd(255))
...
End