コード例 #1
0
    def __init__(self):
        self.win = pyglet.window.Window(800, 600)
        self.win.push_handlers(self)

        squirtle.setup_gl()  #Sets up blending so we get anti-aliased edges.

        self.sky = squirtle.SVG(
            "svgs/sky.svg")  #Anchors default to bottom left
        self.sun = squirtle.SVG("svgs/sun.svg",
                                anchor_x='center',
                                anchor_y='center')
        self.cloud = squirtle.SVG("svgs/cloud.svg",
                                  anchor_x='right',
                                  anchor_y='top')
        self.tile = squirtle.SVG("svgs/tile.svg",
                                 anchor_x='center',
                                 anchor_y='center')

        self.cloud_locs = [(random.uniform(0, 928), random.uniform(0, 728),
                            random.uniform(1, 2)) for n in xrange(10)]
        self.cloud_locs = sorted(self.cloud_locs, key=lambda x: x[2])

        self.time_elapsed = 0
        self.fps = pyglet.clock.ClockDisplay()

        pyglet.clock.schedule_interval(self.tick, 1 / 60.0)
        pyglet.app.run()
コード例 #2
0
ファイル: editor.py プロジェクト: italomaia/turtle-linux
class PlaceDoorTool(Tool):
    icon = squirtle.SVG(data.file_path("images/icons/door.svgz"))

    def select(self):
        super(PlaceDoorTool, self).select()
        self.start = None

    def lclick(self, x, y, mods):
        if self.start:
            new_id = max(self.editor.world.doors.keys() + [0]) + 1
            self.editor.world.doors[new_id] = door.Door(
                None, self.start, (x, y))
            self.start = None
        else:
            self.start = (x, y)

    def draw(self):
        if self.start:
            x, y = self.editor.mouse_world_pos
            glLineWidth(3)
            glBegin(GL_LINES)
            glVertex2f(*self.start)
            glVertex2f(x, y)
            glEnd()
            glLineWidth(1)
コード例 #3
0
ファイル: editor.py プロジェクト: italomaia/turtle-linux
class PlaceOxygenTool(PlaceActorTool):
    icon = squirtle.SVG(data.file_path("images/all/oxygen.svgz"))
    actors = oxygens.oxygens
    img_path = 'images/all'

    def lclick(self, x, y, mods):
        super(PlaceOxygenTool, self).lclick(x, y, mods)
        self.editor.show_entry("Enter oxygen amount (seconds)...")
        self.entry_oxygen = None
        self.entry_pipe = None
        for obj in self.editor.world.actors:
            if isinstance(obj, oxygen.Oxygen):
                obj.is_initial = False
            self.last_added.is_initial = True

    def entry(self, text):
        if self.entry_oxygen is None:
            if not text.isdigit():
                self.editor.show_entry("Enter oxygen amount (seconds)...")
            else:
                self.entry_oxygen = int(text) * 60
                self.editor.show_entry("Enter pipe length (m)...")
        elif self.entry_pipe is None:
            if not text.isdigit():
                self.editor.show_entry("Enter pipe length (m)...")
            else:
                self.entry_pipe = int(text) * 100
                self.last_added.capacity = self.entry_oxygen
                self.last_added.pipe_length = self.entry_pipe
コード例 #4
0
ファイル: door.py プロジェクト: italomaia/turtle-linux
 def __init__(self, *args, **kwargs):
     super(Switch, self).__init__(*args, **kwargs)
     self.alt_image = squirtle.SVG(data.file_path(kwargs['alt_image_file']),
                                   anchor_x='center',
                                   anchor_y='center')
     self.alt_image_file = kwargs['alt_image_file']
     self.doors = kwargs.get('doors', {})
コード例 #5
0
    def _set_filename(self, filename):
        global squirtle
        if squirtle is None:
            import squirtle
# TODO remove this ugly code, improve loader for this
        try:
            pymt_logger.debug('SVGButton: loading %s' % filename)
            self.svg = squirtle.SVG(filename)
        except Exception, e:
            try:
                svgpath = os.path.join(pymt_data_dir, 'icons/svg')
                pymt_logger.exception('SVGButton: unable to load %s' %
                                      filename)
                pymt_logger.warning('SVGButton: trying %s' %
                                    (svgpath + filename))
                self.svg = squirtle.SVG(os.path.join(svgpath, filename))
            except Exception, e:
                pymt_logger.exception('SVGButton: unable to load file %s' %
                                      filename)
コード例 #6
0
ファイル: editor.py プロジェクト: italomaia/turtle-linux
class LinkDoorTool(Tool):
    icon = squirtle.SVG(data.file_path("images/icons/door.svgz"))
    colors = {
        'toggle': (1, 1, 0),
        'open': (0, 1, 0),
        'close': (1, 0, 0),
        '': (0, 0, 1)
    }

    modes = ['toggle', 'open', 'close', '']

    def select(self):
        super(LinkDoorTool, self).select()
        self.switch = None
        self.mode = 'toggle'

    def cycle_modes(self):
        n = self.modes.index(self.mode)
        self.mode = self.modes[(n + 1) % len(self.modes)]

    def lclick(self, x, y, mods):
        for act in self.editor.world.actors:
            if isinstance(act, door.Switch) and (act.pos -
                                                 (x, y)).length < act.radius:
                self.switch = act
                return
        if self.switch:
            for id, my_door in self.editor.world.doors.items():
                dist = (my_door.ls.closest_point(Vector(
                    (x, y))) - (x, y)).length
                if dist < my_door.thickness:
                    if self.mode:
                        self.switch.doors[id] = self.mode
                    else:
                        del self.switch.doors[id]

    def press(self, sym, mods):
        if sym == key.TAB:
            self.cycle_modes()

    def draw(self):
        if self.switch:
            x, y = self.editor.mouse_world_pos
            glLineWidth(3)
            glBegin(GL_LINES)
            glColor3f(*self.colors[self.mode])
            glVertex2f(*self.switch.pos)
            glVertex2f(x, y)
            for id, mode in self.switch.doors.items():
                if mode:
                    glColor3f(*self.colors[mode])
                    glVertex2f(*self.switch.pos)
                    glVertex2f(*self.editor.world.doors[id].pos)
            glEnd()
            glLineWidth(1)
コード例 #7
0
ファイル: pyglet-example3.py プロジェクト: deavid/grease
    def __init__(self, filename, quality=4):
        self.shape = squirtle.SVG(filename,
                                  bezier_points=quality,
                                  circle_points=quality * 3,
                                  anchor_x='center',
                                  anchor_y='center',
                                  reversed_order=True)
        max_size = max([self.shape.width, self.shape.height])

        self.main_scale = 1.0 / max_size
        self.displaylist = self.shape.disp_list
コード例 #8
0
ファイル: editor.py プロジェクト: italomaia/turtle-linux
class PlaceSignpostTool(PlaceActorTool):
    icon = squirtle.SVG(data.file_path("images/all/signpost.svgz"))
    actors = signposts.signposts
    img_path = 'images/all'

    def lclick(self, x, y, mods):
        super(PlaceSignpostTool, self).lclick(x, y, mods)
        self.editor.show_entry('Enter text key...')

    def entry(self, text):
        self.last_added.text_key = text
コード例 #9
0
ファイル: data.py プロジェクト: italomaia/turtle-linux
def load_svg(path, **kwds):
    """Load a scalable vector graphic from the images directory.

    :Parameters:
        `path` : str
            The relative path from the images directory to the file.

    """
    svg_path = os.path.join(DATA_DIR, "images", path)
    svg = squirtle.SVG(svg_path, **kwds)
    return svg
コード例 #10
0
ファイル: test_suite.py プロジェクト: msarch/py
def nextFile():
    global filename, svgObj
    if not filename:
        next = 0
    else:
        prevFile = os.path.basename(filename)
        next = filelist.index(prevFile)+1
        next %= len(filelist)
    filename = os.path.join('svgs', filelist[next])
    print 'Parsing', filename
    svgObj = squirtle.SVG(filename)
    svgObj.anchor_x, svgObj.anchor_y = svgObj.width/2, svgObj.height/2
コード例 #11
0
 def __init__(self, stage=None):
     self.static = spatialhash.SpatialHash(2000)
     self.actors = spatialhash.SpatialHash(500)
     self.doors = {}
     self.swag_counts = {}
     if stage is not None:
         for obj in stage["objects"]:
             self.static.add(obj)
         if 'background' in stage:
             self.background = squirtle.SVG(stage['background'],
                                            anchor_x='center',
                                            anchor_y='center')
         else:
             self.background = squirtle.SVG(
                 'data/images/background/space.svgz',
                 anchor_x='center',
                 anchor_y='center')
         for act in stage.get("actors", []):
             self.actors.add(act)
         self.doors = stage.get('doors', {})
         self.swag_counts = stage.get('swag_counts', {})
コード例 #12
0
 def _set_filename(self, filename):
     global squirtle
     if squirtle is None:
         import squirtle
     # TODO remove this ugly code, improve loader for this
     try:
         if self.rawdata is None:
             pymt_logger.debug('SVG: loading %s' % filename)
             self.svg = squirtle.SVG(filename)
         else:
             pymt_logger.debug('SVG: loading %s from rawdata' % filename)
             self.svg = squirtle.SVG(filename=filename,
                                     rawdata=self.rawdata)
     except Exception:
         try:
             svgpath = os.path.join(pymt_data_dir, 'icons/svg')
             pymt_logger.exception('SVG: unable to load %s' % filename)
             pymt_logger.warning('SVG: trying %s' % (svgpath + filename))
             self.svg = squirtle.SVG(os.path.join(svgpath, filename))
         except Exception:
             pymt_logger.exception('SVG: unable to load file %s' % filename)
             self._filename = filename
             self.size = (self.svg.width, self.svg.height)
コード例 #13
0
def load_image(path, **kwds):
    """Load an image file from the images directory.

    Additional arguments are passed to squirtle.SVG.

    :Parameters:
        `path` : str
            The relative path from the images directory to the file.

    """
    if isinstance(path, basestring):
        image_path = os.path.join(DATA_DIR, "images", path)
    else:
        image_path = os.path.join(DATA_DIR, "images", *path)
    return squirtle.SVG(image_path, **kwds)
コード例 #14
0
ファイル: editor.py プロジェクト: italomaia/turtle-linux
 def select_actor(self, id):
     id %= len(self.actors)
     id += len(self.actors)
     id %= len(self.actors)
     self.actor_class, self.actor_radius, self.actor_name, self.actor_img = self.actors[
         id][:4]
     self.actor_img = os.path.join(self.img_path, self.actor_img)
     self.actor_extras = dict(
         zip(self.actor_class.extra_keys, self.actors[id][4:]))
     for k, v in self.actor_extras.iteritems():
         if isinstance(v, str) and v.endswith('.svgz'):
             self.actor_extras[k] = os.path.join(self.img_path, v)
     self.img_svg = squirtle.SVG(data.file_path(self.actor_img),
                                 anchor_x='center',
                                 anchor_y='center')
     self.selected_id = id
コード例 #15
0
ファイル: mazes.py プロジェクト: msarch/py
    def set(self):
        #print "MAP INDEX = ", self.mapIndex, "MAP SELECTION = ", selection

        #self.mapIndex = selection
        if self.mapIndex > (len(self.mapList) - 1):
            self.mapIndex = 0
        elif self.mapIndex < 0:
            self.mapIndex = (len(self.mapList) - 1)

        Objects.gObjects = []
        self.map = squirtle.SVG(mapsBaseDir + self.mapList[self.mapIndex])

        self.world = libsvg2b2d.SVG2B2D(file=mapsBaseDir +
                                        self.mapList[self.mapIndex],
                                        ratio=self.RATIO)

        self.contactListener = ContactListener()
        self.world.SetContactListener(self.contactListener)

        Objects.world = self.world

        self.spawnObjects()
コード例 #16
0
def draw(canvas):
    canvas.clear()
    nofill()
    stroke(0, 0.25)
    strokewidth(1)
    rect( 50, 50, 50, 50)
    rect(110, 50, 50, 50, stroke=Color(0), strokestyle=DASHED)
    rect(170, 50, 50, 50)


    glClearColor(1,1,1,1)

    squirtle.setup_gl()

    s = squirtle.SVG(filename)
    s.anchor_x, s.anchor_y = s.width/2, s.height/2

    zoom = 1
    angle = 0
    draw_x = 400
    draw_y = 300

    s.draw(draw_x, draw_y, scale=zoom, angle=angle)
コード例 #17
0
ファイル: actor.py プロジェクト: italomaia/turtle-linux
 def __init__(self,
              world,
              pos=(0, 0),
              radius=50,
              bearing=0,
              image_file=None,
              name=None,
              **kwargs):
     self.world = world
     self.pos = v(pos)
     self.old_pos = v(pos)
     self.radius = radius
     self.bearing = bearing
     self.old_bearing = bearing
     self.image_file = image_file
     self.image = squirtle.SVG(data.file_path(image_file),
                               anchor_x='center',
                               anchor_y='center')
     self.dead = False
     self.impulse = v((0, 0))
     self.name = name
     # do not use
     self.scale = 0.0
     self.z = 0
コード例 #18
0
ファイル: editor.py プロジェクト: italomaia/turtle-linux
class PlaceEnemyTool(PlaceActorTool):
    icon = squirtle.SVG(data.file_path("images/icons/enemy.svgz"))
    actors = enemies.enemies
    img_path = 'images'
コード例 #19
0
ファイル: editor.py プロジェクト: italomaia/turtle-linux
class PlaceSwagTool(PlaceActorTool):
    icon = squirtle.SVG(data.file_path("images/icons/swag.svgz"))
    actors = swags.swags
    img_path = 'images/swag'
コード例 #20
0
import os, sys
sys.path.insert(0, os.path.join("..", ".."))

from nodebox.graphics import *
import squirtle
import amethyst

# TODO : load/read svg, extract paths to nodebox paths to be able to modify them
# TODO :  possible re-export screens to svg (svg write) ?

White = color(amethyst.color("white"))
path1 = BezierPath()
path1.moveto(0, 0)
path1.curveto(0, 16.585, 28.321, 28.335, 28.321, 28.335)

filename = "svg/curve.svg"
s = squirtle.SVG(filename)


def draw(canvas):

    background(color(amethyst.color("red")))
    drawpath(path1, fill=None, stroke=White)
    s.draw(200, 200, scale=1, angle=0)


canvas.fps = 60
canvas.size = 600, 400
# canvas.fullscreen = True
canvas.run(draw)
コード例 #21
0
ファイル: labglass.py プロジェクト: msarch/py
 def __init__(self, x, y, width, height, color, hovercolor, text, filename):
     button.__init__(self, x, y, width, height, color, hovercolor, "")
     self.filename = filename
     self.svg = squirtle.SVG(filename, bezier_points=150, circle_points=150)
コード例 #22
0
import os, sys;sys.path.insert(0,os.path.join("..",".."))

from nodebox.graphics import *



from random import seed
from math   import sin

import squirtle


filename = "svg/leaf2.svg"
filename2 = "svg/slice 3.svg"
lines = []
s = squirtle.SVG(filename)
s2 = squirtle.SVG(filename2)
# attention squirtle ne lit pas les svg (issus de skertch) dont les couleurs sont definies par :
# colour rgb(222, 100,33) par ex, utiliser : stroke="#969696"

s.anchor_x, s.anchor_y = 0, s.height
s2.anchor_x, s2.anchor_y = 0, s2.height
zoom = 1
angle = 30
draw_x = 300
draw_y = 200


def draw(canvas):
    background(0.1, 0.0, 0.1, 0.25)
    global angle
コード例 #23
0
from nodebox.graphics import translate, scale, rotate
from random import random
import squirtle
import amethyst
import amethsvg_MOD01 as svgRead
# couleur dans la librairy 'amethyst'
White = color(amethyst.triplet("white"))

# standard nodeboxGL graphics command
path1 = BezierPath()
path1.moveto(0, 0)
path1.curveto(0, 16.585, 28.321, 28.335, 28.321, 28.335)

# squirtle svg parser
filename = "svg/curve.svg"
path2 = squirtle.SVG(filename)

# svg lib from Nodebox
# The parse() command will return
# a list of the shapes in the SVG file.
paths3 = svgRead.parse(open("svg/curve.svg").read())


def draw(canvas):
    #background(color(amethyst.triplet("red")))

    stroke(0.0, 0.25)  # 75% transparent black.
    strokewidth(1)
    triangle(200, 200, 250, 300, 300, 200)

    # While rect() and ellipse() expect x, y, width, height parameters,