示例#1
0
def draw():
    background(0.95, 0.95, 0.95, 1.0)
    color(0, 0, 0, 1)

    walkers = []
    index = 0
    angle = (math.pi * 2) / 90.0
    pos = vec2([100, 100])
    dir = vec2([1, 1])
    x, y = pos[0], pos[1]
    walkers.append(Line(x, y, x, y, 0, dir, angle * 180.0 / math.pi, -1))
    line_length = 20
    depth = -1

    for i in range(3000):
        if i != 0:
            if stop_drawing is True:
                connect = random.randint(0, i - 1)
                pos = walkers[connect].get_lerp(random.uniform(0.25, 0.75))
                dist = math.hypot(walkers[i - 1].p0[0] - center_x,
                                  walkers[i - 1].p0[1] - center_y)
                c = vec2([center_x, center_y])
                dir = ((walkers[i - 1].p0 - c) / dist) * -1.0
                x, y = pos[0], pos[1]
                walkers.append(
                    Line(x, y, x, y, i, dir, angle * 180.0 / math.pi, connect))
                walkers[i].change_dir(walkers[i].dir)
                line_length = 10
                index = index + 1
            else:
                pos = walkers[i - 1].p1
                dir = walkers[i - 1].dir
                x, y = pos[0], pos[1]
                walkers.append(
                    Line(x, y, x, y, i, dir, angle * 180.0 / math.pi, -1))
                walkers[i].change_dir(walkers[i - 1].dir)

        if index > 400:
            break

        stop_drawing = False

        while walkers[i].get_length() < line_length:
            walkers[i].update()

            for w in walkers:
                if walkers[i].id != w.id and walkers[
                        i - 1].id != w.id and walkers[i].connect != w.id:
                    if walkers[i].intersect(w.p0, w.p1) or walkers[i].edges():
                        stop_drawing = True
                        break

            if stop_drawing:
                break

        walkers[i].draw()
        stroke()
示例#2
0
def draw():
    background(0.95, 0.95, 0.95, 1.0)
    color(0, 0, 0, 1)

    border = 50
    border_sQ = border * 2
    num_lines = 18
    y_step = float((height - border_sQ) / num_lines)
    x_step = float((width - border_sQ) / num_lines)
    y_offset = y_step / 2.0
    x_offset = x_step / 2.0
    un_offset = 10
    my_lines = []

    for i in range(num_lines):
        for j in range(num_lines - 1):
            if j == 0:
                p1 = vec2([
                    x_step * j + x_offset +
                    random.uniform(-x_offset, x_offset) + border, y_step * i +
                    y_offset + random.uniform(-y_offset, y_offset) + border
                ])
                p2 = vec2([
                    x_step * (j + 1) + x_offset +
                    random.uniform(-x_offset, x_offset) + border, y_step * i +
                    y_offset + random.uniform(-y_offset, y_offset) + border
                ])
                my_lines.append(Line(p1[0], p1[1], p2[0], p2[1]))
            else:
                p1 = vec2([
                    my_lines[(j + (num_lines - 1) * i) - 1].p1[0],
                    my_lines[(j + (num_lines - 1) * i) - 1].p1[1]
                ])
                p2 = vec2([
                    x_step * (j + 1) + x_offset +
                    random.uniform(-x_offset, x_offset) + border, y_step * i +
                    y_offset + random.uniform(-y_offset, y_offset) + border
                ])
                my_lines.append(Line(p1[0], p1[1], p2[0], p2[1]))

    index = 0
    for i in range(num_lines):
        index = index + 1
        for j in range(num_lines - 1):
            if i != 0:
                lerp_lines = int(map(i, 0, num_lines, 1, 12)) + 1
                for k in range(lerp_lines):
                    p0 = my_lines[(j + (num_lines - 1) * (i - 1))].get_lerp(
                        math.pow(map(k, 0, lerp_lines - 1, 0, 1), 1))
                    p1 = my_lines[(j + (num_lines - 1) * i)].get_lerp(
                        math.pow(map(k, 0, lerp_lines - 1, 0, 1), 1))
                    Line(p0[0], p0[1], p1[0], p1[1]).draw()
                    stroke()

    for line in my_lines:
        line.draw()
        stroke()
示例#3
0
def draw():

    background(0.95, 0.95, 0.95, 1.0)

    grid_size = 3
    border = 40
    x_step = (width-(border*2)) / float(grid_size)
    y_step = (height-(border*2)) / float(grid_size)
    x_offset = x_step / 2.0
    y_offset = y_step / 2.0

    for y in range(grid_size):
        for x in range(grid_size):
            x_pos = x_step * x + x_offset + border
            y_pos = y_step * y + y_offset + border
            my_lines = []
            num_lines = 180
            angle = (2*math.pi) / float(num_lines)
            center_x = width / 2.0
            center_y = height / 2.0
            center = vec2([x_pos, y_pos])
            circle_size = (x_step / 2.0) - 10

            order = []
            for i in range(num_lines):
                order.append(i)

                random.shuffle(order)

            for i in range(num_lines):
                index = order[i]
                pos = vec2([
                    (math.cos(angle*index) * (circle_size-0.1))+center[0],
                    (math.sin(angle*index) * (circle_size-0.1))+center[1]
                ])
                dir = (pos - vec2([center_x, center_y])) * -1.0
                my_lines.append(Line(pos, dir, i))
                my_lines[i].change_dir(dir)

                while my_lines[i].get_dist_from_center(center) < circle_size:
                    my_lines[i].update()

                    stop_drawing = False
                    for line in my_lines:
                        if line.id != my_lines[i].id:
                            if my_lines[i].intersect(line.p0, line.p1):
                                stop_drawing = True
                                break

                    if stop_drawing:
                        break

            for line in my_lines:
                if line.get_length() > 0:
                    line.draw()
def draw():
    background(0.95, 0.95, 0.95, 1.0)

    num_walkers = random.randint(100, 200)
    walkers = []
    x_step = float((width - 100)) / num_walkers
    amt = random.uniform(0.075, 0.15)
    amt_step = random.randint(15, 80)
    start_dist = random.randint(10, 150)

    index = 0
    count = 0
    for i in range(num_walkers):
        x = float((x_step * i) + 50.0)
        pos = vec2([float(x), float(50.0)])
        angle = math.radians(0)
        dirs = vec2([math.sin(angle), math.cos(angle)])
        walkers.append(Line(pos, dirs, i))

        walk = True
        while walk:
            if count % amt_step == 0:
                r = random.uniform(0, 1)
                if r < amt and walkers[index].p0[1] > start_dist:
                    dirs = get_direction()
                    walkers.append(Line(walkers[index].p1, dirs, i))
                    index = index + 1
                else:
                    angle = math.radians(0)
                    dirs = vec2([math.sin(angle), math.cos(angle)])
                    walkers.append(Line(walkers[index].p1, dirs, i))
                    index = index + 1

            walkers[index].extend_line()

            hit_line = False
            for w in walkers:
                if walkers[index].id != w.id:
                    intersect = walkers[index].line_intersect(w.p0, w.p1)
                    if intersect:
                        hit_line = True

            hit_edge = walkers[index].edges()
            if hit_edge or hit_line:
                walk = False

            count = count + 1
        index = index + 1

    for walker in walkers:
        walker.draw()
示例#5
0
 def __init__(self, x1, y1, x2, y2, id, dir, angle, connect):
     super().__init__(x1, y1, x2, y2)
     self.p1 = vec2([x1, y1])
     self.id = id
     self.dir = dir
     self.angle = angle
     self.connect = connect
    def line_intersect(self, p2, p3):
        A1 = self.p1[1] - self.p0[1]
        B1 = self.p0[0] - self.p1[0]
        C1 = A1 * self.p0[0] + B1 * self.p0[1]
        A2 = p3[1] - p2[1]
        B2 = p2[0] - p3[0]
        C2 = A2 * p2[0] + B2 * p2[1]
        denom = A1 * B2 - A2 * B1

        if denom == 0:
            return False

        intersect_x = (B2 * C1 - B1 * C2) / denom
        intersect_y = (A1 * C2 - A2 * C1) / denom

        rx0 = (intersect_x - self.p0[0]) / (self.p1[0] - self.p0[0])
        ry0 = (intersect_y - self.p0[1]) / (self.p1[1] - self.p0[1])
        rx1 = (intersect_x - p2[0]) / (p3[0] - p2[0])
        ry1 = (intersect_y - p2[1]) / (p3[1] - p2[1])

        if(((rx0 >= 0 and rx0 <= 1) or (ry0 >= 0 and ry0 <= 1)) and \
                ((rx1 >= 0 and rx1 <= 1) or (ry1 >= 0 and ry1 <= 1))):
            self.intersect = vec2([intersect_x, intersect_y])
            return True
        else:
            return False
 def __init__(self, p0, dir, id):
     self.id = id
     self.p0 = p0
     self.p1 = p0
     self.dir = dir
     self.intersect = vec2([0.0, 0.0])
     self.count = 0
示例#8
0
def draw():
    background(0.95, 0.95, 0.95, 1.0)
    color(0, 0, 0, 1)

    connector_lines = []

    num_lines_x = 20
    num_lines_y = 3
    x_step = float((width - 100) // num_lines_x)
    y_step = float(height // num_lines_y)
    x_offset = (x_step // 2) + 50
    y_offset = y_step // 2

    for h in range(num_lines_y):
        for i in range(num_lines_x):
            x = x_step * i + x_offset
            y = y_step * h + y_offset
            yy = random.randint(25, 100)
            p0 = vec2([
                x + random.uniform(-(x_step // 2) + 10, (x_step // 2) + 10),
                random.uniform(y - 50, y + 50) + yy
            ])
            p1 = vec2([
                x + random.uniform(-(x_step // 2) + 10, (x_step // 2) + 10),
                random.uniform(y - 50, y + 50) - yy
            ])
            connector_lines.append(Line(p0[0], p0[1], p1[0], p1[1]))

            if i != 0:
                num_lines = 21
                l1 = i + num_lines_x * h
                l2 = (i + num_lines_x * h) + 1

                while l2 == l1:
                    l2 = random.randint(0, len(connector_lines))

                for j in range(num_lines + 1):
                    p0 = connector_lines[l1 - 1].get_lerp(
                        math.pow(map(j, 0, num_lines, 0, 1), 1))
                    p1 = connector_lines[l2 - 1].get_lerp(
                        math.pow(map(j, 0, num_lines, 0, 1), 1))
                    Line(p0[0], p0[1], p1[0], p1[1])
                    stroke()
    def change_dir(self):
        self.count = self.count + 1

        if self.count % 40 == 0:
            angle = math.radians(random.randint(45, 135))
            dir = vec2([math.sin(angle), math.cos(angle)])
            self.dir = dir
            return True
        else:
            return False
def get_direction():
    num_angles = 2
    r = int(random.uniform(0, num_angles))
    angle_step = [0, 45]

    for i in range(num_angles):
        if i == r:
            angle = math.radians(angle_step[i])

    dirs = vec2([math.sin(angle), math.cos(angle)])
    return dirs
示例#11
0
 def change_dir(self, a):
     current_angle = math.atan2(a[1], a[0]) * 180 / math.pi
     new_dir = 90
     b = random.randint(0, 2)
     if b == 0:
         new_dir = 0
     elif b == 1:
         new_dir = 22.5 / 2.0
     else:
         new_dir = -(22.5 / 2.0)
     angle = math.radians(current_angle + new_dir)
     dir = vec2([math.cos(angle), math.sin(angle)])
     self.dir = dir
示例#12
0
 def change_dir(self, a):
     current_angle = math.atan2(a[1], a[0]) * 180 / math.pi
     new_dir = random.randint(-15, 15)
     angle = math.radians(current_angle + new_dir)
     d = vec2([math.cos(angle), math.sin(angle)])
     self.dir = d