Ejemplo n.º 1
0
    def initialiseComponent(self):
        # listen to shutdown events
        ogl_display = OpenGLDisplay.getDisplayService()[0]
        self.link( (ogl_display, "signal"), (self, "control") )
    
        # create board
        self.boardvis = CheckersBoard(position=(0,0,-15)).activate()
        
        self.interactor_comms = {}

        self.board = {}                
        for i in range(8):
            self.board[i] = {}
            for j in range(8):
                self.board[i][j] = None
        
        # create black pieces
        self.blackPieces = []
        self.blackInteractors = []
        for i in range(8):
            for j in range(3):
                if (i+j) %2 == 0:
                    x = float(i)-3.5
                    y = float(j)-3.5
                    piece = CheckersPiece(position=(x, y, -15), colour=(0.6,0,0)).activate()
                    self.blackPieces.append(piece)

                    interactor = CheckersInteractor(target=piece, colour='B').activate()
                    self.blackInteractors.append(interactor)

                    intcomms = self.addOutbox("interactor_comms")
                    self.interactor_comms[id(interactor)] = intcomms
                    self.link( (self, intcomms), (interactor, "inbox"))
                    self.link( (interactor, "outbox"), (self, "inbox"))
                    
                    self.board[i][j] = 'B'

                    
        # create white pieces
        self.whitePieces = []
        self.whiteInteractors = []
        for i in range(8):
            for j in range(5,8):
                if (i+j) %2 == 0:
                    x = float(i)-3.5
                    y = float(j)-3.5
                    piece = CheckersPiece(position=(x, y, -15), colour=(0,0,0.6)).activate()
                    self.whitePieces.append(piece)

                    interactor = CheckersInteractor(target=piece, colour='B').activate()
                    self.whiteInteractors.append(interactor)

                    intcomms = self.addOutbox("interactor_comms")
                    self.interactor_comms[id(interactor)] = intcomms
                    self.link( (self, intcomms), (interactor, "inbox"))
                    self.link( (interactor, "outbox"), (self, "inbox"))

                    self.board[i][j] = 'W'

        return 1
Ejemplo n.º 2
0
    def __init__(self,
                 screensize=(800, 600),
                 fullscreen=False,
                 caption="3D Topology Viewer",
                 particleTypes=None,
                 initialTopology=None,
                 laws=None,
                 simCyclesPerRedraw=1,
                 border=0):
        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""

        super(TopologyViewer3D, self).__init__()

        glutInit(sys.argv)

        tracker = _cat.coordinatingassistanttracker.getcat()
        try:
            self.display = tracker.retrieveService("ogl_display")[0]
        except KeyError:
            self.display = OpenGLDisplay(width=screensize[0],
                                         height=screensize[1],
                                         fullscreen=fullscreen,
                                         title=caption)
            self.display.activate()
            OpenGLDisplay.setDisplayService(self.display, tracker)
        self.display = OpenGLDisplay.getDisplayService()[0]
        self.link((self, "display_signal"), (self.display, "notify"))
        self.link((self.display, "signal"), (self, "control"))

        self.border = border

        if particleTypes == None:
            self.particleTypes = {
                "-": CuboidParticle3D,
                "cuboid": CuboidParticle3D,
                "sphere": SphereParticle3D,
                "teapot": TeapotParticle3D
            }
        else:
            self.particleTypes = particleTypes

        if initialTopology == None:
            initialTopology = ([], [])
        self.initialNodes = list(initialTopology[0])
        self.initialBonds = list(initialTopology[1])

        self.hitParticles = []
        self.multiSelectMode = False
        self.selectedParticles = []
        self.grabbed = False
        self.rotationMode = False

        if laws == None:
            self.laws = Kamaelia.Support.Particles.SimpleLaws(bondLength=2)
        else:
            self.laws = laws

        self.physics = ParticleSystem(self.laws, [], 0)
        self.biggestRadius = 0

        # Do interaction
        self.simCyclesPerRedraw = simCyclesPerRedraw
        self.lastIdleTime = time.time()

        # Tell if new node is added; if true, new id needs adding to OpenGLDisplay list
        self.isNewNode = False

        # For hierarchy structure
        self.maxLevel = 0
        self.currentLevel = 0
        self.previousParentParticleID = self.currentParentParticleID = ''
        self.viewerOldPos = Vector()
        self.levelViewerPos = {}
        # The Physics particle system of current display level for display
        self.currentDisplayedPhysics = ParticleSystem(self.laws, [], 0)

        # For double click
        self.lastClickPos = (0, 0)
        self.lastClickTime = time.time()
        self.dClickRes = 0.3
Ejemplo n.º 3
0
from Webcam import VideoCaptureSource

#from BlankCanvas import BlankCanvas


if __name__=="__main__":
    width = 1024
    height = 768
    top = 0
    left = 0
    colours_order = [ "black", "red", "orange", "yellow", "green", "turquoise", "blue", "purple", "darkgrey", "lightgrey" ]
    ogl_display = OpenGLDisplay(title="Kamaelia Whiteboard",width=width,height=height,background_colour=(255,255,255))
    ogl_display.activate()
    OpenGLDisplay.setDisplayService(ogl_display)
    
    ogl_display = OpenGLDisplay.getDisplayService()
    PygameDisplay.setDisplayService(ogl_display[0])
    
    if (0):
        #PygameDisplay.setDisplayService(ogl_display)
        CANVAS = Canvas( position=(left,top+32),size=(1200,(900-(32+15))),notepad="Test" ).activate() #(replace width with 'width' and height with 'height-(32+15)'
        PAINTER = Painter().activate()
        CANVAS_WRAPPER = PygameWrapper(wrap=CANVAS, position=(0,0,-10), rotation=(0,0,0)).activate() 
        ERASER  = Eraser(left,top).activate()
        PALETTE = buildPalette( cols=colours, order=colours_order, topleft=(left+64,top), size=32 ).activate()
        CLEAR = ClearPage(left+(64*5)+32*len(colours),top).activate()
        #PALETTE_WRAPPER = PygameWrapper(wrap=PALETTE, position=(4,1,-10), rotation=(-20,15,3)).activate()
    
        #PAINTER_WRAPPER = PygameWrapper(wrap=PAINTER, position=(4,1,-10), rotation=(-20,15,3)).activate()
        CANVAS.link( (PAINTER,"outbox"), (CANVAS, "inbox") )
        PAINTER.link( (CANVAS,"eventsOut"), (PAINTER, "inbox") )
Ejemplo n.º 4
0
    def initialiseComponent(self):
        # listen to shutdown events
        ogl_display = OpenGLDisplay.getDisplayService()[0]
        self.link((ogl_display, "signal"), (self, "control"))

        # create board
        self.boardvis = CheckersBoard(position=(0, 0, -15)).activate()

        self.interactor_comms = {}

        self.board = {}
        for i in range(8):
            self.board[i] = {}
            for j in range(8):
                self.board[i][j] = None

        # create black pieces
        self.blackPieces = []
        self.blackInteractors = []
        for i in range(8):
            for j in range(3):
                if (i + j) % 2 == 0:
                    x = float(i) - 3.5
                    y = float(j) - 3.5
                    piece = CheckersPiece(position=(x, y, -15),
                                          colour=(0.6, 0, 0)).activate()
                    self.blackPieces.append(piece)

                    interactor = CheckersInteractor(target=piece,
                                                    colour='B').activate()
                    self.blackInteractors.append(interactor)

                    intcomms = self.addOutbox("interactor_comms")
                    self.interactor_comms[id(interactor)] = intcomms
                    self.link((self, intcomms), (interactor, "inbox"))
                    self.link((interactor, "outbox"), (self, "inbox"))

                    self.board[i][j] = 'B'

        # create white pieces
        self.whitePieces = []
        self.whiteInteractors = []
        for i in range(8):
            for j in range(5, 8):
                if (i + j) % 2 == 0:
                    x = float(i) - 3.5
                    y = float(j) - 3.5
                    piece = CheckersPiece(position=(x, y, -15),
                                          colour=(0, 0, 0.6)).activate()
                    self.whitePieces.append(piece)

                    interactor = CheckersInteractor(target=piece,
                                                    colour='B').activate()
                    self.whiteInteractors.append(interactor)

                    intcomms = self.addOutbox("interactor_comms")
                    self.interactor_comms[id(interactor)] = intcomms
                    self.link((self, intcomms), (interactor, "inbox"))
                    self.link((interactor, "outbox"), (self, "inbox"))

                    self.board[i][j] = 'W'

        return 1
Ejemplo n.º 5
0
 def __init__(self, screensize         = (800,600),
                    fullscreen         = False, 
                    caption            = "3D Topology Viewer", 
                    particleTypes      = None,
                    initialTopology    = None,
                    laws               = None,
                    simCyclesPerRedraw = 1,
                    border             = 0):
     """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
     
     super(TopologyViewer3D, self).__init__()
     
     glutInit(sys.argv)
     
     tracker = _cat.coordinatingassistanttracker.getcat()
     try:
         self.display = tracker.retrieveService("ogl_display")[0]
     except KeyError:
         self.display = OpenGLDisplay(width=screensize[0], height=screensize[1],fullscreen=fullscreen,
                                 title=caption)
         self.display.activate()
         OpenGLDisplay.setDisplayService(self.display, tracker)
     self.display = OpenGLDisplay.getDisplayService()[0]                
     self.link((self,"display_signal"), (self.display,"notify"))
     self.link((self.display,"signal"), (self,"control"))
     
     self.border = border
     
     if particleTypes == None:
         self.particleTypes = {"-":CuboidParticle3D, "cuboid":CuboidParticle3D, "sphere":SphereParticle3D,
                               "teapot":TeapotParticle3D}
     else:
         self.particleTypes = particleTypes
         
     if initialTopology == None:
         initialTopology = ([],[])
     self.initialNodes   = list(initialTopology[0])
     self.initialBonds   = list(initialTopology[1])
     
     self.hitParticles = []
     self.multiSelectMode = False
     self.selectedParticles = []
     self.grabbed = False
     self.rotationMode = False  
     
     if laws==None:
         self.laws = Kamaelia.Support.Particles.SimpleLaws(bondLength=2)
     else:
         self.laws = laws
         
     self.physics = ParticleSystem(self.laws, [], 0)
     self.biggestRadius = 0
     
     # Do interaction
     self.simCyclesPerRedraw = simCyclesPerRedraw
     self.lastIdleTime = time.time()
     
     # Tell if new node is added; if true, new id needs adding to OpenGLDisplay list
     self.isNewNode = False
     
     # For hierarchy structure
     self.maxLevel = 0
     self.currentLevel = 0
     self.previousParentParticleID = self.currentParentParticleID = ''
     self.viewerOldPos = Vector()
     self.levelViewerPos = {}
     # The Physics particle system of current display level for display
     self.currentDisplayedPhysics = ParticleSystem(self.laws, [], 0)
     
     # For double click
     self.lastClickPos = (0,0)
     self.lastClickTime = time.time()
     self.dClickRes = 0.3
Ejemplo n.º 6
0
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.UI.OpenGL.OpenGLDisplay import OpenGLDisplay
from Kamaelia.UI.OpenGL.PygameWrapper import PygameWrapper
from Kamaelia.UI.OpenGL.MatchedTranslationInteractor import MatchedTranslationInteractor
from Kamaelia.UI.PygameDisplay import PygameDisplay
from Kamaelia.UI.Pygame.Button import Button
from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer

from Kamaelia.UI.Pygame.VideoSurface import VideoSurface
from Kamaelia.Codec.Dirac import DiracDecoder
from Kamaelia.Util.RateFilter import MessageRateLimit
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
from Kamaelia.Video.PixFormatConversion import ToRGB_interleaved

# override pygame display service
ogl_display = OpenGLDisplay.getDisplayService(fullscreen=True)
PygameDisplay.setDisplayService(ogl_display[0])

READER = Textbox(size=(400, 300), text_height=30).activate()
WRITER = TextDisplayer(size=(400, 300), text_height=30).activate()

SCREEN = VideoSurface().activate()

Pipeline(
    ReadFileAdaptor("TestMaterial/TrainWindow.drc",
                    readmode="bitrate",
                    bitrate=1000000),
    DiracDecoder(),
    MessageRateLimit(10),
    ToRGB_interleaved(),
    SCREEN,
Ejemplo n.º 7
0
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.UI.OpenGL.OpenGLDisplay import OpenGLDisplay
from Kamaelia.UI.OpenGL.PygameWrapper import PygameWrapper
from Kamaelia.UI.OpenGL.MatchedTranslationInteractor import MatchedTranslationInteractor
from Kamaelia.UI.PygameDisplay import PygameDisplay
from Kamaelia.UI.Pygame.Button import Button
from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer

from Kamaelia.UI.Pygame.VideoSurface import VideoSurface
from Kamaelia.Codec.Dirac import DiracDecoder
from Kamaelia.Util.RateFilter import MessageRateLimit
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
from Kamaelia.Video.PixFormatConversion import ToRGB_interleaved

# override pygame display service
ogl_display = OpenGLDisplay.getDisplayService(fullscreen=True)
PygameDisplay.setDisplayService(ogl_display[0])

READER = Textbox(size = (400, 300),text_height=30).activate()
WRITER = TextDisplayer(size = (400, 300),text_height=30).activate()

SCREEN = VideoSurface().activate()


Pipeline(
         ReadFileAdaptor("TestMaterial/TrainWindow.drc", readmode="bitrate",
                         bitrate = 1000000),
         DiracDecoder(),
         MessageRateLimit(10),
         ToRGB_interleaved(),
         SCREEN,