[英]Where to place image(canvas, 0, 0) in a p5.js programme?
I read the official documentation regarding the image() function but it has no information on this aspect of the function.我阅读了有关 image() 函数的官方文档,但没有关于该函数这方面的信息。 The basic structure of my programme is as follows:
我的程序的基本结构如下:
function setup() {
createCanvas(400, 400);
sec = createGraphics(400, 400);
}
function draw() {
sec.background(255)
background(0)
image(sec, 0, 0)
}
I am confused as to where I should place the background functions of the main and secondary canvas and the image(sec, 0, 0) function.我很困惑我应该在哪里放置主画布和辅助画布的背景功能以及 image(sec, 0, 0) 功能。
What I am trying to achieve is for the secondary canvas to be transparent and above the main canvas.我想要实现的是使辅助画布透明并位于主画布上方。 Both of the canvases should be visible.
两个画布都应该可见。
I think what you are looking for is the tint() function:我认为您正在寻找的是tint()函数:
Sets the fill value for displaying images.
设置显示图像的填充值。 Images can be tinted to specified colors or made transparent by including an alpha value.
图像可以着色为指定的颜色或通过包含 alpha 值使其透明。
In this codepen I reused your code but changed the colors of the backgrounds to red and green to be able to see which one is displayed and I used tint()
to change the transparency of the second canvas.在这个 codepen 中,我重用了你的代码,但将背景的颜色更改为红色和绿色,以便能够看到显示的是哪个,我使用
tint()
来更改第二个画布的透明度。
let tintAlpha = 0;
function draw() {
tintAlpha++;
sec.background(0, 255, 0) // sec background is green
background(255, 0, 0) // primary background is red
tint(255, tintAlpha) // when alpha rises the secondary background is less and less transparent
image(sec, 0, 0)
}
I think it yields the result you are trying to get.我认为它产生了你想要得到的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.