Roboface eye position

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ruperty
 
Posts: 49
Joined: Sun Mar 01, 2015 7:41 am

Roboface eye position

Post by ruperty »

Trying out the roboface example for the adafruit 8x8 matrix it looks to me that the code for choosing an eye position does not cover the whole matrix. If I understand things correctly any position on row 6 is excluded (apart from position 3). Any reason why that was done?

For example, position 6,4 -> (6-3) = 3 and (4-3) = 1
3*3 + 1*1 = 10, so is rejected.

Code: Select all

 do { // Pick random positions until one is within the eye circle
        newX = random(7); newY = random(7);
        dX   = newX - 3;  dY   = newY - 3;
      } while((dX * dX + dY * dY) >= 10);      // Thank you Pythagoras

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Roboface eye position

Post by pburgess »

It's to keep the pupil inside a roughly circular-ish area within the eye. Since the pupil is 2 pixels high and wide, row/column 3 can be considered the center. (dX * dX + dY * dY) is the square of the distance from the center. Rather than using a square root, which is slow, we can compare against the square of some threshold distance to get the same effect. sqrt(10.0) is about 3.16, so the four cardinal directions -just- squeeze by with one extra pixel of movement in that direction

A map of allowable landing pixels (marked 'X', with '+' at the 'center'):

Code: Select all

000X0000
0XXXXX00
0XXXXX00
XXX+XXX0
0XXXXX00
0XXXXX00
000X0000
00000000

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”