triangle

yzheka-m/nokia-5510-display/triangle

No description
triangle
@/triangle
DISPLAY@/display
Display object
P1@/point
position of the 1st corner
P2@/point
position of the 2nd corner
P3@/point
position of the 3rd corner
FILLboolean
Fill triangle or not
BLACKboolean
Black or white color
triangle
DISPLAY
P1
P2
P3
FILL
BLACK
DONE
DONEpulse
Pulse when triangle is placed on the screen
To use the node in your project you should have the yzheka-m/nokia-5510-display library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
    int x1,y1,x2,y2,x3,y3;
    bool fill,black,set=false;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    auto display = getValue<input_DISPLAY>(ctx);
    auto p1 = getValue<input_P1>(ctx);
    auto p2 = getValue<input_P2>(ctx);
    auto p3 = getValue<input_P3>(ctx);
    auto state=getState(ctx);
    if(state->set){
        if(state->fill)display->fillTriangle(state->x1,state->y1,state->x2,state->y2,state->x3,state->y3,state->black?WHITE:BLACK);
        else display->drawTriangle(state->x1,state->y1,state->x2,state->y2,state->x3,state->y3,state->black?WHITE:BLACK);
    }
    state->x1=p1->x; state->y1=p1->y;
    state->x2=p2->x; state->y2=p2->y;
    state->x3=p3->x; state->y3=p3->y;
    state->fill=getValue<input_FILL>(ctx);
    state->black=getValue<input_BLACK>(ctx);
    state->set=true;
    if(state->fill)display->fillTriangle(state->x1,state->y1,state->x2,state->y2,state->x3,state->y3,state->black?BLACK:WHITE);
    else display->drawTriangle(state->x1,state->y1,state->x2,state->y2,state->x3,state->y3,state->black?BLACK:WHITE);
    display->display();
    emitValue<output_DONE>(ctx, 1);
}