ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18mrjr

Dependencies:   mbed

Board/Board.cpp

Committer:
MatisRequis
Date:
2020-05-19
Revision:
2:d59a92e65bd9
Child:
3:54132cf073d7

File content as of revision 2:d59a92e65bd9:

#include "Board.h"

Board::Board() {
    
}

Board::~Board() {
    
}


void Board::draw(N5110 &lcd) {
    //outer rectangle
    lcd.drawRect(21, 3, 42, 42, FILL_TRANSPARENT);
    
    //inner rectangle
    lcd.drawRect(34,16,16, 16, FILL_TRANSPARENT);
    
    
    
    //Draw lane Lines
    
    lcd.drawLine(21, 3, 34, 16, 1);
    
    lcd.drawLine(35, 3, 39, 16, 1);
    lcd.drawLine(48,3,44,16,1);
    
    lcd.drawLine(62,3,49,16,1);
    
    lcd.drawLine(62,17,49,21,1);
    lcd.drawLine(62,30,49,26,1);
    
    lcd.drawLine(62,44,49,31,1);
    
    lcd.drawLine(48,44,44,31, 1);
    lcd.drawLine(45,44,39,31, 1);
    
    lcd.drawLine(21,44,34,31,1);
    
    lcd.drawLine(21,30,34,26,1);
    lcd.drawLine(21,17,34,21,1);
}

void Board::path() {
    /*drawpath(28, 3, 37, 16, column0[]);
    drawpath(42, 3, 41, 16, column1[]);
    drawpath(55, 3, 46, 16, column2[]);
    
    drawpath(62, 10, 49, 19, column3[]);
    drawpath(62, 24, 49, 23, column4[]);
    drawpath(62, 37, 49, 28, column5[]);
    
    drawpath(55, 44, 46, 31, column6[]);
    drawpath(41, 44, 42, 31, column7[]);
    drawpath(28, 44, 37, 31, column8[]);
    
    drawpath(21, 10, 34, 19, column9[]);
    drawpath(21, 23, 34, 24, column10[]);
    drawpath(21, 37, 34, 28, column11[]);*/
    
}

void Board::drawpath(int x0, int y0, int x1, int y1, Vector2D array[]) {
    
    int const y_range = static_cast<int>(y1) - static_cast<int>(y0);
    int const x_range = static_cast<int>(x1) - static_cast<int>(x0);
    
    if ( abs(x_range) > abs(y_range) ) {

        // ensure we loop from smallest to largest or else for-loop won't run as expected
        unsigned int const start = x_range > 0 ? x0:x1;
        unsigned int const stop =  x_range > 0 ? x1:x0;

        // loop between x pixels
        for (unsigned int x = start; x<= stop ; x++) {
            // do linear interpolation
            int const dx = static_cast<int>(x)-static_cast<int>(x0);
            unsigned int const y = y0 + y_range * dx / x_range;

            // If the line type is '0', this will clear the pixel
            // If it is '1' or '2', the pixel will be set
            if (dx <= y_range) {
                array[dx].y = y;
            }
            array[dx].x = x;
            
        }
    } else {

        // ensure we loop from smallest to largest or else for-loop won't run as expected
        unsigned int const start = y_range > 0 ? y0:y1;
        unsigned int const stop =  y_range > 0 ? y1:y0;

        for (unsigned int y = start; y<= stop ; y++) {
            // do linear interpolation
            int const dy = static_cast<int>(y)-static_cast<int>(y0);
            unsigned int const x = x0 + x_range * dy / y_range;

            // If the line type is '0', this will clear the pixel
            // If it is '1' or '2', the pixel will be set
            if (dy <= x_range) {
                array[dy].x = x;
            }
            array[dy].y = y;
        }
    }
}