示例#1
0

size = Vec2(600,600)
canvas = Window(size)

def inMandelbrotSet(c):
    z = 0
    h = 0
    for h in xrange(0, 100):
        z = z**2 + c
        if abs(z) > 2:
            break;
    if abs(z) >= 2:
        return -1
    else:
        return h

for x in range (0, size.x):
    real = x / 200.0 - 1.5
    for y in range(0, size.y):
        img = y / 200.0 -1.5
        c = complex(real, img)

        n = inMandelbrotSet(c)
        if n!= -1:
            #print n/100.0
            canvas.setColor(Vec2(x,y), Color.getHSBColor(n/100.0,1,0.5))
canvas.refresh()
print "done"

示例#2
0
Window.init(PixelMathBridge())

size = Vec2(100,100)
canvas = Window(size)
pmOpenImage(canvas.id,"archery.jpg")


def neighboring(position):
    yield position.plus(Vec2(-1,-1))
    yield position.plus(Vec2(-1,0))
    yield position.plus(Vec2(-1,1))
    yield position.plus(Vec2(0,-1))
    #yield position.plus(Vec2(0,0))
    yield position.plus(Vec2(0,1))
    yield position.plus(Vec2(1,-1))
    yield position.plus(Vec2(1,0))
    yield position.plus(Vec2(1,1))

for pos in canvas.positions():
    for neighbor in neighboring(pos):
        if neighbor.y < size.y and neighbor.x < size.x and neighbor.y >0 and neighbor.x >0:
            current = canvas.getColor(pos)
            next    = canvas.getColor(neighbor)
            if current.equals(next):
                canvas.setColor(pos,Color.RED)
                break

canvas.refresh()
print "done"

示例#3
0
    def getImageWidth(self, id):
        return pmGetImageWidth(int(id))
    def getImageHeight(self, id):
        return pmGetImageHeight(int(id))

    def refresh(self, id):
        return pmUpdateDisplay(int(id))
Window.init(PixelMathBridge())

marker = "*"
def sierpinski(n):
    d = [marker]
    for i in xrange(n):
        sp = " " * (2 ** i)
        d = [sp+x+sp for x in d] + [x+" "+x for x in d]
    return d


canvas = Window(Vec2(255,255))
y = 0
x = 0
for line in sierpinski(7):
    y += 1
    for char in line:
        x += 1
        if char in marker:
            canvas.setColor(Vec2(x,y),Color.RED)
    x=0
canvas.refresh()
print "done"