예제 #1
0
def setup(sk):
    "Add all content to the sketch"

    # Add text to the sketch
    font = {"font": Font.mono(), "fontStyle": BOLD}
    sk["Score"] = Text(0).config(anchor=TOPLEFT, color="red", **font)
    text = "Pummel the Chimp, and Win $$$"
    sk += Text(text).config(pos=(sk.width - 1, 0), anchor=TOPRIGHT,
                            **font).config(width=0.75 * sk.width)

    # Add fist
    folder = resolvePath("examples/data", pygame.__file__) + "/"
    img = loadImage(folder + "fist.bmp")
    sk += Image(img).config(pos=sk.center, anchor=TOP).bind(ondraw)

    # Add chimp sprite
    img = loadImage(folder + "chimp.bmp")
    sk["Chimp"] = Sprite(img).config(pos=(48, 48), vel=(10, 0),
                                     bounce=BOTH).bind(ondraw=chimpDraw)

    # Load audio files
    audio = "punch.wav", "whiff.wav"
    sk.sounds = [pygame.mixer.Sound(folder + f) for f in audio]

    # Bind click event handler; hide cursor
    sk.bind(onmousedown)
    sk.cursor = False
예제 #2
0
파일: chimp.py 프로젝트: dmaccarthy/sc8pr
def setup(sk):
    "Add all content to the sketch"

    # Add text to the sketch
    font = {"font":Font.mono(), "fontStyle":BOLD}
    sk["Score"] = Text(0).config(anchor=TOPLEFT, color="red", **font)
    text = "Pummel the Chimp, and Win $$$"
    sk += Text(text).config(pos=(sk.width-1,0),
        anchor=TOPRIGHT, **font).config(width=0.75*sk.width)

    # Add fist
    folder = resolvePath("examples/data", pygame.__file__) + "/"
    img = loadImage(folder + "fist.bmp")
    sk += Image(img).config(pos=sk.center, anchor=TOP).bind(ondraw)

    # Add chimp sprite
    img = loadImage(folder + "chimp.bmp")
    sk["Chimp"] = Sprite(img).config(pos=(48,48),
        vel=(10,0), bounce=BOTH).bind(ondraw=chimpDraw)

    # Load audio files
    audio = "punch.wav", "whiff.wav"
    sk.sounds = [pygame.mixer.Sound(folder + f) for f in audio]

    # Bind click event handler; hide cursor
    sk.bind(onclick)
    sk.cursor = False
예제 #3
0
def setup(sk):
    # Load image originals
    fldr = resolvePath("img", __file__)
    sk.imgs = [
        Image("{}/{}.png".format(fldr, f))
        for f in ("target", "paper", "scissors")
    ]

    # Create button controls and add images to buttons
    w, h = sk.size
    x = w / 4 - 44
    for img in sk.imgs:
        btn = Button((40, 40), 2).config(anchor=BOTTOM, pos=(x, h - 4))
        btn += Image(img).config(pos=btn.center, height=32)
        sk += btn.bind(onclick)  # Bind event handlers
        x += 44

    # Initialize scores to zero
    font = {"font": Font.mono(), "fontSize": 40, "fontStyle": BOLD}
    sk["Score1"] = Text(0).config(color="red",
                                  anchor=TOPLEFT,
                                  pos=(4, 4),
                                  **font)
    sk["Score2"] = Text(0).config(color="blue",
                                  anchor=TOPRIGHT,
                                  pos=(w - 4, 4),
                                  **font)

    # Create status text
    sk["Status"] = Text("Make a choice!").config(pos=(0.75 * w, h - 24),
                                                 font=Font.sans(),
                                                 fontSize=32,
                                                 color="red")
예제 #4
0
 def setup(self):
     self.caption = "sc8pr Video Converter"
     self.menu()
     attr = dict(anchor=BOTTOMRIGHT,
                 color="red",
                 bg="#a0a0a080",
                 font=Font.mono(),
                 fontSize=18)
     self["Text"] = Text().config(pos=(self.width - 4, self.height - 4),
                                  **attr)
예제 #5
0
 def setup(self):
     x, y = self.center
     attr = dict(font=Font.mono(),
                 fontSize=18,
                 fontStyle=BOLD,
                 weight=1,
                 padding=4,
                 border="#c0c0c0",
                 promptColor="#c0c0c0")
     self["Param"] = TextInput("", "fps w h x y").config(pos=(x + 16, y),
                                                         **attr)
     self["Record"] = self.recordButton(y)
     self.grab = None
예제 #6
0
def setup(sk):
    # Load image originals
    fldr = resolvePath("img", __file__)
    sk.imgs = [Image("{}/{}.png".format(fldr, f))
        for f in ("target", "paper", "scissors")]

    # Create button controls and add images to buttons
    w, h = sk.size
    x = w / 4 - 44
    for img in sk.imgs:
        btn = Button((40, 40), 2).config(anchor=BOTTOM, pos=(x, h-4))
        btn += Image(img).config(pos=btn.center, height=32)
        sk += btn.bind(onclick) # Bind event handlers
        x += 44

    # Initialize scores to zero
    font = {"font":Font.mono(), "fontSize":40, "fontStyle":BOLD}
    sk["Score1"] = Text(0).config(color="red", anchor=TOPLEFT, pos=(4, 4), **font)
    sk["Score2"] = Text(0).config(color="blue", anchor=TOPRIGHT, pos=(w-4, 4), **font)

    # Create status text
    sk["Status"] = Text("Make a choice!").config(pos=(0.75*w, h-24),
        font=Font.sans(), fontSize=32, color="red")
예제 #7
0
    from sc8pr.geom import vec2d, delta
    from sc8pr.gui.textinput import TextInput
    from sc8pr.gui.button import Button
    from sc8pr.misc.video import Video
except Exception as e:
    print(e)
    print("Try running 'pip3 install sc8pr' on command line")
    exit()
from pygame.constants import K_UP, K_DOWN, K_LEFT, K_RIGHT
import json
from time import time
from math import pow
from random import uniform, randint

JSON = "asterShield_scores.json"
FONT = Font.mono()


class Ship(Sprite):
    "The spaceship is controlled by the player using the keyboard"

    def reset(self, sk):
        "Configure to start game"
        return self.config(width=sk.width / 15,
                           fired=0,
                           hits=0,
                           pos=sk.center,
                           vel=(0, 0),
                           angle=270,
                           spin=0)
예제 #8
0
파일: soccer.py 프로젝트: dmaccarthy/sc8pr
        if brain is remote:
            self.bind(onkeydown=Robot.remoteControl).config(remoteRobot=robot)
        robot.bind(brain=brain)

    def start(self):
        "Robots take the field"
        yellow = SoccerRobot(["#ffd428", "#ff5050"])
        red = SoccerRobot(["#ff5050", "#ffd428"])
        self.bindBrain(red, self.brains[0])
        self.bindBrain(yellow, self.brains[1])
        x, y = self.center
        x += (2 * randint(0, 1) - 1) * 16
        self["Yellow"] = yellow.config(pos=(1.5 * x, y), width=y/4, angle=90)
        self["Red"] = red.config(pos=(0.5 * x, y), width=y/4, angle=270)

    ondraw = physics
    
    def goal(self, player):
        "Change the scoreboard"
        score = self.score[player]
        score.config(data=score.data+1)


def main(*brains, **kwargs):
    sk = SoccerGame((640,480)).config(font=kwargs.get("font"))
    if len(brains) == 1: sk.brains = [brains[0], followBall]
    elif len(brains) == 2: sk.brains = brains
    sk.play("Robot Soccer")

if __name__ == "__main__": main(font=Font.mono())
예제 #9
0
try:
    from sc8pr import Sketch, Canvas, Image, BOTTOM, TOPRIGHT, TOPLEFT
    from sc8pr.shape import QCircle, Line
    from sc8pr.text import Text, Font, BOLD
    from sc8pr.geom import delta
    from sc8pr.util import ondrag
    from sc8pr.misc.cursors import hand
    from sc8pr.gui.dialog import MessageBox
except Exception as e:
    print(e)
    print("Try running 'pip3 install sc8pr' on command line")
    exit()
from math import hypot, asin, degrees
from random import uniform

MONO = Font.mono()


class Simulation(Sketch):
    @property
    def scale(self):
        return 10 * self.width / 640

    def __init__(self):
        self.mass = uniform(1, 4)
        self.q1 = uniform(0.1, 0.4)
        self.q2 = uniform(0.1, 0.4)
        super().__init__((640, 256))

    def setup(self):
        self.caption = "Electric Force Simulation"
예제 #10
0
파일: soccer.py 프로젝트: swipswaps/sc8pr
        robot.bind(brain=brain)

    def start(self):
        "Robots take the field"
        yellow = SoccerRobot(["#ffd428", "#ff5050"])
        red = SoccerRobot(["#ff5050", "#ffd428"])
        self.bindBrain(red, self.brains[0])
        self.bindBrain(yellow, self.brains[1])
        x, y = self.center
        x += (2 * randint(0, 1) - 1) * 16
        self["Yellow"] = yellow.config(pos=(1.5 * x, y), width=y/4, angle=90)
        self["Red"] = red.config(pos=(0.5 * x, y), width=y/4, angle=270)

    ondraw = physics
    
    def goal(self, player):
        "Change the scoreboard"
        score = self.score[player]
        score.config(data=score.data+1)


def play(*brains, **kwargs):
    sk = SoccerGame((640,480)).config(font=kwargs.get("font"))
    if len(brains) == 1: sk.brains = [brains[0], followBall]
    elif len(brains) == 2: sk.brains = brains
    sk.play("Robot Soccer")

main = play

if __name__ == "__main__": play(font=Font.mono())
예제 #11
0
# along with "sc8pr".  If not, see <http://www.gnu.org/licenses/>.

"A simulation of the electric force (Coulomb's Law) between two spheres"

if __name__ == "__main__": import depends
from math import hypot, asin, degrees
from random import uniform
from sc8pr import Sketch, Canvas, Image, BOTTOM, TOPRIGHT, TOPLEFT
from sc8pr.shape import Circle, Line
from sc8pr.text import Text, Font, BOLD
from sc8pr.geom import delta
from sc8pr.util import ondrag
from sc8pr.misc.cursors import hand
from sc8pr.gui.dialog import MessageBox

MONO = Font.mono()

class Simulation(Sketch):

    @property
    def scale(self): return 10 * self.width / 640

    def __init__(self):
        self.mass = uniform(1, 4)
        self.q1 = uniform(0.1, 0.4)
        self.q2 = uniform(0.1, 0.4)
        super().__init__((640,256))

    def setup(self):
        self.caption = "Electric Force Simulation"
        w, h = self.size