html - Getting pixel color from bitmap (javascript) not working -
i working on simple game using three.js on javascript. need utilize bitmap create scenario. bitmap 15x15 pixel
all want rgb value every pixel on image. code have far:
function world() { var cubematrix = []; this.makescenario = function(scene) { var context = document.getelementbyid('canvas').getcontext('2d'); var img = new image(); img.src = 'bitmap/map1.bmp'; context.drawimage(img,0,0); var imgdata = context.getimagedata(0, 0, canvas.height, canvas.width); var cube = new cube(); cube.makecube(1,1,movable_cube); var i, j; for(i = 0; < matrix_size; i++) //x { for(j = 0; j < matrix_size; j++) //z { var rgba = getpixel( imagedata, i, j); if(rgba.r == 255 && rgba.g == 255 && rgba.b == 255) //white { cube.pushcube(); } } } } } this code i'm using pixel
function getpixel( imagedata, x, y ) { var position = ( x + imagedata.width * y ) * 4, info = imagedata.data; homecoming { r: data[ position ], g: data[ position + 1 ], b: data[ position + 2 ]}; } also added html body:
<canvas id="canvas" width="15"height="15"></canvas> i created cube , changed position when entering "if" (enters when color white), cube never moves @ all!
i made tests , found out rgb values 0.
can please help me this? give thanks you!
note: functions on different file html, linked by
<script src="world.js"></script> javascript html bitmap three.js getpixel
No comments:
Post a Comment