Skip to content

Instantly share code, notes, and snippets.

@techieji
Last active October 5, 2021 22:50
Show Gist options
  • Save techieji/a52a96c9fd4cf2d6d712cb43308bc27e to your computer and use it in GitHub Desktop.
Save techieji/a52a96c9fd4cf2d6d712cb43308bc27e to your computer and use it in GitHub Desktop.
A 3d drawer
SCALE, Point, Drawer, run, run_lines = 25, type('Point', (), {'__init__': lambda self, x, y, z: [None, [setattr(self, a, b) for a, b in zip('x y z _x _y _z'.split(), [x, y, z, x*SCALE, y*SCALE, z*SCALE])]][0]}), type('Drawer', (__import__('turtle').Turtle,), {'go_home': lambda self: [self.pu(),self.home(),self.pd()],'go_to_point': lambda self, p: [self.home(),self.seth(150),self.fd(p._x),self.seth(30),self.fd(p._y),self.seth(90),self.fd(p._z)],'draw_line': lambda self, p1, p2: [self.pu(),self.go_to_point(p2),position := self.pos(),self.go_to_point(p1),self.pd(),self.goto(position)],'draw_shape': lambda self, *l: [self.draw_line(l[x - 1], l[x]) for x in range(len(l))]}), lambda t, i: {'pu': t.pu, 'pd': t.pd, 'gp': t.go_to_point, 'dl': t.draw_line, 'ds': t.draw_shape, 'ex': __import__('sys').exit, 'cl': t.reset}.get(i[:2], lambda *a: print('?'))(*([Point(*[float(y.strip()) for y in x.split(',')]) for x in i[2:].split(';')] if len(i) != 2 else [])), lambda s: [t := Drawer(), t.speed(0), [run(t, w) for x in s.split('\n') if (w:=x.strip())], t.go_home()]
# run_lines("ds0,0,0;3,0,0;3,0,3\nds0,2,0;3,2,0;3,2,3\ndl3,0,0;3,2,0\nds0,0,0;0,1,3;0,2,0\nds3,0,3;0,1,3;3,2,3") # prob 21
# run_lines("ds0,0,0;3,0,0;3,0,2;2,0,2;2,0,1;0,0,1\nds0,2,0;3,2,0;3,2,2;0,2,2\ndl0,0,0;0,2,0\ndl3,0,0;3,2,0\ndl3,0,2;3,2,2\ndl0,0,1;0,2,2\ndl2,0,1;0,2,2\ndl2,0,2;0,2,2\n") # prob 23
@techieji
Copy link
Author

techieji commented Oct 5, 2021

Now, it's minimized. For the big, actual version with the shell and everything, just look at the previous commit.

To run a sample model, just uncomment one of bottom two lines. These were given to me as an assignment in class to draw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment