覆盖矩形时更改文本填充颜色 - 处理
我这里有一个小动画,它以重复的无缝模式进行动画处理。
我在画布中间有白色的文本,环形形状经过该文本。我想要解决的是,当白条经过文本时,它会变成黑色。因此,当白色条的一半越过“文本”的 T 时,T 的一半将是黑色的,而未被覆盖的一半在对角线上仍将是白色的。
这是通过拆分字母来完成的吗?通过遮罩或使用矢量图像?
这是我想要实现的目标的图形示例。
drawLine wob1;
drawLine wob2;
drawLine wob3;
drawLine wob4;
drawLine wob5;
PFont helv;
drawText title;
void setup() {
//frame.setResizable(true);
size(320, 480);
smooth();
frameRate(50);
wob1 = new drawLine(0);
wob2 = new drawLine(200);
wob3 = new drawLine(400);
wob4 = new drawLine(600);
wob5 = new drawLine(800);
title = new drawText();
}
void draw() {
background(#000000);
wob1.increment();
wob1.display(#ffffff);
wob1.pos();
wob1.boundary();
wob2.increment();
wob2.display(#ffffff);
wob2.boundary();
wob3.increment();
wob3.display(#ffffff);
wob3.boundary();
wob4.increment();
wob4.display(#ffffff);
wob4.boundary();
wob5.increment();
wob5.display(#ffffff);
wob5.boundary();
title.rendertitle(#ffffff;
}
class drawLine {
int x = -480;
int y = 0;
int count;
drawLine(int offset) {
this.x = this.x + offset;
}
void increment() {
this.x += 3;
this.y += 4;
}
void display(int col) {
//noStroke();
fill(col);
//translate(0,0);
rectMode(CENTER);
rotate(-PI/3.0);
rect(x,y,100,3000);
rotate(PI/3.0);
}
void pos() {
println(this.x);
//if(this.x >= -218 && this.x <= 207){ colr = #000000; } else { colr = #ffffff; }
}
void boundary() {
if(this.x > 520) {
this.x = -480; this.y = 0;
}
}
}
class drawText {
drawText() {
helv = loadFont("Helvetica-Bold.vlw");
}
void rendertitle(int colr) {
fill(colr);
textFont(helv, 30);
text("Text goes here", width/2, height/2, 240, 50);
}
}
I have this little animation here that animates in a repeated seamless pattern.
I have text, colored white, in the middle of the canvas that the looped shapes pass over. What I am trying to work out is when the white bars pass over the text it turns black. So as half the white bar goes over the T of "Text", half the T would be black and the half not covered would be still white on a diagonal.
Would this be done with splitting up the letters? By doing masking, or using vector images?
Here is a graphic example of what I'm trying to achieve.
drawLine wob1;
drawLine wob2;
drawLine wob3;
drawLine wob4;
drawLine wob5;
PFont helv;
drawText title;
void setup() {
//frame.setResizable(true);
size(320, 480);
smooth();
frameRate(50);
wob1 = new drawLine(0);
wob2 = new drawLine(200);
wob3 = new drawLine(400);
wob4 = new drawLine(600);
wob5 = new drawLine(800);
title = new drawText();
}
void draw() {
background(#000000);
wob1.increment();
wob1.display(#ffffff);
wob1.pos();
wob1.boundary();
wob2.increment();
wob2.display(#ffffff);
wob2.boundary();
wob3.increment();
wob3.display(#ffffff);
wob3.boundary();
wob4.increment();
wob4.display(#ffffff);
wob4.boundary();
wob5.increment();
wob5.display(#ffffff);
wob5.boundary();
title.rendertitle(#ffffff;
}
class drawLine {
int x = -480;
int y = 0;
int count;
drawLine(int offset) {
this.x = this.x + offset;
}
void increment() {
this.x += 3;
this.y += 4;
}
void display(int col) {
//noStroke();
fill(col);
//translate(0,0);
rectMode(CENTER);
rotate(-PI/3.0);
rect(x,y,100,3000);
rotate(PI/3.0);
}
void pos() {
println(this.x);
//if(this.x >= -218 && this.x <= 207){ colr = #000000; } else { colr = #ffffff; }
}
void boundary() {
if(this.x > 520) {
this.x = -480; this.y = 0;
}
}
}
class drawText {
drawText() {
helv = loadFont("Helvetica-Bold.vlw");
}
void rendertitle(int colr) {
fill(colr);
textFont(helv, 30);
text("Text goes here", width/2, height/2, 240, 50);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用两个生成的图像制定了一个解决方案。第一个
imgText
仅包含黑色背景前面的文本(白色)。第二个imgMask
用作遮罩,因此包含屏幕线条图案。可以在setup()
部分中仅生成一次第一个(文本图像);因为你的类型不会改变/移动或变换。如果要达到“扫描”线条的效果,则必须每帧更新掩模图像。通过offset
参数的移位,每次draw()
循环都会发生这种情况。其余的都是非常基本的;在显示实际的蒙版图像之前,清除每一帧的背景并绘制
imgText
的反转版本。I worked out a solution using two generated images. The first one
imgText
contains only text (white) in front of black background. The second oneimgMask
functions as mask and therefore contains the screen line pattern. It's fine to generate the first (text image) only once within thesetup()
part; because your type doesn't change/move or transform. The mask image has to be updated every frame if you want to achieve the effect of "scanning" lines. This happens everydraw()
loop through the shift of theoffset
parameter.The rest is pretty basic; clear the background every frame and draw the inverted version of
imgText
before you display the actual masked image.