processing java 2d_如何使用Processing 2.0(Java)在元素周围绘制光晕?

本文介绍了一种通过在对象后面绘制一系列渐变和变暗的椭圆来创建光晕效果的方法。示例代码展示了如何根据需要调整透明度和形状,以实现自定义的光晕视觉效果。
摘要由CSDN通过智能技术生成

我不知道内置的方式,至少一般(你没有提到你的代码是如何组织的)。但是,这是一个DIY方法的快速演示。这个想法是,你在对象后面画出一系列渐变和变暗的椭圆。你可能想根据自己的喜好来调整硬编码的数字,也许它可以非线性地变得透明(可能更暗一些,也许会更暗)。

Thing thing1;

Thing thing2;

void setup(){

size(300,300);

smooth();

thing1 = new Thing(1*width/3,height/2,false);

thing2 = new Thing(2*width/3,height/2,true);

}

void draw(){

background(100);

stroke(0);

line(100,100,250,250);

line(150,100,300,250);

thing1.display();

thing2.display();

}

class Thing

{

PVector loc;

boolean glowing;

Thing(int x, int y, boolean glow){

loc = new PVector(x,y);

glowing = glow;

}

void display(){

if(glowing){

//float glowRadius = 100.0;

float glowRadius = 100.0 + 15 * sin(frameCount/(3*frameRate)*TWO_PI);

strokeWeight(2);

fill(255,0);

for(int i = 0; i < glowRadius; i++){

stroke(255,255.0*(1-i/glowRadius));

ellipse(loc.x,loc.y,i,i);

}

}

//irrelevant

stroke(0);

fill(0);

ellipseMode(CENTER);

ellipse(loc.x,loc.y,40,40);

stroke(0,255,0);

line(loc.x,loc.y+30,loc.x,loc.y-30);

line(loc.x+30,loc.y,loc.x-30,loc.y);

}

}

WeC7r.png

此外,如果你的对象不是圆形对称的,你可以不喜欢以下。它会查看对象的像素,并在找到非空白像素的任何位置绘制几乎透明的椭圆。尽管这是一个相当混乱的解决方案。遵循对象的边缘或者其他方法可能会更好。我希望这给你一些想法!

Thing thing1;

void setup(){

size(300,300);

background(0);

thing1 = new Thing();

thing1.display();

}

void draw(){}

class Thing

{

PGraphics pg;

Thing(){

pg = createGraphics(200,200);

}

void display(){

pg.beginDraw();

pg.background(0,0);

pg.strokeWeight(10);

pg.stroke(255,100,0);

pg.line(100,50,100,150);

pg.line(75,50,125,50);

pg.line(75,150,125,150);

pg.line(30,100,170,100);

pg.endDraw();

PGraphics glow = createGraphics(200,200);

glow.beginDraw();

glow.image(pg,0,0);

glow.loadPixels();

glow.fill(255,3);

glow.noStroke();

//change the +=2 for different effects

for(int x = 0; x < glow.width; x+=2){

for(int y = 0; y < glow.height; y+=2){

if(alpha(glow.pixels[y*glow.width+x]) != 0) glow.ellipse(x,y,40,40);

}

}

glow.endDraw();

//draw the glow:

image(glow,50,50);

//draw the sprite:

image(pg,50,50);

}

}

5Sqt8.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值