26.11.2021 Views

ecosistemas humano 11 25 21

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ecosistema humano

mateo méndez villamizar

“””Provides a scripting component.

Inputs:

x: The x script variable

y: The y script variable

Output:

a: The a output variable”””

import rhinoscriptsyntax as rs

import Rhino.Geometry as rg

import ghpythonlib as gp

import random

import math

`

target_brick.ports[target_port][“plane”].Rotate(rotation, rg.Vector3d.ZAxis)

target_port_plane = target_brick.ports[target_port][“plane”]

cur_port_plane = cur_brick.ports[cur_port][“plane”]

t = rg.Transform.PlaneToPlane(cur_port_plane, target_port_plane)

self.connected_ports.append(cur_port_plane)

self.connected_bricks.append(target_brick.footprint)

self.connected_ports_name.append(str(target_brick) + “ “ + target_port)

cur_brick.move(t)

cur_brick.update_ports(cur_port, target_port, target_brick)

return cur_brick

def add_brick(self, new_brick):

self.bricks.append(new_brick)W

random.seed(option)

class Stack_bricks(object):

def __init__(self, brick_data, rules, target_n, start_plane):

self.brick_data = brick_data

self.rules = rules

self.target_n = target_n

self.start_plane = start_plane

self.bricks = []

self.connected_ports = []

self.connected_bricks = []

self.connected_ports_name = []

self.grow_rule_seq = []

def orient_brick(self, cur_port, target_port):

# I don’t have time to clean this, but I think there must be a simpler implementation

# of this logic. The general idea here is to orient the block based on which port it connects to.

if cur_port == target_port:

rotation = math.pi

elif cur_port == “top” and target_port != “bottom”:

if target_port == “right”:

rotation = math.pi/2

elif target_port == “left”:

rotation = math.pi/2 * -1

elif cur_port == “bottom” and target_port != “top”:

if target_port == “right”:

rotation = math.pi/2 * -1

elif target_port == “left”:

rotation = math.pi/2

elif cur_port == “right” and target_port != “left”:

if target_port == “top”:

rotation = math.pi/2 * -1

elif target_port == “bottom”:

rotation = math.pi/2

elif cur_port == “left” and target_port != “right”:

if target_port == “top”:

rotation = math.pi/2

elif target_port == “bottom”:

rotation = math.pi/2 * -1

else:

rotation = 0

return rotation

def stack_brick(self, cur_brick_data, target_brick, cur_port, target_port, id):

# super messy here. The idea is to connect the brick after it’s oriented correctly.

cur_brick = brick(cur_brick_data[“depth”], cur_brick_data[“width”], cur_brick_data[“color”], id)

rotation = self.orient_brick(cur_port, target_port)

def all_open_ports(self):E

open_ports = []

for brick in self.bricks:

for port in brick.ports:

if brick.ports[port][“neighbor”] == None:

open_ports.append([brick, port])

target_brick, target_port = random.choice(open_ports)

return target_brick, target_port

def generate(self):

# the main loop that generates the brick mass. Two rules here, you either give it a pre-made

detemrinistic rule ids.

# or adjust the target_n to randomly generate one.

start_brick_data = random.choice(self.brick_data,)

start_brick = brick(start_brick_data[“depth”], start_brick_data[“width”], start_brick_

data[“color”], 0)

self.add_brick(start_brick)

cur_n = 0

if use_rule_seq:

target_num = len(rule_seq)

else:

target_num = target_n

id)

while cur_n < target_num:

target_brick, target_port = self.all_open_ports()

cur_brick_data = random.choice(self.brick_data)

if use_rule_seq:

sel_rule_idx = int(rule_seq[cur_n])

cur_port = self.rules[sel_rule_idx]

else:

cur_port = random.choice(self.rules)

self.grow_rule_seq.append(cur_port)

new_brick_id = cur_n + 1

cur_brick = self.stack_brick(cur_brick_data, target_brick, cur_port, target_port, new_brick_

self.add_brick(cur_brick)

cur_n += 1

brick = brick

stack_bricks = Stack_bricks(brick_data, rules, target_n, start_plane)

stack_bricks.generate()

# All the stuff below are for visualization

planes = [brick.origin for brick in stack_bricks.bricks]

footprints = [brick.footprint for brick in stack_bricks.bricks]

used_ports = stack_bricks.connected_ports

used_bricks = stack_bricks.connected_bricks

connected_ports_name = stack_bricks.connected_ports_name

grow_rule_seq = stack_bricks.grow_rule_seq

66 67

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!