Hello Everybody,
am new to processing (but not programming at all) and trying to place my first steps on processing...
My first quick sketch has two "eyes" following the mouse.
Created a own class for the eye... creating two objects and drawing them...
However if i use rotate() before calling the eye.draw() method, the eyes are not visible
Did i get something wrong?!
applet:
Code:
import Eye.Eye;
import processing.core.*;
public class ProcessingExample extends PApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
private Eye myEye;
private Eye myEye2;
private int eyeRadius = 100;
public void setup() {
size( 800, 800 );
background(255);
smooth();
myEye = new Eye( this, (width/2)+((eyeRadius/4)*3), (height/2), eyeRadius, 0 ); //((eyeRadius/4)*3) );
myEye2 = new Eye( this, (width/2)-((eyeRadius/4)*3), (height/2), eyeRadius, 0 ); //-((eyeRadius/4)*3) );
}
public void draw()
{
// if the rotate is enabled, the shapes seem to be not drawn (maybe they're out of the window?
// rotate( TWO_PI - HALF_PI );
background( 255 );
myEye.draw();
myEye2.draw();
}
}
eye class:
Code:
package Eye;
import processing.core.*;
public class Eye {
/**
*
*/
private static final long serialVersionUID = 1L;
private PApplet parent;
private int eyeRadius;
private float eyeX;
private float eyeY;
private float irisOffset;
private float irisMaxRadius;
private float lineMaxRadius;
private float irisMaxX;
private float irisMaxY;
private float lineMaxX;
private float lineMaxY;
private float angle;
private float mouseDist;
public Eye( PApplet p, int posX, int posY, int radius, int offset )
{
parent = p;
eyeX = posX;
eyeY = posY;
eyeRadius = radius;
irisOffset = offset;
}
public void move( int posX, int posY )
{
eyeX = posX;
eyeY = posY;
}
public void resize( int radius )
{
eyeRadius = radius;
}
public void draw()
{
drawEye();
drawIrirs();
}
private void drawEye()
{
parent.pushMatrix();
parent.translate( eyeX, eyeY );
parent.fill( 125 );
parent.ellipse( 0, 0, eyeRadius, eyeRadius );
parent.popMatrix();
}
private void drawIrirs()
{
parent.pushMatrix();
//calculate the angle from the middle of the eyes!
parent.translate( eyeX-irisOffset, eyeY );
angle = PApplet.atan2( parent.mouseY-(eyeY), parent.mouseX-(eyeX-irisOffset) );
irisMaxX = PApplet.cos( angle );
irisMaxY = PApplet.sin( angle );
lineMaxX = irisMaxX;
lineMaxY = irisMaxY;
mouseDist = PApplet.dist( eyeX-irisOffset, eyeY, parent.mouseX, parent.mouseY );
irisMaxRadius = PApplet.constrain( mouseDist, 0f, ((eyeRadius/2)/2)-8 );
lineMaxRadius = PApplet.constrain( mouseDist, 0f, ((eyeRadius/2)/2) );
irisMaxX *= irisMaxRadius;
irisMaxY *= irisMaxRadius;
lineMaxX *= lineMaxRadius;
lineMaxY *= lineMaxRadius;
parent.popMatrix();
parent.pushMatrix();
parent.translate( eyeX, eyeY );
parent.fill( 255 );
parent.translate( irisMaxX, irisMaxY );
parent.ellipse( 0, 0, (eyeRadius/2), (eyeRadius/2) );
parent.line( 0, 0, lineMaxX , lineMaxY );
// System.out.println( "angle = " + angle + " maxX = " + maxX + " maxY = " + maxY );
parent.popMatrix();
}
}
appreciate your help
shinobi