I'm working on a (very, very last minute) Halloween prop. I'm making a recreation of the "Book" from Hocus Pocus, and followed this "Uncanny Eyes" tutorial to create a (very convincing!) eye for the prop.
My only problem is I added some material around the eye to look like eyelids, and now when the eye looks down it's almost impossible to see; and doesn't look very natural.
Is there a way to modify the Uncanny Eye code to keep the random eye movement - but limit the Y-Axis to only allow upward eye movement? I perused through the code and a solution wasn't popping out at me; and my attempts at modification were unsuccessful.
Any help? I promise to post pictures in return!
Uncanny Eyes - Limiting Y-Axis Movement
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Uncanny Eyes - Limiting Y-Axis Movement
This should be a start:
It will replace the code in the default sketch between lines 291 and 296.
Only the test in the while() statement has actually been changed. That loop generates random positions within a square surrounding the current position, then checks to see if the position is also within the circle of legal positions for the eye.
The test I added also rejects positions whose Y value is more than 3/4 of the way to one edge.
I'm not positive whether 'looking up' is positive or negative, so you may need to swap that test with:
if I guessed wrong.
Changing the value '768' will change how far the eye can go. Larger values go closer to the edge of the circle, smaller values stay closer to the center.
Code: Select all
do { // Pick new dest in circle
eyeNewX = random(1024);
eyeNewY = random(1024);
dx = (eyeNewX * 2) - 1023;
dy = (eyeNewY * 2) - 1023;
} while(
(dy > 768)
|| ((d = (dx * dx + dy * dy)) > (1023 * 1023))
); // Keep trying
Only the test in the while() statement has actually been changed. That loop generates random positions within a square surrounding the current position, then checks to see if the position is also within the circle of legal positions for the eye.
The test I added also rejects positions whose Y value is more than 3/4 of the way to one edge.
I'm not positive whether 'looking up' is positive or negative, so you may need to swap that test with:
Code: Select all
(dy < -768)
Changing the value '768' will change how far the eye can go. Larger values go closer to the edge of the circle, smaller values stay closer to the center.
- cbud
- Posts: 14
- Joined: Tue Jan 31, 2012 4:28 pm
Re: Uncanny Eyes - Limiting Y-Axis Movement
Thank you for the help! It was greatly appreciated! (Unfortunately it didn't make it in time for Halloween; but the book was still crazy convincing and everyone was asking how it was done.)
I posted two images on imgur; you can see them here: http://imgur.com/a/R4gbQ
Also, I decided to limit the Y-movement both up and down; I got it to match the "shape" of the eyelids nicely! Here's the code I added (Between 291 and 296, of course):
I really should write a tutorial for it... however I've decided version 2.0 will need to have 3D printed snake accents!
Thank you again for the help!
I posted two images on imgur; you can see them here: http://imgur.com/a/R4gbQ
Also, I decided to limit the Y-movement both up and down; I got it to match the "shape" of the eyelids nicely! Here's the code I added (Between 291 and 296, of course):
Code: Select all
do { // Pick new dest in circle
eyeNewX = random(1024);
eyeNewY = random(1024);
dx = (eyeNewX * 2) - 1023;
dy = (eyeNewY * 2) - 1023;
} while(
(dy > 500 || dy < -900)
|| ((d = (dx * dx + dy * dy)) > (1023 * 1023))
); // Keep trying
Thank you again for the help!
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Uncanny Eyes - Limiting Y-Axis Movement
Nice build! Thanks for posting it.
Please be positive and constructive with your questions and comments.