EvanSheehan-13-9-65

by Evan @ 11:29 pm 22 January 2012


Also available here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
PVector[][] vertices;
 
void setup() {
  size(600, 600);
  background(255);
  smooth();
 
  vertices = new PVector[int(random(5, 10)) + 1][int(random(6, 10)) + 1];
 
  for (int i = 0; i < vertices.length; i++) {
    PVector row[] = vertices[i];
 
    for (int j = 0; j < row.length; j++) {
      int x = 0, y = 0;
 
      if (i > 0) {
        x = int(vertices[0][j].x);
      } else if (j > 0) {
        x = int(row[j - 1].x + random(width / 10, width / 6));
        if (x > width || j >= row.length - 1) {
          x = width;
        }
      }
 
      if (i > 0) {
        do {
          float dy = random(height / 10, height / 5);
          y = int(vertices[i - 1][j].y + dy);
        } while (y < vertices[i - 1][j].y);
 
        if (y > height) {
          y = height;
        }
      }
 
      row[j] = new PVector(x, y);
    }
  }
 
  noFill(); 
  noLoop();
}
 
void draw() {
  // Set up margins and border
  scale(0.9);
  translate(.05 * width, .05 * height);
  rect(0, 0, width, height);
 
  for (int i = 0; i < vertices.length; i++) {
    PVector row[] = vertices[i];
    PVector last = row[0];
 
    for (int j = 1; j < row.length; j++) {
      PVector v = row[j];
 
      if (i+1 < vertices.length) {
        float p = random(1.0);
        if (p < 0.4) {
          verticalLines(last, v, vertices[i+1][j-1], vertices[i+1][j]);
        } else if (p < 0.65) {
          drawTriangles(last, v, vertices[i+1][j-1], vertices[i+1][j]);
        }
      }
 
      line(last.x, last.y, v.x, v.y);
      last = v;
    }
  }
 
  for (int i = 0; i < random(1, 6); i++) {
    int r = int(random(10, height / 4));
    ellipse(int(random(r / 2, width - r / 2)), int(random(r / 2, height - r / 2)), r, r);
  }
 
  save("plotter.tif");
}
 
void verticalLines(PVector tl, PVector tr, PVector bl, PVector br) {
  float top_slope = (tr.y - tl.y) / (tr.x - tl.x);
  float bottom_slope = (br.y - bl.y) / (br.x - bl.x);
  float top_b = tl.y - top_slope * tl.x;
  float bottom_b = bl.y - bottom_slope * bl.x;
 
  for (int i = 0; i < random(30); i++) {
    int x = int(random(tl.x, tr.x));
    line(x, top_slope * x + top_b, x, bottom_slope * x + bottom_b);
  }
}
 
void drawTriangles(PVector tl, PVector tr, PVector bl, PVector br) {
  float top_slope = (tr.y - tl.y) / (tr.x - tl.x);
  float bottom_slope = (br.y - bl.y) / (br.x - bl.x);
  float top_b = tl.y - top_slope * tl.x;
  float bottom_b = bl.y - bottom_slope * bl.x;
 
  for (int i = 0; i < random(30); i++) {
    int x = int(random(tl.x, tr.x));
    int x2 = int(random(tl.x, tr.x));
    int x3 = int(random(tl.x, tr.x));
 
    while (x3 == x2) {
      x3 = int(random(tl.x, tr.x));
    }
 
    if (random(1.0) < 0.3) {
      line(x2, top_slope * x2 + top_b, x, bottom_slope * x + bottom_b);
      line(x3, top_slope * x3 + top_b, x, bottom_slope * x + bottom_b);
    } else {
      line(x, top_slope * x + top_b, x2, bottom_slope * x2 + bottom_b);
      line(x, top_slope * x + top_b, x3, bottom_slope * x3 + bottom_b);
    }
  }
}

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2023 Interactive Art and Computational Design, Spring 2012 | powered by WordPress with Barecity