#include <stdio.h>

typedef struct pt {
  int x;
  int y;
} pt;

void plot(int x, int y, char c)
{
  printf("\x1b\x5b%d;%dH%c", y, x, c);
}


pt pt1 = {20,10};
pt pt2 = {40,30};
pt pt3 = {0,30};


void line(pt a, pt b)
{
  pt change = {b.x - a.x, b.y - a.y};
  int ctx = change.x > 0 ? change.x : -change.x;
  int cty = change.y > 0 ? change.y : -change.y;
  int ct = ctx > cty ? ctx : cty;
  for (int t = 0; t <= ct; ++ t) {
    plot(a.x + change.x * t / ct, a.y + change.y * t / ct, '*');
  }
}

int main()
{
  line(pt1, pt2);
  line(pt2, pt3);
  line(pt3, pt1);
}

Reply via email to