text 流动的eyes.pde
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 流动的eyes.pde相关的知识,希望对你有一定的参考价值。
//PImage pupil;
Pupil p1;
Pupil p2, p3, p4, p5, p6, p7;
PImage img1;
PVector eye = new PVector(300, 300);
void setup(){
size(1000, 1000);
imageMode(CENTER);
img1 = loadImage("weird guy.png");
img1.resize(1000, 1000);
image(img1,width/2.0, height/2.0);
//pupil = loadImage("blackcircle.png");
// X Y DIAMETER EYEX EYEX EYERADIUS
p1 = new Pupil(611, 407, 30, 611, 407, 25);
p2 = new Pupil(549, 293, 30, 549, 293, 25);
p3 = new Pupil(424, 273, 10, 424, 273, 12);
p4 = new Pupil(421, 369, 20, 421, 369, 15);
p5 = new Pupil(344, 320, 8, 344, 320, 8);
p6 = new Pupil(308, 349, 10, 308, 349, 10);
p7 = new Pupil(349, 367, 10, 349, 367, 9);
//p2 = new Pupil(random(width), random(height),90, width/2, height/2);
}
void draw(){
image(img1,width/2.0, height/2.0);
/*// if pupils touch background turns green
float d = dist(p1.x, p1.y, p2.x, p2.y);
if (d < p1.diameter/2 + p2.diameter/2) {
background(0, 255, 0);
}*/
//image(pupil, 0,0);
p1.moveToMouse();
p1.display();
p1.top();
p2.moveToMouse();
p2.display();
p2.top();
p3.moveToMouse();
p3.display();
p3.top();
p4.moveToMouse();
p4.display();
p4.top();
p5.moveToMouse();
p5.display();
p5.top();
p6.moveToMouse();
p6.display();
p6.top();
p7.moveToMouse();
p7.display();
p7.top();
/*
p2.moveToMouse();
p2.display();
p2.top();
p1.constrainToEye();*/
}
/*
static final color BG = -4;
void setup(){
size(200, 200);
background(BG);
ellipseMode(CENTER);
noStroke();
fill(0);
noLoop();
}
void draw(){
ellipse(width/2, height/2, 190, 190);
saveTransparentCanvas(BG, "img");
}
void saveTransparentCanvas(final color bg, final String name) {
final PImage canvas = get(0,0,height,width);
canvas.format = ARGB;
final color p[] = canvas.pixels, bgt = bg & ~#000000;
for (int i = 0; i != p.length; ++i) if (p[i] == bg) p[i] = bgt;
canvas.updatePixels();
canvas.save("blackcircle.png");
}*/
class Pupil {
float x;
float y;
float diameter;
float eyex;
float eyey;
float eyeRadius;
float d;
Pupil(float tempx, float tempy, float tempD, float tempEX, float tempEY, float tempER) {
x = tempx;
y = tempy;
diameter = tempD;
eyex = tempEX;
eyey = tempEY;
eyeRadius = tempER;
}
void moveToMouse() {
if (abs(mouseX - x) > 0.1){
x = x + (mouseX - x) * 0.05;
}
if (abs(mouseY - y) > 0.1){
y = y + (mouseY - y) * 0.05;
}
}
void display() {
PVector circle = new PVector(eyex, eyey);
stroke(0);
fill(25);
if (mousePressed == true) {
fill(int(random(255)), int(random(255)), int(random(255)));
}
PVector m = new PVector(mouseX, mouseY);
if (dist(x,y, eyex, eyey) > (eyeRadius - diameter/2)){
m.sub(circle);
m.normalize();
m.mult(eyeRadius - diameter/2);
m.add(circle);
ellipse(m.x, m.y, diameter, diameter);
} else {
ellipse(x, y, diameter, diameter);
}
}
void top() {
if (y < diameter/2) {
y = diameter/2;
}
}
}
以上是关于text 流动的eyes.pde的主要内容,如果未能解决你的问题,请参考以下文章