<commit_before>from browser import window, document
from random import randint
from javascript import JSObject, JSConstructor

w = window.open("", "")


# depends on pixi.js 
PIXI = JSObject(window.PIXI)
PIXI_loader = JSObject(PIXI.loader)
PIXI_loader.reset()

PIXI_Sprite = JSConstructor(PIXI.Sprite)
PIXI_Texture = JSConstructor(PIXI.Texture)
PIXI_Rectangle = JSConstructor(PIXI.Rectangle)


class Rectangle(object):
    def __init__(self, x, y, w, h):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.PIXI = PIXI_Rectangle(x,y,w,h)
    
    @property
    def center(self):
        return (self.x + self.w//2, self.y + self.h//2)
    
    @center.setter
    def center(self, value):
        c = self.center
        self.x += value[0] - c[0]
        self.y += value[1] - c[1]
        
class ImageAsset(object):
    def __init__(self, url):
        self.url = url
        self.PIXI = PIXI.Texture.fromImage(url, False)

class Sprite(object):
    def __init__(self, texture, position = (0,0), frame = False):
        if (frame):
            self.PIXI = PIXI_Sprite(PIXI_Texture(texture.PIXI, frame.PIXI))
            print("sub-frame {}".format(frame))
        else:
            self.PIXI = PIXI_Sprite(texture.PIXI)
        self.pos = position
        
    @property
    def pos(self):
        return (self.PIXI.position.x, self.PIXI.position.y)
        
    @pos.setter
    def pos(self, value):
        self.PIXI.position.x = value[0]
        self.PIXI.position.y = value[1]
        

if __name__ == '__main__':
    def animate(fake):
      w.requestAnimationFrame(animate)
      RENDERER.render(STAGE)
    
    bunnyurl = "bunny.png"
    print("ggame test.")
    bunny = ImageAsset(bunnyurl)
    Stage = JSConstructor(PIXI.Container)
    STAGE = Stage()
    RENDERER = PIXI.autoDetectRenderer(1000,650, {'transparent':True})

    #s1 = PIXI_Sprite(PIXI_Texture(bunny.texture, frame))

    frame = Rectangle(0,0,30,30)
    s = Sprite(bunny, (0,0), frame)
    
    STAGE.addChild(s.PIXI)
    w.document.body.appendChild(RENDERER.view)
    w.requestAnimationFrame(animate)
<commit_msg>Updated from Brython Server: 7/27/2015 4:39:42 PM<commit_after>from browser import window, document
from random import randint
from javascript import JSObject, JSConstructor

w = window.open("", "")


# depends on pixi.js 
PIXI = JSObject(window.PIXI)
PIXI_loader = JSObject(PIXI.loader)
PIXI_loader.reset()

PIXI_Sprite = JSConstructor(PIXI.Sprite)
PIXI_Texture = JSConstructor(PIXI.Texture)
PIXI_Rectangle = JSConstructor(PIXI.Rectangle)


class Rectangle(object):
    def __init__(self, x, y, w, h):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.PIXI = PIXI_Rectangle(x,y,w,h)
    
    @property
    def center(self):
        return (self.x + self.w//2, self.y + self.h//2)
    
    @center.setter
    def center(self, value):
        c = self.center
        self.x += value[0] - c[0]
        self.y += value[1] - c[1]
        
class ImageAsset(object):
    def __init__(self, url):
        self.url = url
        self.PIXI = PIXI.Texture.fromImage(url, False)

class Sprite(object):
    def __init__(self, texture, position = (0,0), frame = False):
        if (frame):
            self.PIXI = PIXI_Sprite(PIXI_Texture(texture.PIXI, frame.PIXI))
        else:
            self.PIXI = PIXI_Sprite(texture.PIXI)
        self.pos = position
        
    @property
    def pos(self):
        return (self.PIXI.position.x, self.PIXI.position.y)
        
    @pos.setter
    def pos(self, value):
        self.PIXI.position.x = value[0]
        self.PIXI.position.y = value[1]
        

if __name__ == '__main__':
    def animate(fake):
      w.requestAnimationFrame(animate)
      RENDERER.render(STAGE)
    
    bunnyurl = "bunny.png"
    print("ggame test.")
    bunny = ImageAsset(bunnyurl)
    Stage = JSConstructor(PIXI.Container)
    STAGE = Stage()
    RENDERER = PIXI.autoDetectRenderer(1000,650, {'transparent':True})

    #s1 = PIXI_Sprite(PIXI_Texture(bunny.texture, frame))

    frame = Rectangle(0,0,30,30)
    s = Sprite(bunny, (0,0), frame)
    
    for x in range(50,500,10):
        for y in range(50,500,10):
            STAGE.addChild(Sprite(bunny, (x,y)).PIXI)
    
    
    w.document.body.appendChild(RENDERER.view)
    w.requestAnimationFrame(animate)

{'fraction_non_alphanumeric': 0.12923289564616447, 'fraction_numerical': 0.01796821008984105, 'mean_word_length': 2.5473856209150325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6016447', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1548, 'n_words': 303}