Romeno’s Self Portrait

I wanted to go for a more interactive self portrait which resulted in me focusing more on the interactivity rather than the visual detail of my face. I used the keyPressed function to trigger the movement of my character using the TAB key, the ‘q’ key for closing/opening my eyes and the ‘w’ key for changing directions of the character’s movement. I added a background image of our campus and used an image for my hair.

The code is pasted below:

int faceWidth=200;//150
int faceHeight=200;
int faceCenterX=0;
int faceCenterY=220;
boolean moveFront=true;
int moveFrontVal=5;
boolean eyesOpen=true;
//int pos=0;
int pos=0;
int mouseXPrev=0;
float[] colors=new float[]{random(255),random(255),random(255)};
int sWidth=1000;
int sHeight=600;
int ground=600;
boolean light=true;
PImage bg;
PImage hair;
int changeDirFace=0;
int opacity=0;
int maxY=faceCenterY;
boolean stayStill=true;
void setup() {
size(1000,600);
bg = loadImage("nyu.jpg");
bg.resize(1000, 600);
rotate(PI/6);
hair = loadImage("hair.png");
hair.resize(200,100);
}
void draw() {
  background(bg);
  /*if(light) {
  background(255);
  } else {
  background(0);
  }*/
  fill(0);
  //arc(faceCenterX-40, faceCenterY-((faceHeight/2))-25, 85, 50, PI, 0);
  image(hair, faceCenterX-changeDirFace-95,faceCenterY-130);
  //rect(faceCenterX-70-changeDirFace,faceCenterY-((faceHeight/2))-15,135,40);

fill(192,192,192);
if(moveFront) {
changeDirFace=-10;
} else {
changeDirFace=10;
}
rect(faceCenterX-130,faceCenterY+(faceHeight/2)-10,230,10);
ellipse(faceCenterX-changeDirFace,faceCenterY+100,faceWidth-55,faceHeight);
fill(215,159,102);
stroke(0);
ellipse(faceCenterX-changeDirFace,faceCenterY,faceWidth,faceHeight);
noStroke();
fill(0);
ellipse(faceCenterX-40,faceCenterY-50,50,50);
ellipse(faceCenterX+30,faceCenterY-50,50,50);
if(eyesOpen) {
fill(255);
}
ellipse(faceCenterX-30,faceCenterY-50,20,20);
ellipse(faceCenterX+45,faceCenterY-50,20,20);
fill(0);
//rect(faceCenterX-60,faceCenterY+35,pos,6);
fill(192,192,192);
rect(faceCenterX-130,faceCenterY+(faceHeight/2),230,200);

//rect(faceCenterX-130,faceCenterY+(faceHeight/2),400,35);

fill(colors[0],colors[1],colors[2]);
rect(faceCenterX-100,faceCenterY+(faceHeight/2),170,200);
fill(0);
arc(faceCenterX, faceCenterY+35, 100, 50, 0, PI);
fill(215,159,102);

arc(faceCenterX-changeDirFace, faceCenterY+(faceHeight/2), 85, 50, 0, PI);
if(mouseX!=mouseXPrev) {
if(pos<140) {
pos+=10;
} else {
pos=0;
} 



}
if(stayStill==false) {
faceCenterX+=moveFrontVal;
if((faceCenterX>(sWidth+(faceWidth/2))) && (moveFrontVal==5)) {
faceCenterX=-(faceWidth/2);
}

if((faceCenterX<(0-(faceWidth/2))) && (moveFrontVal==-5)) {
faceCenterX=(sWidth+(faceWidth/2));
}
mouseXPrev=mouseX;


}
if (faceCenterY+280>ground) { //+200
faceCenterY=280;
}

faceCenterY+=2;
}
void keyPressed() {
  if (key==TAB){
stayStill=!stayStill;} 
if (key=='q'){
  eyesOpen= !eyesOpen;
}
if(key=='w'){
  colors[0]=random(255);
colors[1]=random(255);
colors[2]=random(255);
  //eyesOpen= !eyesOpen;
  if(faceCenterY>maxY) {
faceCenterY-=50;
  }
if (moveFront==false) {
moveFrontVal=-5;
} else {
moveFrontVal=5;
}
moveFront=!moveFront;

if(((faceCenterX-100)<mouseX) && (mouseX<(faceCenterX+70))&& ((faceCenterY+(faceHeight/2)+200)<mouseY) && (mouseY<(faceCenterY+(faceHeight/2)))) {
  light= !light;
}
}
}
void mousePressed() {


}

 

Leave a Reply

Your email address will not be published. Required fields are marked *