def drawStar(x0, y0, numArms, skip=[]):
    for i in range(numArms):

        a = a0 + i * 2 * pi / numArms
        x = x0 + cos(a)
        y = y0 + sin(a)
        if i in skip:
            ps.dot(x, y, fillcolor='lightgray')
            ps.zigzag(x, y, x0, y0, linecolor='lightgray')
        else:
            ps.dot(x, y);
            ps.zigzag(x, y, x0, y0)
    ps.dot(x0, y0)
def hexagon(x0, y0, a0=2 * pi / 12, n=6):
    lastX = 0
    lastY = 0

    for i in range(n):
        a = a0 + i * 2.0 * pi / 6
        x = x0 + cos(a)
        y = y0 + sin(a)
        ps.dot(x, y)

        if i > 0:
            ps.zigzag(x, y, lastX, lastY)

        lastX = x
        lastY = y
def drawStar(x0, y0, numArms, skip=[], connect=[]):
    for i in range(numArms):

        a = a0 + i * 2 * pi / numArms
        x = x0 + cos(a)
        y = y0 + sin(a)
        if i in skip:
            ps.dot(x, y, fillcolor='lightgray')
            ps.zigzag(x, y, x0, y0, linecolor='lightgray')
        else:
            ps.dot(x, y)
            ps.zigzag(x, y, x0, y0)

        if i in connect:
            a2 = a0 + (i + 1) * 2 * pi / numArms
            x2 = x0 + cos(a2)
            y2 = y0 + sin(a2)
            ps.zigzag(x, y, x2, y2)
    ps.dot(x0, y0)
示例#4
0
import pstricks as ps

# Setup
rows = 4
cols = 4

# ps.put('\psset { coilarm=0.5, coilwidth=0.3, coilheight=0.4 }\n')
ps.init()
ps.dotSize = 0.2
ps.text(1.3, 1.4, '$\overset{\scriptscriptstyle{2, 2}}{u}$')

for y in range(rows):
    for x in range(cols):
        ps.dot(x, y)
        if x == cols - 1 and y == rows - 2:
            ps.zigzag(x, y, x, y + 1)
        else:
            if x < cols - 1:
                ps.zigzag(x, y, x + 1, y)

            if y < rows - 1:
                if x == cols - 1:
                    ps.zigzag(x, y, x, y + 1)
                else:
                    ps.zigzag(x, y, x, y + 1)

ps.end()
ps.render()
drawStar(x0, y0, numArms)
ps.text(x0, y0 - 2.5, 'a)')

ps.arc(x0, y0, 1.2, 0, -90, arrowEnd=True)
a = - pi / 4
l = 1.6
ps.text(x0 + l * cos(a), y0 + l * sin(a), '$N-1$')

x0 += 1.5
ps.line(x0, y0, x0 + 1, y0, arrowEnd=True)

x0 += 2.5
y0 -= 0.5

drawStar(x0, y0, numArms, skip=[5])
ps.text(x0, y0 - 2.0, 'b)')
ps.zigzag(x0, y0 + 1, x0, y0 + 2)
ps.dot(x0, y0 + 2)

ps.arc(x0, y0, 1.2, 0, -90, arrowEnd=True)
a = - pi / 4
l = 1.6
ps.text(x0 + l * cos(a), y0 + l * sin(a), '$N-2$')
ps.framebox(x0 + 0.5, y0, '$-1$')
ps.framebox(x0 + 1.4, y0 + 0.5, '$-2$')
ps.framebox(x0 + 0.5, y0 + 1, '$+2$')
ps.framebox(x0 + 0.5, y0 + 2, '$+2$')

ps.end()
ps.render()