コード例 #1
0
ファイル: ledeyes.c プロジェクト: ameggs/bot-thoughts-blog
void blink(uint8_t count)
{
	uint8_t i;

	for (i = 0; i < count; i++) {
		// off for 400ms
		eyes(OFF);
		delay(50+(uint8_t)(rand()>>24)); // 50 + up to 256ms
		// on for 3-4s
		eyes(ON);
		delay(1000+(uint16_t)(rand()>>20)); // 3000 + up to 4096ms
	}
}
コード例 #2
0
Acad::ErrorStatus
AsdkSmiley::osnapQuad(
    const AcGePoint3d& pickPoint,
    AcGePoint3dArray& snapPoints) const
{
    AcGeVector3d xoff(0,0,0);
    AcGeVector3d yoff(0,0,0);

    // Osnap quad to the face's quad points
    //
    xoff.x = yoff.y = radius();
    AcGePoint3d center( center() );
    snapPoints.append( center + xoff );
    snapPoints.append( center + yoff );
    snapPoints.append( center - xoff );
    snapPoints.append( center - yoff );
    
    // Osnap quad to the eyes' quad points
    //
    AcGePoint3dArray eyearray;
    AcGePoint3d eyecen;
    eyes( eyearray );
    for( int i = 0; i < eyearray.length(); i++ ){
        eyecen = eyearray.at( i );
        xoff.x = meyesize;
        yoff.y = meyesize;
        snapPoints.append( eyecen + xoff );
        snapPoints.append( eyecen + yoff );
        snapPoints.append( eyecen - xoff );
        snapPoints.append( eyecen - yoff );
    }

    return Acad::eOk;
}
コード例 #3
0
ファイル: Sfml.class.cpp プロジェクト: jspezia/Nibbler
void			Sfml::_drawSnake(Snake *snake)
{
	//head
	sf::CircleShape	head(this->_squareSize / 2);
	head.setFillColor(sf::Color(BLACK));

	head.setPosition(snake->_head->getX() * this->_squareSize + 1, snake->_head->getY() * this->_squareSize + 1);
	this->_win->draw(head);

	//eyes
	sf::CircleShape	eyes((this->_squareSize / 2 - 1) / 4);
	eyes.setFillColor(sf::Color(WHITE));

	eyes.setPosition(snake->_head->getX() * this->_squareSize + this->_squareSize * 1 / 4, snake->_head->getY() * this->_squareSize + 1 + this->_squareSize * 1 / 4);
	this->_win->draw(eyes);
	eyes.setPosition(snake->_head->getX() * this->_squareSize + this->_squareSize * 3 / 4 - 1, snake->_head->getY() * this->_squareSize + 1 + this->_squareSize * 1 / 4);
	this->_win->draw(eyes);

	sf::CircleShape	body(this->_squareSize / 2);
	body.setFillColor(sf::Color(BODY_COLOR));

	for (std::list<GameEntity *>::iterator it = snake->_body.begin(); it != snake->_body.end(); it++)
	{
		body.setPosition((*it)->getX() * this->_squareSize + 1, (*it)->getY() * this->_squareSize + 1);
		this->_win->draw(body);
	}
}
コード例 #4
0
ファイル: ledeyes.c プロジェクト: ameggs/bot-thoughts-blog
int main() 
{
	uint8_t i;

	delay(64000); // delay before clock slows down, 1000ms * 64

	init_wdt();
	init_blink();
	slow_clock();

	while (1) {
		blink(3+(uint8_t)(rand()>>31)); // 3 + up to 3 blinks
		eyes(OFF);
		sleep(3+(uint8_t)(rand()>>30)); // 3 +  up to 7 seconds
	}
}
コード例 #5
0
Acad::ErrorStatus
AsdkSmiley::getGripPoints(
    AcGePoint3dArray& gripPoints,
    AcDbIntArray& osnapMasks,
    AcDbIntArray& geomIds) const
{
    assertReadEnabled();

    // Grip points to face
    //
    AcGePoint3d center( center() );
    gripPoints.append( center );
    AcGeVector3d xoff( radius(), 0, 0 ),
                 yoff( 0, radius(), 0 );
    gripPoints.append( center + xoff );
    gripPoints.append( center + yoff );
    gripPoints.append( center - xoff );
    gripPoints.append( center - yoff );

    // Grip points to mouth
    //
    AcGeLineSeg3d chord( mouthLeft(), mouthRight() );

    gripPoints.append( mouthLeft() );
    gripPoints.append( mouthRight() );
    gripPoints.append( chord.midPoint() );
    gripPoints.append( mouthBottom() );

    // Grip points to eyes
    //
    AcGePoint3dArray eyearray;
    AcGePoint3d eyecen;
    eyes( eyearray );
    for( int i = 0; i < eyearray.length(); i++ ){
        eyecen = eyearray.at( i );
        gripPoints.append( eyecen );
        AcGeVector3d xoff( meyesize, 0, 0 ),
                     yoff( 0, meyesize, 0 );
        gripPoints.append( eyecen + xoff );
        gripPoints.append( eyecen + yoff );
        gripPoints.append( eyecen - xoff );
        gripPoints.append( eyecen - yoff );
    }

    return Acad::eOk;
}
コード例 #6
0
Adesk::Boolean
AsdkSmiley::worldDraw(AcGiWorldDraw *wd)
{
    assertReadEnabled();

    AcGeVector3d offset(0,0,0);
    AcGeCircArc3d face = mfacecircle;

    // If dragging, don't fill the smiley
    //
    if( wd->isDragging() ){
        wd->subEntityTraits().setColor( colorIndex() );
        wd->subEntityTraits().setFillType( kAcGiFillNever );
    }
    else
        wd->subEntityTraits().setFillType( kAcGiFillAlways );

    // Give the circle a GS marker of 1
    //
    wd->subEntityTraits().setSelectionMarker( 1 );
    wd->geometry().circle( face.center(), face.radius(), mnormal );

    if( !wd->isDragging() )
        wd->subEntityTraits().setColor( 250 );

    // Give the eyes GS markers of 2 etc.
    //
    AcGePoint3dArray eyearray;

    eyes( eyearray );
    for( int i = 0; i < eyearray.length(); i++ ){
        wd->subEntityTraits().setSelectionMarker( i + 2 );
        wd->geometry().circle( eyearray.at(i) + offset, meyesize, mnormal );
    }

    AcGePoint3d smilecen( mouthCenter() + offset ),
                startpt( mouthLeft() + offset ),
                endpt( mouthRight() + offset );
    AcGeVector3d startvec = startpt - smilecen,
                 endvec = endpt - smilecen;
    double mouthangle = startvec.angleTo( endvec );

    wd->subEntityTraits().setSelectionMarker( eyearray.length() + 2 );
    wd->geometry().circularArc( smilecen, mouthRadius(), mnormal, startvec, mouthangle, kAcGiArcChord );
    return Adesk::kTrue;
}
コード例 #7
0
Rect InputProcessing::getRightEyePosition(Mat frame, Rect facePosition) {
    Size minS((int)(facePosition.width*.15), (int)(facePosition.height*.15));
    Size maxS((int)(facePosition.width*.4), (int)(facePosition.height*.4));
    vector<Rect> eyes(1);
    facePosition.width /= 2;
    facePosition.height /= 2;
    facePosition.y += facePosition.height / 3;
    Mat  face(frame, facePosition);
    eyeCascade.detectMultiScale(face, eyes, 1.05, 3, CV_HAAR_FIND_BIGGEST_OBJECT,minS,maxS);
    if (eyes.size() == 0) {
        return  Rect(0,0,0,0);
    }
    eyes.at(0).x += facePosition.x;
    eyes.at(0).y += facePosition.y;
    //from empirical observations, cascades tend to crop right parts for both eyes, so we add width
    eyes.at(0).width += (int) ceil(eyes.at(0).width *.125);
    return eyes.at(0);
}
コード例 #8
0
Acad::ErrorStatus
AsdkSmiley::osnapCen(
    const AcGePoint3d& pickPoint,
    AcGePoint3dArray& snapPoints) const
{
    // Osnap center to the face's center
    //
    snapPoints.append( center() );

    // Osnap center to the eyes' center
    //
    AcGePoint3dArray eyearray;
    eyes( eyearray );
    for( int i = 0; i < eyearray.length(); i++ ){
        snapPoints.append( eyearray.at( i ));
    }

    return Acad::eOk;
}
コード例 #9
0
void
AsdkSmiley::saveAs(AcGiWorldDraw *wd, AcDb::SaveType saveType)
{

    // saveType == AcDb::kR12Save for saveasr12
    // saveType == AcDb::kR13Save for proxy graphics save
    //
    AcGiRegenType rtype = wd->regenType();

    if( AcDb::kR12Save == saveType )
        wd->subEntityTraits().setFillType( kAcGiFillNever );
    else if( AcDb::kR13Save == saveType )
        wd->subEntityTraits().setFillType( kAcGiFillAlways );

    // Draw face
    //
    wd->geometry().circle( center(), radius(), mnormal );

    if( AcDb::kR13Save == saveType )
        wd->subEntityTraits().setColor( 250 );

    // Draw eyes
    //
    AcGePoint3dArray eyearray;
    eyes( eyearray );
    AcGeVector3d eyevec( -1, 0, 0 );
    double eyeang = kPi;
    for( int i = 0; i < eyearray.length(); i++ ){
        wd->geometry().circularArc( eyearray.at( i ), meyesize, mnormal, eyevec, eyeang );
    }

    // Draw frown
    //
    AcGePoint3d smilecen = center();
    smilecen[Y] -= radius() * 1.1;
    double smilerad = radius() * 0.8;
    AcGeVector3d smilevec( 1, 1, 0 );
    double smileang = kPi / 2;
    wd->geometry().circularArc( smilecen, smilerad, mnormal, smilevec, smileang, kAcGiArcChord );
}
コード例 #10
0
Acad::ErrorStatus
AsdkSmiley::explode(AcDbVoidPtrArray& entities) const
{
    assertReadEnabled();

    AcDbCircle *pCircle = new AcDbCircle( center(), mnormal, radius() );
    entities.append( pCircle );

    // Create eyes
    //
    AcGePoint3dArray eyearray;
    eyes( eyearray );
    for( int i = 0; i < eyearray.length(); i++ ){
        AcDbCircle *pCircle = new AcDbCircle( eyearray.at(i), mnormal, meyesize );
        entities.append( pCircle );
    }

    // Create smile arc
    //
    AcGePoint3d smilecen( mouthCenter() ),
                startpt( mouthLeft() ),
                endpt( mouthRight() );
    AcGeVector3d normvec( 1, 0, 0 ),
                 startvec = startpt - smilecen,
                 endvec = endpt - smilecen;
    double startang = 2 * kPi - startvec.angleTo( normvec ),
           endang = 2 * kPi - endvec.angleTo( normvec );
    AcDbArc *pArc = new AcDbArc( smilecen, mnormal, mouthRadius(), startang, endang );
    entities.append( pArc );

    // Create smile arc chord
    //
    AcDbLine *pLine = new AcDbLine( startpt, endpt );
    entities.append( pLine );

    return Acad::eOk;
}
コード例 #11
0
ファイル: bluetooth.cpp プロジェクト: rmoravcik/jarvis-2.0
void Bluetooth::onReadyRead(void)
{
    qDebug() << "Ready read..." << "request:" << m_request;

    if (!m_socket)
        return;

    while (m_socket->canReadLine()) {
        QByteArray data = m_socket->readLine();
        QString line = QString::fromUtf8(data.constData(), data.length()).trimmed();
        if (line.length() > 0) {
            qDebug() << "Received:" << line << "request:" << m_request;

            if (m_timer->isActive()) {
                m_timer->stop();
            }

            switch (m_request) {
                case REQUEST_BATTERY:
                    if (line.contains(BLUETOOTH_CMD_BATTERY)) {
                        line.remove(BLUETOOTH_CMD_BATTERY + QString(": "));
                        line.remove(QChar('%'));
                        unsigned int capacity = line.toInt();
                        m_request = REQUEST_NO_REQUEST;
                        emit battery(capacity);
                    } else {
                        // FIXME: ERROR
                    }
                    break;

                case REQUEST_EYES:
                    if (line.contains(BLUETOOTH_CMD_EYES)) {
                        PowerState state;
                        if (line.contains(BLUETOOTH_PARAM_ON)) {
                            state = PowerOn;
                        } else {
                            state = PowerOff;
                        }
                        m_request = REQUEST_NO_REQUEST;
                        emit eyes(state);
                    } else {
                        getEyes();
                    }
                    break;

                case REQUEST_HELMET:
                    if (line.contains(BLUETOOTH_CMD_HELMET)) {
                        HelmetState state;
                        if (line.contains(BLUETOOTH_PARAM_CLOSE)) {
                            state = HelmetClose;
                        } else {
                            state = HelmetOpen;
                        }
                        m_request = REQUEST_NO_REQUEST;
                        emit helmet(state);
                    } else {
                        getHelmet();
                    }
                    break;

                case REQUEST_INTENSITY:
                    if (line.contains(BLUETOOTH_CMD_INTENSITY)) {
                        line.remove(BLUETOOTH_CMD_INTENSITY + QString(": "));
                        PowerIntensity value = (PowerIntensity) line.toInt();
                        m_request = REQUEST_NO_REQUEST;
                        emit intensity(m_intensityDevice, value);
                    } else {
                        getIntensity(m_intensityDevice);
                    }
                    break;

                case REQUEST_QUOTE:
                    if (line.contains("OK")) {
                        m_request = REQUEST_NO_REQUEST;
                        emit quoteFinished();
                    } else {
                        // FIXME: ERROR
                    }
                    break;

                case REQUEST_REPULSOR:
                    if (line.contains("OK")) {
                        emit repulsorBlastGenerated(m_repulsor);
                    }
                    m_request = REQUEST_NO_REQUEST;
                    break;

                case REQUEST_REPULSORS:
                    if (line.contains(BLUETOOTH_CMD_REPULSORS)) {
                        PowerState state;
                        if (line.contains(BLUETOOTH_PARAM_ON)) {
                            state = PowerOn;
                        } else {
                            state = PowerOff;
                        }
                        m_request = REQUEST_NO_REQUEST;
                        emit repulsors(state);
                    } else {
                        getRepulsors();
                    }
                    break;

                case REQUEST_UNIBEAM:
                    if (line.contains(BLUETOOTH_CMD_UNIBEAM)) {
                        PowerState state;
                        if (line.contains(BLUETOOTH_PARAM_ON)) {
                            state = PowerOn;
                        } else {
                            state = PowerOff;
                        }
                        m_request = REQUEST_NO_REQUEST;
                        emit unibeam(state);
                    } else {
                        getUnibeam();
                    }
                    break;

                case REQUEST_VERSION:
                    if (m_revision.isEmpty()) {
                        m_revision = line;
                    } else if (m_build.isEmpty()) {
                        m_build = line;
                        m_request = REQUEST_NO_REQUEST;
                        emit version(m_revision, m_build);
                    }
                    break;

                case REQUEST_VOLUME:
                    if (line.contains(BLUETOOTH_CMD_VOLUME)) {
                        line.remove(BLUETOOTH_CMD_VOLUME + QString(": "));
                        VolumeLevel level = (VolumeLevel) line.toInt();
                        emit volume(level);
                        m_request = REQUEST_NO_REQUEST;
                    } else {
                        getVolume();
                    }
                    break;

                default:
                    break;
            }
        }
    }
}
コード例 #12
0
Acad::ErrorStatus
AsdkSmiley::moveGripPointsAt(
    const AcDbIntArray& indices,
    const AcGeVector3d& offset)
{
    assertWriteEnabled();

    AcGePoint3dArray eyearray;
    AcGePoint3d oldquad, newquad, newmouthcenter, newmouthbottom,
                smilecen, startpt, endpt, midpt, newpt;
    AcGeVector3d vecstart(0,0,0), vecend(0,0,0), newvec(0,0,0);

    eyes( eyearray );
    for( int i = 0; i < indices.length(); i++ ) {
        int idx = indices[i];
        switch( idx ) {

        // Stretch smiley center
        //
        case 0:
            setCenter( center() + offset );
            continue;

        // Stretch smiley radius
        //
        case 1:
            oldquad = center() + AcGeVector3d( radius(), 0, 0 );
            break;
        case 2:
            oldquad = center() + AcGeVector3d( 0, radius(), 0 );
            break;
        case 3:
            oldquad = center() - AcGeVector3d( radius(), 0, 0 );
            break;
        case 4:
            oldquad = center() - AcGeVector3d( 0, radius(), 0 );
            break;

        // Stretch smiley mouth
        //
        case 5:
            // Left hand edge of mouth
            //
            setMouthLeft( mouthLeft() + offset );
            ensureRadius();

            continue;

        case 6:
            // Right hand edge of mouth
            //
            setMouthRight( mouthRight() + offset );
            ensureRadius();

            continue;

        case 7:
            // Middle mouth chord
            //
            setMouth( mouthLeft() + offset, mouthBottom() + offset, mouthRight() + offset );
            ensureRadius();

            continue;

        case 8:
            // Bottom of mouth arc
            //
            setMouthBottom( mouthBottom() + offset );
            ensureRadius();

            continue;

        // Stretch smiley eyes
        //
        default:
            if(( eyearray.length() * 5 ) + 9 > idx ){
                
                // Get eye number, extracting it from the array
                //
                int eyepos = (int)(( idx - 9 ) / 5 );
                AcGePoint3d eyecen = eyearray.at( eyepos );
                
                // Handle the grip for the eye
                //
                int subidx = idx - 9;
                while ( subidx >= 5 ){ subidx -= 5; }
                switch( subidx ){

                // Stretch eye center
                //
                case 0:
                    // Keep the minimum eye height at zero
                    //
                    if( meyesheight+offset[Y] < 0 )
                        setEyesHeight( 0 );
                    else
                        setEyesHeight( meyesheight + offset[Y] );

                    // Keep the eyes from overlapping
                    //
                    if( eyecen[X] < center()[X] ){    // left eye
                        if( meyesapart - ( offset[X] * 2 ) < meyesize * 2 )
                            setEyesApart( meyesize * 2 );
                        else
                            setEyesApart( meyesapart - ( offset[X] * 2 ));
                    }
                    else {                          // right eye
                        if( meyesapart + ( offset[X] * 2 ) < meyesize * 2 )
                            setEyesApart( meyesize * 2 );
                        else
                            setEyesApart( meyesapart + ( offset[X] * 2));
                    }
                    ensureRadius();
                    continue;

                // Stretch eye radius
                //
                case 1:
                    oldquad = eyecen + AcGeVector3d( meyesize, 0, 0 );
                    break;
                case 2:
                    oldquad = eyecen + AcGeVector3d( 0, meyesize, 0 );
                    break;
                case 3:
                    oldquad = eyecen - AcGeVector3d( meyesize, 0, 0 );
                    break;
                case 4:
                    oldquad = eyecen - AcGeVector3d( 0, meyesize, 0 );
                    break;
                }
                newquad = oldquad + offset;
                
                // Keep eyes from touching
                //
                if( newquad.distanceTo( eyecen ) > meyesapart / 2 )
                    setEyeSize( meyesapart / 2 );
                else
                    setEyeSize( newquad.distanceTo( eyecen ));
                ensureRadius();
            }
            continue;
        }
        newquad = oldquad + offset;
        scaleRadius( newquad.distanceTo( center() ));
    }

    return Acad::eOk;
}
コード例 #13
0
ファイル: ledeyes.c プロジェクト: ameggs/bot-thoughts-blog
void init_blink()
{
	DDRB |= (1<<LEFTEYE)|(1<<RIGHTEYE);
	eyes(OFF);
}