<div> </div>
<div>Here's some field tested code that I think showcases what a student</div>
<div>interested in computer graphics might eyeball and run, after some </div>
<div>background in the basic syntax. </div>
<div> </div>
<div>True, there's stuff going on behind the scenes (another module, plus </div>
<div>VPython, all well documented).</div>
<div> </div>
<div>I'll plan to use this with my high schoolers in April. I want them to </div>
<div>see what real Python really looks like, to get ideas from, for doing </div>
<div>graphics of their own.</div>
<div> </div>
<div>We also use VRML, maybe just projected on the big screen in front.</div>
<div> </div>
<div>Kirby</div>
<div> </div>
<div>
<p>"""<br>coupler.py<br>by K. Urner, (gpl) 2007 <a href="http://4dsolutions.net">4dsolutions.net</a></p>
<p>Documentation for Coupler:</p>
<p>The Coupler is a space-filling irregular octahedron defined<br>by three mutually orthogonal quadrilaterals: one square and<br>two congruent rhombi. This module constructs these quadri-<br>laterals and displays them in VPython.
</p>
<p>In the concentric hierarchy, the Coupler's volume = 1 (i.e.<br>is same as tetrahedron's defined by 4 unit-radius CCP balls).</p>
<p><a href="http://www.rwgrayprojects.com/synergetics/s09/figs/f86431.html">http://www.rwgrayprojects.com/synergetics/s09/figs/f86431.html</a></p>
<p>URL for stickworks.py:<br><a href="http://www.4dsolutions.net/ocn/python/stickworks.py">http://www.4dsolutions.net/ocn/python/stickworks.py</a></p>
<p>Documentation for stickworks.py:<br><a href="http://www.4dsolutions.net/ocn/stickworks.html">http://www.4dsolutions.net/ocn/stickworks.html</a></p>
<p>Relevant VRML worlds by sw dharmraj (see Synergeo on Yahoo!):<br><a href="http://members.westnet.com.au/dharmraj/vrml/coupler.wrl">http://members.westnet.com.au/dharmraj/vrml/coupler.wrl</a><br><a href="http://members.westnet.com.au/dharmraj/vrml/KmiteCube.wrl">
http://members.westnet.com.au/dharmraj/vrml/KmiteCube.wrl</a></p>
<p>See also: Richard Hawkins Digital Archive:<br><a href="http://www.newciv.org/Synergetic_Geometry/">http://www.newciv.org/Synergetic_Geometry/</a></p>
<p>"""</p>
<p>from stickworks import Vector, Edge, axes<br>from math import sqrt</p>
<p>sqrt2 = sqrt(2)<br>apexd = sqrt2/2.0</p>
<p># convention nx for -x (negative x)<br>x = Vector((1,0,0))<br>y = Vector((0,1,0))<br>nx = Vector((-1,0,0))<br>ny = Vector((0, -1, 0))</p>
<p>apex = Vector((0, 0, apexd))<br>napex = Vector((0, 0, -apexd))</p>
<p><br>class Square (object) :<br> """<br> Coupler Square Equator in XY plane<br> """</p>
<p> def __init__(self):<br> Edge.color = (1,0,0)<br> self.edges = [Edge(x,y), Edge(y,nx),<br> Edge(nx,ny), Edge(ny,x)]</p>
<p> def draw(self):<br> for e in self.edges:<br> e.draw()<br> <br>class Fx (object) :<br> """<br> Coupler Equator in XZ plane<br> """</p>
<p> def __init__(self):<br> Edge.color = (0,1,0) <br> self.edges = [ Edge(x, apex), Edge(apex, nx),<br> Edge(nx, napex), Edge(napex, x)]</p>
<p> def draw(self):<br> for e in self.edges:<br> e.draw()<br> <br>class Fy (object) :<br> """<br> Coupler Equator in YZ plane<br> """</p>
<p> def __init__(self): <br> self.edges = [ Edge(y, apex), Edge(apex, ny),<br> Edge(ny, napex), Edge(napex, y)]</p>
<p> def draw(self):<br> for e in self.edges:<br> e.draw()<br> <br>def test():<br> """<br> Draw a Coupler centered at (0,0,0) with XYZ Axes<br> """</p>
<p> # blue axes, please<br> Edge.color = (0,0,1)<br> axes(2,2,2)</p>
<p> # create equator objects<br> ofy = Fy()<br> ofx = Fx()<br> osq = Square()</p>
<p> # draw the rhombi<br> Edge.color = (0,1,0)<br> ofy.draw()<br> ofx.draw()</p>
<p> # draw the square <br> Edge.color = (1,0,0) <br> osq.draw()</p>
<p>if __name__ == '__main__':<br> test()<br> </p></div>