We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › picture not drawn when calling rotate()
Page Index Toggle Pages: 1
picture not drawn when calling rotate() (Read 377 times)
picture not drawn when calling rotate()
May 15th, 2009, 10:26am
 
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  Huh 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
Re: picture not drawn when calling rotate()
Reply #1 - May 15th, 2009, 10:38am
 
Looks like you are rotating around the left corner of the sketch.

So a point at 50,50 rotated say 90 degrees will end up at -50,50 (not visible).

If you translate to center screen then rotate, it will be relative to center.
Don't forget to adjust the x,y positions of what you are drawing.
Re: picture not drawn when calling rotate()
Reply #2 - May 15th, 2009, 2:57pm
 
oh damn... its so obviously  Embarrassed
Thanks  Wink
Page Index Toggle Pages: 1