import decodes from decodes.core import * outie = decodes.make_out(decodes.Outies.Rhino) from math import * line_in = Segment(Point(10,0), Point(-1,-5)) """ Line Replacement Rule Replaces a line with a collection of lines - this one is the basis for the Koch Fractal """ divs = ( 0 , 1/3 , 0.5 , 2/3 , 1 ) height_ratio = 1/3 height = line_in.length*height_ratio pts = [line_in.eval(t) for t in divs] vec = line_in.vec.cross(Vec(0,0,1)).normalized(height) pts[2] += vec new_lines = [Segment(pts[n],pts[n+1]) for n in range(len(pts)-1)] outie.put(new_lines) outie.draw()
import decodes as dc from decodes.core import * outie = dc.make_out(dc.Outies.SVG, "svg_out", path="", canvas_dimensions=Interval(1000, 500), flip_y=True) scale = 50 for x in range(10): for y in range(10): pt = Point(x * scale, y * scale) pt.set_color(Color(1, 0, 0)) pt.set_weight(2 * y + 1.5) outie.put(pt) def func(t): return Point(t * scale, math.sin(t) * scale) crv = Curve(func, Interval(0, math.pi * 2)) pl = crv.surrogate pl.set_color(1, 0, 0) pl.set_weight(5.0) outie.put(pl) outie.draw()
import decodes as dc from decodes.core import * outie = dc.make_out(dc.Outies.SVG, "svg_out", path="", canvas_dimensions=Interval(1000,500), flip_y = True) scale = 50 for x in range(10): for y in range(10): pt = Point(x*scale,y*scale) pt.set_color(Color(1,0,0)) pt.set_weight(2*y+1.5) outie.put(pt) def func(t): return Point(t*scale,math.sin(t)*scale) crv = Curve(func,Interval(0,math.pi*2)) pl = crv.surrogate pl.set_color(1,0,0) pl.set_weight(5.0) outie.put(pl) outie.draw()
import decodes from decodes.core import * outie = decodes.make_out(decodes.Outies.JSON, "json_out", save_file=True) from decodes.extensions.graph import SpatialGraph """ Proximity Edges Adds edges to a given SpatialGraph such that each Point forms connections with a given number of Points nearest to it. """ def add_proximity_connections(gph, val=5): for p1 in gph.nodes: # make a list of all points in the graph without pt others = [p for p in gph.nodes if p != p1] # sort them by distance to pt others.sort(key=lambda p: p.distance2(p1)) # return the closest ones others = others[:val] for p2 in others: gph.add_edge(p1, p2, bidirectional=False, check_validity=False) """ Divide Edges Method Subdivides a given graph's edges a given number of times, and returns the resulting points. """ def divide_edges(gph, divs=4):
import decodes as dc from decodes.core import * from decodes.io import * outie = dc.make_out(dc.Outies.Rhino, "wayout") u = 10 v = 10 x = .8 y = 1.2 """ Define a two parametric surfaces """ def func_a(u, v): u1 = u * x v1 = v * y return Point(u, v, (u1**3 - 3 * u1 * (v1**2)) / 4) # eval function for a handkerchief surface def func_b(u, v): u1 = u * x v1 = v * y return Point(u, v, ((1 / 3) * u1**3 + u1 * v1**2 + 2 * (u1**2 - v1**2)) / 4) func = func_a
import decodes from decodes.core import * """ Point """ # point construction pt_a = Point(2,3) pt_b = Point(10,20,30) print pt_a print pt_b #dot operator accesses properties and methods print pt_a.x, pt_a.y, pt_a.z print pt_a.distance(pt_b) # point manipulation pt_a.x = 3 print pt_a """ Drawing Geometry """ outie = decodes.make_out(decodes.Outies.Rhino) #this contains the geometry to be drawn outie.put(pt_a) outie.put(pt_b) outie.draw()
import decodes as dc from decodes.core import * from decodes.io import * outie = dc.make_out(dc.Outies.Rhino, "wayout") u= 10 v = 10 x = .8 y = 1.2 """ Define a two parametric surfaces """ def func_a(u,v): u1 = u*x v1 = v*y return Point(u,v,(u1**3-3*u1*(v1**2))/4) # eval function for a handkerchief surface def func_b(u,v): u1 = u*x v1 = v*y return Point(u,v,((1/3)*u1**3+u1*v1**2+2*(u1**2-v1**2))/4 ) func = func_a # create surface over domain -1 to 1 surf = Surface(func,Interval(-1,1),Interval(-1,1)) meshes = surf.to_mesh(divs_u=u,divs_v=v)
import decodes from decodes.core import * out = decodes.make_out(decodes.Outies.ThreeJS, "myscene", "C:\\") out.put(Point(2, 2, 4)) out.draw() # { # "metadata":{"version":4.3, "type":"Object","generator":"ObjectExporter"}, # "geometries": [{ "uuid": "Some number", "x": , "y": , "z": }], # "materials":[{}], # "object":{ , , ,"children":[{},{}]} # }
import decodes from decodes.core import * outie = decodes.make_out(decodes.Outies.JSON, "json_out", save_file=True) from decodes.extensions.graph import SpatialGraph """ Proximity Edges Adds edges to a given SpatialGraph such that each Point forms connections with a given number of Points nearest to it. """ def add_proximity_connections(gph, val=5): for p1 in gph.nodes: # make a list of all points in the graph without pt others = [p for p in gph.nodes if p != p1] # sort them by distance to pt others.sort(key=lambda p: p.distance2(p1)) # return the closest ones others = others[:val] for p2 in others: gph.add_edge(p1, p2, bidirectional=False, check_validity=False) """ Divide Edges Method Subdivides a given graph's edges a given number of times, and returns the resulting points. """
import decodes as dc from decodes.core import * from decodes.io import * from decodes.io.pyautocad import * acad = Autocad(False, True) outie = dc.make_out(dc.Outies.ACAD, "wayout") # Surface Parameters rad_0 = 0.4 rad_1 = 0.2 ipt = Point(1.0,1.0,0.0) # u_val Parameters count_u = 15 skew_u = 0.5 ival_u = Interval(0, math.pi) # v_val Parameters count_v = 15 skew_v = 1 ival_v = Interval(0, math.pi) # Surface Function tvec = Vec(0,-3,0) # to move the thing away from origin def func(u,v): x = (rad_0+rad_1*math.cos(v))*math.cos(u) y = (rad_0+rad_1*math.cos(v))*math.sin(u) z = rad_1 * math.sin(v)
import decodes as dc from decodes.core import * from decodes.io import * from decodes.io.pyautocad import * acad = Autocad(False, True) outie = dc.make_out(dc.Outies.ACAD, "wayout") # Surface Parameters rad_0 = 0.4 rad_1 = 0.2 ipt = Point(1.0, 1.0, 0.0) # u_val Parameters count_u = 15 skew_u = 0.5 ival_u = Interval(0, math.pi) # v_val Parameters count_v = 15 skew_v = 1 ival_v = Interval(0, math.pi) # Surface Function tvec = Vec(0, -3, 0) # to move the thing away from origin def func(u, v): x = (rad_0 + rad_1 * math.cos(v)) * math.cos(u) y = (rad_0 + rad_1 * math.cos(v)) * math.sin(u)