Utility Documentation

Graph

class Graph

This class is an undirected graph implementation with utility methods for exporting to different mesh formats.

Attributes: adjacency_list (dict): Dictionary of vertices and their connected partners. colors (list): List of vertex colors. vertices (list): List of vertices.

add_edge(v1, v2)

Adds an edge between two vertices. Will add the vertices if they don’t already exist in the graph.

Parameters: v1 (vec3): Vertex position 1 v2 (vec3): Vertex position 2

add_vertex(vertex, color=array([1, 1, 1, 0]))

Adds a vertex to the undirected graph.

Parameters: vertex (vec3): Vertex to add. color (vec3): Color of the vertex.

clear()

Clears the graph.

edge_exists(v1, v2)

Checks if an edge exists between two vertices.

Parameters: v1 (vec3): Vertex 1 v2 (vec3): Vertex 2

Returns: - True/False for if it exists.

export_to_matplot2d()

Exports the graph to vertices matplotlib can use.

Returns: - list: List of vertices.

export_to_ogl_indices()

Generates & exports all vertex, color, and indice data needed for OpenGL Element drawing calls.

Returns: - tuple(np.array, np.array, np.array) - - Array 0 is the array of vertices. - - Array 1 is the array of colors. - - Array 2 is the array of indices.

export_to_ogl_verts()

Exports the graph vertices to a format OpenGL can use.

Returns: - numpy.array: A numpy array of the vertices.

export_to_pyqtgraph()

Exports the graph to a format MeshObject can use for pyqtgraph’s 3D mesh objects.

Returns: - tuple: (verts, adj)

generate_indices(adjacency_list, vert_list)

Generates the indices of the vertices/adjacency list for OpenGL element drawing calls.

Parameters: adjacency_list (dict): Dictionary of vertex->vertex mappings vert_list (list): List of all vertices.

Returns: - list: List of indices.

input_check

check_blank_line(obj)

Determines if the inputs are blank

check_branching(obj)

determines if there is branching and if it is in a valid syntax

check_if_numeric(obj)

determines if the inputs are numeric

check_in_alphabet(obj)

determines if the characters are in the alphabet

check_nd(obj)

determine if the percentages are valid

check_prod_rule_format(obj)

determines if the production rules are in the proper format

check_valid_numeric(obj)

determines if the numbers are valid

input_check(obj)

collects all the input checks and determines if they are valid

print_error_message(obj, msg)

Indicates there’s an error and invalidates the input from that textbox

lsystem_utils

This file for now is acting as a catch-all utility file.

generate_lsystem_2d(grammar)

Generates a 2D L-System based off of the grammar.

Parameters: grammar (dict): Dictionary representing the grammar defining the lsystem.

Returns: Graph: Graph object used to generate the mesh.

generate_lsystem_3d(grammar)

Generates a 3D L-System based off of the grammar.

Parameters: grammar (dict): Dictionary representing the grammar defining the lsystem.

get_saved_lsystem(key, saved_lsystems)

Fetches a saved lsystem in our loaded lsystems by key.

Parameters: key (string): Dictionary key used to identify a saved lsystem. saved_lsystems (dict): Dictionary of loaded lsystems.

Returns: dict: dictionary of the saved lsystem grammar, or None if it doesn’t exist.

get_saved_path()

Gets the operating system dependent saved_lsystems.json path

Returns: - os.path: Operating system dependent saved_lsystems.json path

load_saved_lsystems()

Loads the pre-defined and user defined L’Systems.

Returns: - dict: Dictionary of all saved lsystems in the form of {key:grammar, key:grammar}

remove_saved_lsystem(key, dim)

Deletes saved lsystem by key by loading the file into a json object, removing the key, then writing the file back to disk.

Parameters: key (string): Key of the lsystem to remove.

save_lsystem(key, grammar, dim)

Saves a given lsystem to disk to “lsystem/saved_lsystems.json” Overwrites any previous lsystem defined with the same key.

Parameters: key (string): Key used to identify the lsystem. grammar (dict): Dictionary of the grammar defining the lsystem.

Returns: - dict: New dictionary of lsystems with the new addition.

Parsing

This file performs all of the parsing

nd_choice(prods)

Randomly selects the rule in nondeterminism

parsed_thread(strings, prods, iters)

Takes in an axiom set of prods and number of iterations and generates the new string

string_parse(strings, prod_rules)

NOTE: Context sensitive reads left to right, with longest key getting priority

str_temp is the current string it will be used to keep track of what parts of the string still need proccessing Context free implimentation idea: 1. sort the keys from longest to shortest 2. say the key is length n, if the first n letters of the string match the key, add prod[key] to the new string 3a.if the first n letters ever match a key remove the first n letters of the string 3b.default rule: a letter goes to itself

stack_loop 2D

This module makes the stack loop

read_stack(stack, starting_pt, angle, turn_angle, line_scale)

This function converts a string into an array of objects placed at the vertices determined by the turtle graphics interpretation of the string

Inputs:
stack: a string starting_pt: the turtles starting_pt (the origin of your fractal) angle: the degrees the angle should turn when seeing a + or - turn_angle: the degrees the angle should increment by when seeing ( or ) line_scale: the factor by which the line length should change when seeing < or >
Outputs:

An array of vertices formatted as such [[[x1,y1],[x2,y2],[x3,y3]],

[[x4,y4],[x5,y5],[x6,y6]]…]

where [x1,y1] is connected by a line to [x2,y2] which is connected by a line to [x3,y3] and [x4,y4] marks the starting point of a separte line

read_substring(lsys, curr_state, turn_angle, trig_dict, line_scale)

This is a utility function for read_stack, takes in a string without branching ([, ]) or move without draw (f,g,h) Inputs:

lsys: a string curr_state: a dictionary that has current point, orientation, and line scale turn_angle: the degrees the angle should increment by when seeing ( or ) trig_dict: a dictionary of all the already calculated trig necassary for step direction as well as the angle to turn by when seeing + or - line_scale: the factor by which the line length should change when seeing < or >
Outputs:
An array of vertices formatted as such: [[x1,y1],[x2,y2],[x3,y3],…]

stack_loop 3D

This module makes the stack loop

read_stack(stack, starting_pt, angle, obj)

This function converts a string into an array of objects placed at the vertices determined by the turtle graphics interpretation of the string

Inputs:
stack: a string starting_pt: the turtles starting_pt (the origin of your fractal) angle: the degrees the angle should turn when seeing a +, -, ^, &, < or > obj: the type of object that should be displayed, needs to be a mesh object
Outputs:
An array of type obj
read_substring(lsys, curr_state, turn_angle, obj)

This is a utility function for read_stack, takes in a string without branching ([, ]) or move without draw (f)

Inputs:
lsys: a string curr_state: a dictionary that has current point, and orientation turn_angle: the degrees the angle should turn when seeing a +, -, ^, &, < or > obj: the type of object that should be displayed, needs to be a mesh object
Outputs:
An array of type obj