Beispiel #1
0
            ]

        def on_mouse_down(self, InputEvent):
            #print InputEvent
            if InputEvent.shift_key == True:
                self.q.getSmallestBBox(Point(InputEvent.x, InputEvent.y))
                print self.q.smallestContainer

            self.q.insert(Point(InputEvent.x, InputEvent.y))
            self.points.append(Point(InputEvent.x, InputEvent.y))
            self.bboxs = self.q.getBBoxes()
            print "click: ", InputEvent.x, InputEvent.y

        def drawShapes(self):
            self.draw_rect(0, 0, self.width, self.height, color="#000")
            self.fill_oval(self.width / 2, self.height / 2, 7, 7, "#F00")

            for p in self.points:
                self.fill_oval(p.x, p.y, 7, 7, "#F00")

            self.bboxs = self.q.getBBoxes()
            for b in self.bboxs:
                self.draw_rect(b.ul.x, b.ul.y, b.w, b.h, "#000")

        def update(self):
            self.clear_rect(0, 0, self.width, self.height)
            self.drawShapes()

    app = pantograph.SimplePantographApplication(Driver)
    app.run()
Beispiel #2
0
            (382, 356),  (338, 368),  (287, 302),  (224, 304),  (128, 338),
            (110, 316),  (129, 270),  (83, 231),  (103, 201), 
            (126, 162),  (65, 51)], "#00f"),
            pantograph.CompoundShape([
                pantograph.Rect(15, 15, 10, 10, "#0ff"),
                pantograph.Circle(20, 20, 5, "#ff0")
            ])
        ]

        self.shapes = [BouncingShape(shp) for shp in static_shapes]

    def update(self):
        self.clear_rect(0, 0, self.width, self.height)

        for shape in self.shapes:
            shape.update(self)

        for (a, b) in itertools.combinations(self.shapes, 2):
            if a.shape.intersects(b.shape):
                print a.shape
                xveltmp = a.xvel
                yveltmp = a.yvel
                a.xvel = b.xvel
                a.yvel = b.yvel
                b.xvel = xveltmp
                b.yvel = yveltmp

if __name__ == '__main__':
    app = pantograph.SimplePantographApplication(BouncingBallDemo)
    app.run()
Beispiel #3
0
    """

    def addFinish(self, x, y):
        self.fill_rect(x, y, self.block, self.block, "#0F0")
        self.finishCoord = x, y

    """
    @function adjustCoords

    Fattens the coords to fit grid.

    @param  {integer} - x: x-coordinate
    @param  {integer} - y: y-coordinate
    """

    def adjustCoords(self, x, y):
        """adjust the coords to fit our grid"""
        x = (x / self.block) * self.block
        y = (y / self.block) * self.block
        return (x, y)


"""
Main Driver!!!
"""
if __name__ == '__main__':
    app = pantograph.SimplePantographApplication(DrawAstar)
    app.run()

print("Program ran in %s seconds." % (time.time() - start_time))
Beispiel #4
0
        for state in self.states:
            self.draw_polygon(state, color="#000")

    def shiftState(self, state):
        shiftedState = []
        for p in state:
            x, y = p
            x = x - self.minX
            y = y - self.minY
            shiftedState.append([x, y])
        return shiftedState

    def projectState(self, state):
        projectedState = []
        for p in state:
            x, y = p
            x = (x / self.maxX) * self.width
            y = (y / self.maxY) * self.height
            projectedState.append([x, y])
        return projectedState

    def update(self):
        self.clear_rect(0, 0, self.width, self.height)
        # draw the circle for the "rim" of the wheel
        self.drawStates()


if __name__ == '__main__':
    app = pantograph.SimplePantographApplication(DrawStates)
    app.run()
Beispiel #5
0
            self.balls[i][0] += d1
            self.balls[i][1] += d2

    def drawBalls(self):
        for i in range(self.numBalls):
            self.fill_circle(self.balls[i][0],
                             self.balls[i][1],
                             self.balls[i][3],
                             color=self.balls[i][2])

    def resizeBalls(self):
        for i in range(self.numBalls):
            if random.randint(0, 311) % 2 == 0:
                negate = -1
            else:
                negate = 1

            self.balls[i][3] = self.balls[i][3] + (random.randint(0, 5) *
                                                   negate)

    def update(self):
        self.moveBalls()
        self.clear_rect(0, 0, self.width, self.height)
        #self.resizeBalls()
        self.drawBalls()


if __name__ == '__main__':
    app = pantograph.SimplePantographApplication(ManyBalls)
    app.run()
Beispiel #6
0
                           door.ptstart[1],
                           10,
                           abs(door.ptstart[1] - door.ptend[1]),
                           color="#66CDAA")
        i = 0
        for x, y in zip(area.X_crowd, area.Y_crowd):
            rad = 6
            if i in BIG_USERS:
                img_src = '/img/' + str(i) + '.png'
                self.draw("image", src=img_src, x=x, y=y, width=60, height=60)
                rad = 0.5
                #self.draw_line(x+50,y+100,w,h)
            else:
                self.fill_circle(x,
                                 y,
                                 rad,
                                 color=colors[area.crowd_rooms[i] + 1])
            #else:
            #self.fill_rect(x,y,8,8,color=colors[area.crowd_rooms[i]+1])
            i += 1

        area.make_iteration()


if __name__ == '__main__':
    #app = pantograph.PantographApplication([
    #    ("Pantograph", "/", Rotary)
    #])
    app = pantograph.SimplePantographApplication(Rotary)
    app.run()
Beispiel #7
0
        
    def createBalls(self):
        for i in range(self.numBalls):
            self.balls.append([random.uniform(1, self.width),random.uniform(1,self.height),"#%06x" % random.randint(0, 0xFFFFFF)])
    
    def moveBalls(self):
        for i in range(self.numBalls):
            negate = random.randint(0,311) % 2
            if negate == 0:
                negate = -1
            else:
                negate = 1
            d1 = random.randint(1, 1) * random.randint(1, 1) * negate
            d2 = random.randint(1, 1) * random.randint(1, 1) * negate
            self.balls[i][0] += d1
            self.balls[i][1] += d2
            
    def drawBalls(self):
         for i in range(self.numBalls):
            self.fill_circle(self.balls[i][0], self.balls[i][1], 10, color = self.balls[i][2])       

    def update(self):
        self.moveBalls()
        self.clear_rect(0, 0, self.width, self.height)
        self.drawBalls()
        
        
if __name__ == '__main__':
    app = pantograph.SimplePantographApplication(MyStuff)
    app.run()
Beispiel #8
0
import pantograph
import math
import random
import simulate


class AntCanvas(pantograph.PantographHandler):
    def setup(self):
        self.height, self.width = 1000, 100
        self.farm = simulate.AntFarm(self.height, self.width)
        self.on_mouse_down = self.test
        for x in range(self.height):
            for y in range(self.width):
                self.farm[x, y].guiObject.draw(self)

    def update(self):
        pass

    def test(self, event):
        x, y = event.x // 5, event.y // 5
        print(self.farm[x, y].color)


if __name__ == '__main__':
    app = pantograph.SimplePantographApplication(AntCanvas)
    app.run()
        if (x+w) > self.width:
            w = (self.width-self.buffer)

        if shape == "point":
            h = self.pointSize
            w = self.pointSize

        return Size(x,y,w,h)

    def on_mouse_down(self,InputEvent):
        self.collRect.x = InputEvent.x
        self.collRect.y = InputEvent.y

    def on_mouse_move(self,InputEvent):
        self.collRect.x = InputEvent.x
        self.collRect.y = InputEvent.y


class Size(object):
    def __init__(self,x,y,w,h):
        self.x = x
        self.y = y
        self.w = w
        self.h = h


if __name__ == '__main__':
    app = pantograph.SimplePantographApplication(DrawTree)
    app.run()
Beispiel #10
0
        for sx in range(startX,stopX,step*2):
            if sx + step > stopX:
                break
            self.draw_line(sx, startY, sx+step, startY, "#c0c0c0")

        for sx in range(startX,stopX,step*2):
            if sx + step > stopX:
                break
            self.draw_line(sx, stopY, sx+step, stopY, "#c0c0c0")

        for sy in range(startY,stopY,step*2):
            if sy + step > stopY:
                break
            self.draw_line(startX, sy, startX, sy+step, "#c0c0c0")

        for sy in range(startY,stopY,step*2):
            if sy + step > stopY:
                break
            self.draw_line(stopX, sy, stopX, sy+step, "#c0c0c0")

def printRTree(root):
    for i in root:
        if isinstance(i, Node):
            print (i)
            printRTree(i.Children)


if __name__ == '__main__':
    app = pantograph.SimplePantographApplication(printRtree)
    app.run()