[英]How to set the background of an ellipse in javascript to an image?
I'm using javascript with the p5 library and currently I only know how to use the fill() function to fill an ellipse with a color.我将 javascript 与 p5 库一起使用,目前我只知道如何使用 fill() function 用颜色填充椭圆。 Is there a way to set the ellipse's background to an image?
有没有办法将椭圆的背景设置为图像?
Rather that setting a background you could try using the mask() method combined with the ellipse() method:而不是设置背景,您可以尝试将mask()方法与ellipse()方法结合使用:
let photo, maskImage function preload() { photo = loadImage('https://picsum.photos/300/200') } function setup() { createCanvas(600, 200) background(125) image(photo, 0, 0); maskImage = createGraphics(300, 200) maskImage.ellipse(150, 100, 250, 150) photo.mask(maskImage) image(photo, 300, 0) }
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.