Guest User

Untitled

a guest
May 12th, 2019
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. void setup() {
  2.     size(400,400);
  3.     background(255);
  4. }
  5.  
  6. void draw() {
  7.     background(255);
  8.     int[] pointA = {30,90};
  9.     int[] pointB = {300, 240};
  10.     cline(pointA,pointB);
  11. };
  12.  
  13. void cline(int[] a, int[] b) {
  14.     if (a[0] > b[0]) {
  15.         int tmp = a[0];
  16.         a[0] = b[0];
  17.         b[0] = tmp;
  18.     }
  19.     if (a[1] > b[1]) {
  20.         int tmp = a[1];
  21.         a[1] = b[1];
  22.         b[1] = tmp;
  23.     };
  24.    
  25.     if (a == b) {
  26.         point(a[0], a[1]);
  27.     } else if (a[0] == b[0]) {
  28.         for (int y = a[1]; y <= b[1]; y++) { point(a[0], y); }
  29.    
  30.     } else if (a[1] == b[1]) {
  31.         for (int x = a[0]; x <= b[0]; x++) { point(x, a[1]); }
  32.    
  33.     } else {
  34.         float vdif = (float) (b[1]-a[1])/(b[0]-a[0]);
  35.         float y = a[0];
  36.         println(vdif);
  37.         for (int x = a[0]; x <= b[0]; x++) {
  38.             point(x,y);
  39.             y += vdif;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment