Random Eye Movement Pseudo code

const int NUM_EYE_MOVEMENTS = 500; // we generate 500 random eye movements


// these variables determin how the eye randomly moves

int[NUM_EYE_MOVEMENTS] eyeMovementX;

int[NUM_EYE_MOVEMENTS] eyeMovementY;

boolean moveToTarget = false;


int currentEyeMovement; // the index in eyeMovementsX/Y so we remember where we last moved to;


Motor motorX;

Motor motorY;


int targetX;

int targetY;


/**

* this is a general random number generator

**/

int[] generateRandomNumbers(int n)

{

// TODO: generate n random numbers and return them as an array

}


void setup()

{

currentEyeMovement = 0;

eyeMovementsX = generateRandomNumbers(NUM_EYE_MOVEMENTS);

eyeMovementsY = generateRandomNumbers(NUM_EYE_MOVEMENTS);

motorX = // setup motor that moves left/right

motorY = // setup motor that moves up/down
}



void loop()

{

if(moveToTarget)

{

// interupt the move to to to a target

motorX.moveMotorToPosition(targetX);

motorY.moveMotorToPosition(targetY);

moveToTarget = false;

}

else

{

// your eye is randomly moving

// move your eye to currentEyeMovement. I am guessing at this because it depends on how you eye moves. I am assuming you have 2 motors, the first motor moves the eye left/right (X) and the second motor moves up and down (Y)

// NOTE: the next 2 lines depend on what motor library you use so I am guessing at it

motorX.moveMotorToPosition(eyeMovementsX[currentEyeMovement]);

motorY.moveMotorToPosition(eyeMovementsY[currentEyeMovement]);


currentEyeMovement = currentEyeMovement+1;

if(currentEyeMovement = NUM_EYE_MOVEMENTS)

{

// we just moved to the last eye position. for simplicity I am just going to repeat the last movements.

// if you wanted to we could generate new random eye movements here

currentEyeMovement = 0;

}

}// end else

// while the eye is moving check for a target

if(sensor.foundTarget())

{

targetX = sensor.getTargetX();

targetY = sensor.getTargetY();

moveToTarget = true;

}

delay(500);// give the eye time to move to the target

}


Comments

  • Nice!

    Here's a sample of some random eye movement I was playing with a while ago for my Skeksis project:  http://123d.circuits.io/circuits/233191-skeksis

    The code is not working perfectly in their current IDE version, and needs some work, but it's a starting point!

    Eventually I plan to add automated blink behavior tied into the eye movement.

    /Chris
Sign In or Register to comment.