javascript - html5 canvas, image as background for arch or circle -
hello stackoverflow people, first post here.
i have circle on canvas, , circle divided sky , ground portion, , (analog) clock looking, imagine hands of clock extended edge of circle, making 2 'pie slices'. , hands moving. have different (background) images 2 portions. have gradiant fill, change gradiant appropriate images. images must fill whole portion of 'pie slice'. code far:
// ground portion of circle var lingrad=ctx.createlineargradient(center.x, center.y,center.x,main_radius*2); lingrad.addcolorstop(0,'green'); lingrad.addcolorstop(1,'brown'); ctx.fillstyle=lingrad; ctx.beginpath(); ctx.moveto(center.x, center.y); ctx.lineto(x2, y2); ctx.arc(center.x, center.y, radius, d2r(z1 + 90), d2r(v1 + 90), false); ctx.moveto(center.x, center.y); ctx.lineto(x1, y1); ctx.closepath(); ctx.fill(); // sky portion of circle var lingrad1=ctx.createlineargradient(center.x,0,center.x,center.y); lingrad1.addcolorstop(0,'yellow'); lingrad1.addcolorstop(0.5,'yellow'); lingrad1.addcolorstop(1,'cyan'); ctx.fillstyle=lingrad1; ctx.beginpath(); ctx.moveto(center.x, center.y); ctx.lineto(x2, y2); ctx.arc(center.x, center.y, radius, d2r(z1 + 90), d2r(v1 + 90), true); ctx.moveto(center.x, center.y); ctx.lineto(x1, y1); ctx.closepath(); ctx.fill();
thank , sorry english
you can use example clip()
first defining clip path using arc()
, call clip()
, draw in 2 images in each half.
a simple example:
var img1 = new image, img2 = new image, count = 0, ctx = c.getcontext("2d"); img1.onload = img2.onload = go; img1.src = "//i.stack.imgur.com/eu6kb.jpg"; img2.src = "//i.stack.imgur.com/umea9.jpg"; function go() { if (++count < 2) return; // make sure both images has loaded // save state restoring way remove clip-mask ctx.save(); // define clip-mask using path operations ctx.arc(75, 75, 75, 0, 6.28); ctx.clip(); // draw in top image ctx.drawimage(img1, 0, 0); // draw in bottom image ctx.drawimage(img2, 0, 75); // remove clip mask ctx.restore(); }
<canvas id=c></canvas>
you can of course use position, size clipping arguments of drawimage()
taste.
Comments
Post a Comment