def __init__(self, verbose=False):
     self._objectName = "CONTROLLER"
     self._objectLevel = 1
     self._verbose = verbose
     self.bucket = Bucket()
     self.watermark = Watermark()
     self.options = Options()
     self.engine = Engine()
     self.iomanager = IOManager()
class EngineTest(BaseTest):
    def setUp(self):
        self.init()
        self.engine = Engine(self.fake_input, self.fake_print)

    def test_engine_enters_main_loop(self):
        try:
            self.say("Q")
            self.engine.main_loop()
        except AttributeError:
            self.fail("Engine does not have a main_loop() method")

    def test_engine_will_prompt_and_exit_with_q(self):
        self.say("Q")
        self.engine.main_loop()
        self.assertIn(prompt, ">")
        self.assertPrinted(prompt, 0)

    def test_engine_commands_are_not_case_sensitive(self):
        self.say("q")
        self.engine.main_loop()
        self.assertIn(prompt, ">")
        self.assertPrinted(prompt, 0)

    def test_help_will_be_printed_when_asked_for(self):
        self.say("help")
        self.say("q")
        self.engine.main_loop()
        self.assertPrinted("help", 1)
class CanLoopTheMainLoop(BaseTest):
    def setUp(self):
        self.init()
        self.engine = Engine(self.fake_input, self.fake_print)
    
    def test_fred_can_start_and_stop_the_loop_with_ease(self):
        # Fred is an avid gamer, some would say that he is a compulsive gamer
        # It has gotten so bad that he games in the middle of the night, when he should be sleeping
        # He games in the day at work.
        # Sometimes he games when he should be mowing the lawn.
        # Today Fred is trying a new CodeNewbie text adventure game he found, he starts it up
        # As soon as he gets the prompt of the main loop his boss walks by
        # In a panic Fred presses "Q" to quit.
        self.say("Q")
        self.engine.main_loop()
        
        # The text adventure ends 
        self.assertPrinted(">", 0)

    def test_fred_can_stop_the_loop_with_lower_case_q(self):
        # Fred when closing the game as quickly as possible doesn't have time to press shift 
        # He sends a lower case 'q' instead
        # The game closes anyway
        self.say("q")
        self.engine.main_loop()
        
        # The text adventure ends 
        self.assertPrinted(">", 0)

    def test_jaime_can_get_help(self):
        # Jamie has heard from Fred that this new Python powered CodeNewbie text adventure game
        # is not only the cause of his loss of job and sleep, but is also relitively easy for
        # beginners to enjoy because the help functionality is so easy to use.  All she needs to
        # do to check the help is start the main loop.
        # Type 'help' and press enter.
        self.say("help")
        self.say("q")
        self.engine.main_loop()

        # A list of commands will display
        # Jamie can then quit the game and tell her friends all the ease of use.
        self.assertPrinted("help", 1)
class Controller:
    def __init__(self, verbose=False):
        self._objectName = "CONTROLLER"
        self._objectLevel = 1
        self._verbose = verbose
        self.bucket = Bucket()
        self.watermark = Watermark()
        self.options = Options()
        self.engine = Engine()
        self.iomanager = IOManager()

    # LOADING ################################################################################

    def bucketIsReady(self):
        return (self.bucket.isFilled)

    def watermarkIsReady(self):
        return (self.watermark.isSelected)

    def fillBucket(self):
        self.bucket.fill()
        if self.bucket.isFilled:
            return (True)
        else:
            return (False)

    def loadWatermark(self):
        wmp = self.iomanager.askWatermarkPath()
        self.watermark.setPath(wmp)
        if self.watermark.isSelected:
            self.watermark.load()
            return (True)
        else:
            return (False)

    def resetWatermark(self):
        self.watermark.reset()

    # OPTIONS SETTING ########################################################################

    def setWatermarkDestinationBrightness(self, brightness):
        self.options.setWatermarkDestinationBrightness(brightness)

    def setWatermarkDestinationOffsetPercentage(self, offsetPerc):
        self.options.setWatermarkDestinationOffsetPercentage(offsetPerc)

    def setWatermarkDestinationSizePercentage(self, sizePerc):
        self.options.setWatermarkDestinationSizePercentage(sizePerc)

    def setOutputPrefix(self, outputPrefix):
        self.options.setOutputPrefix(outputPrefix)

    def setOutputSuffix(self, outputSuffix):
        self.options.setOutputSuffix(outputSuffix)

    def setOutputFolder(self):
        outputFolder = self.iomanager.askOutputFolder()
        self.options.setOutputFolder(outputFolder)

    def resetOutputFolder(self):
        cwd = self.iomanager.resetOutputFolder()
        self.options.setOutputFolder(cwd)

    # GET THE JOB DONE ######################################################################

    def process(self):
        watermark = self.watermark
        bucket = self.bucket
        options = self.options
        self.engine.parallelMerge(bucket, watermark, options)

    def serialProcess(self):
        watermark = self.watermark
        bucket = self.bucket
        options = self.options
        self.engine.serialMerge(bucket, watermark, options)

    # LOGGER ################################################################################

    def _logger(self, message):
        if self._verbose == True:
            now = time.strftime("%H:%M:%S", time.localtime())
            message = "%s [%s]: %s" % (now, self._objectName, message)
            print(message)
 def setUp(self):
     self.init()
     self.engine = Engine(self.fake_input, self.fake_print)
 def test_can_get_output_from_stdout_and_input_to_stdin(self):
     self.say("Hero")
     engine = Engine(self.fake_input, self.fake_print)
     engine.greet()
     self.assertEqual("Hello, what is your name: ", self.printed[0])
     self.assertEqual("Welcome to text adventure, Hero!", self.printed[1])
 def get_engine(self):
     return Engine(self.library_path(), self.fake_input, self.fake_print)
# main game loop goes here
from modules.engine import Engine
from os import getcwd
from os.path import join

"""
This script launches the game:

> python game.py
"""
library_path = join(getcwd(), "resources")
flux_capacitor = Engine(library_path)
flux_capacitor.main_loop()
Beispiel #9
0
from modules.vector import Point
from modules.color import Color
from modules.blackhole import BlackHole
from modules.disk import Disk
from modules.camera import Camera
from modules.scene import Scene
from modules.engine import Engine

c_origin = Point(0, 0.7, -9.0)
c_focus = Point(0, 0, 0.0)

bh = BlackHole(c_focus, 80)

# You can specify a texture file for the accretion disk with `texture='filename.png'` or a color by `color=Color('#ffffff') (default)`
disk = Disk(c_focus, 4.5*bh.radius, 16.2*bh.radius)

scene = Scene(
	width = 500,
	height = 250,
	camera = Camera(c_origin, c_focus-c_origin, 1.2),
	blackhole = bh,
	disk = disk
)

engine = Engine(scene)
engine.render()

engine.save('images/blackhole.png')
Beispiel #10
0
from modules.objects import Sphere
from modules.scene import Scene
from modules.engine import Engine
from PIL import Image

camera = Point(0, 0, -1)

lights = [
    Light(Point(-5, -15, -2), Color('#ffffff'), 1.0),
]

objects = [
    Sphere(Point(0, 104, 35), 100, Material(Color('#ffffff'), specular=0.5)),
    Sphere(Point(-4.5, 1, 10), 3, Material(Color('#880000'), specular=0.6)),
    Sphere(Point(0, -4, 18), 5, Material(Color('#008800'), specular=0.6)),
    Sphere(Point(4.5, 1, 10), 3, Material(Color('#000088'), specular=0.6)),
]

scene = Scene(camera=camera,
              lights=lights,
              objects=objects,
              width=800,
              height=600)

engine = Engine(scene, reflection_depth=5)
engine.render()

pixels = scene.image.pixels
image = Image.fromarray(pixels.astype(np.uint8))

image.save('output.png')
from google import search
from sys import argv

from modules.engine import Engine

if len(argv) == 3:

    file_name = argv[1]
    keys = argv[2]

    print('\n %s \n %s \n %s \n %s \n %s\n\n' %
          ('############################################################',
           '##### Email Grabber Start ! #####', 'Output file: ' + file_name,
           'Keys: ' + keys,
           '############################################################'))

    for url in search(keys, stop=None):
        print("URL: %s" % url)
        Engine.start(file_name, url)

else:
    print('\n %s \n %s \n %s \n\n %s \n %s\n\n' %
          ('############################################################',
           '##### HOW TO USE #####',
           'python3 email_grabber.py output.txt "keys to search"',
           'To long searchs, google will block you.',
           '############################################################'))

    quit()
# main game loop goes here
from modules.engine import Engine

flux_capacitor = Engine()
flux_capacitor.start()
Beispiel #13
0
# main game loop goes here
from modules.engine import Engine
from os import getcwd
from os.path import join
"""
This script launches the game:

> python game.py
"""
library_path = join(getcwd(), "resources")
flux_capacitor = Engine(library_path)
flux_capacitor.main_loop()