Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- size(400,400);
- background(255);
- }
- void draw() {
- background(255);
- int[] pointA = {30,90};
- int[] pointB = {300, 240};
- cline(pointA,pointB);
- };
- void cline(int[] a, int[] b) {
- if (a[0] > b[0]) {
- int tmp = a[0];
- a[0] = b[0];
- b[0] = tmp;
- }
- if (a[1] > b[1]) {
- int tmp = a[1];
- a[1] = b[1];
- b[1] = tmp;
- };
- if (a == b) {
- point(a[0], a[1]);
- } else if (a[0] == b[0]) {
- for (int y = a[1]; y <= b[1]; y++) { point(a[0], y); }
- } else if (a[1] == b[1]) {
- for (int x = a[0]; x <= b[0]; x++) { point(x, a[1]); }
- } else {
- float vdif = (float) (b[1]-a[1])/(b[0]-a[0]);
- float y = a[0];
- println(vdif);
- for (int x = a[0]; x <= b[0]; x++) {
- point(x,y);
- y += vdif;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment