Wednesday 15 April 2015

javascript - How do browsers render contents of a canvas element -



javascript - How do browsers render contents of a canvas element -

how browser render contents of html canvas? things context.lineto(x, y). there must component converts function calls pixel data. want know if there way pixel info without rendering somewhere.

i want know if can run sort of stand lone javascript engines (v8) , pass javascript code , pixel info output.

what want know if there way pixel info without rendering somewhere.

natively no, there no way pixel info besides using canvas (technically bitmap) rasterize vector info (paths) in browser.

the browsers typically utilize underlying graphic core scheme (ie. directx etc.) rasterization. have no access through browser (nor on top of v8/node.js unless modify it). sub-system handle rasterizing of lines, circles, arcs , ellipses pixels, fill polygons , forth, not building array of point positions simply "walking" slope (put simple of course of study - fill uses different approach though based on line scanning).

for lines means current pixel illustration registered temporary relative previous one, circle/ellipses pixel typically in add-on mirrored here , there. in essence there no registration of absolute or relative pixel positions can extracted after rasterization took place.

if after array positions of each pixel need implement own solution of algorithm. unless need special reason cannot see why not utilize canvas much faster you, or work in vector space directly, rasterize them when needed.

you can utilize javascript implement using various line algorithms , have out there. see marke's first-class reply starter. did retro-canvas while can have @ see algorithms used in javascript. optimized well.

in add-on need implement 2d matrix rotation, scaling , translation if want flexibility/compatibility of canvas.

one thing need aware of though approach eliminate anti-aliasing of import smooth looking result. you'll have add together on top if need (you seek sync internal lines drawn on canvas need exact same @ stage can problem linux, mac, windows etc. uses different graphic sub-systems perchance minor variations in result) , require register additional pixels different colors/alpha values.

some resources:

bresenham line , circle algorithm efla line algorithm bresenham ellipse algorithm polygon fill algorithm

these basic building blocks typical polygonal shape (an arc part of circle didn't include this, there exists optimized approaches out there).

you can in add-on utilize catmull/rom , cardinal splines bezier typically implemented 2. order (quadratic, 1 command point) , 3. order (two command points), if want ability create smoother shapes, font outlines , forth.

another possible approach draw shapes on off-screen canvas in white color on black or transparent background, scan each line , set each pixel find it's position , relative color (to alpha) in array. however, not give continuous lines, each pixel's position whatever part of...

javascript html5 web html5-canvas

No comments:

Post a Comment