File: cube.py

package info (click to toggle)
pyx3 0.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: python: 27,656; makefile: 225; ansic: 130; sh: 17
file content (31 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from itertools import product, combinations
from operator import eq
from pyx import *

projector = graph.graphxyz.central(10, 20, -30).point

a = 2
cube = list(product([-a, a], repeat=3))
edges = list(filter(lambda edge: sum(map(eq, edge[0], edge[1])) == 2,
                    combinations(cube, 2)))

c = canvas.canvas()

for begin, end in edges:
    x1, y1 = projector(*begin)
    x2, y2 = projector(*end)
    if begin[0] != end[0]:
        col = color.rgb.blue
    elif begin[0] == a:
        col = color.rgb.red
    else:
        col = color.rgb.green
    c.stroke(path.line(x1, y1, x2, y2), [style.linewidth.Thick, col])

for vertex in cube:
    x, y = projector(*vertex)
    c.fill(path.circle(x, y, 0.2))

c.writeEPSfile()
c.writePDFfile()
c.writeSVGfile()