Not logged in.

From instruction: Draw a straight line and follow it

Code: waiting for godot by jesusgollonet

create a conceptual line and virtual ego.
draw the line and set the ego to follow it. If the line ever moves, we'll move behind it.

// --------------------------------------------
class Line {
    int x1, y1, x2, y2;
    Line(int _x1, int _y1, int _x2, int _y2) {
        x1 = _x1;
        y1 = _y1;
        x2 = _x2;
        y2 = _y2;
    }    
    void draw() {
        line(x1, y1, x2, y2);    
    }
}

// --------------------------------------------
// this is me
class Me {
    int x, y;
    Me() {
      // I'm rather empty  
    }
    void follow(Line l) {
        x = l.x1;
        y = l.y1;
    }
    
}

// --------------------------------------------
Line l = new Line (10,10,90,90);
Me m = new Me();

// --------------------------------------------
void draw() {
    l.draw(); 
    // if the line ever moves, we'll follow her 
    m.follow(l);
}

[download]

Written in Processing. Released under the MIT License license