コード例 #1
0
 def __init__(self):
     pygame.init()
     self.score = 0
     self.scoreText = pygame.font.Font("Minecraft.ttf", 30)
     self.timeText = pygame.font.Font("Minecraft.ttf", 30)
     self.width = 1000
     self.height = 700
     self.screen = pygame.display.set_mode((self.width, self.height))
     self.background = pygame.Surface(self.screen.get_size())
     self.background = self.background.convert()
     self.screen.fill((200,200,200)) # Values can be changed as needed. Example values
     self.bg = background.Background(self.screen, 0, 375)
     self.ship1Y = random.randint(340, 375)
     self.ship2Y = random.randint(375, 385)
     self.ship3Y = random.randint(385, 395)
     self.ship1 = ships.Ship(self.screen, 0, self.ship1Y)
     self.ship2 = ships.Ship(self.screen, -50, self.ship2Y)
     self.ship3 = ships.Ship(self.screen, -80, self.ship3Y) 
     self.scope = scope.Scope(self.screen)
     self.linev = scope.Scope(self.screen)
     self.lineh = scope.Scope(self.screen)
     self.P1 = (500, 700)
     self.dx = 0
     self.dy = 0
     self.torpedo = None
     self.ship1Speed = random.randint(1,3)
     self.ship2Speed = random.randint(1,3)
     self.ship3Speed = random.randint(1,3)
     self.explosionLocX = None
     self.explosionLocY = None
     self.explosion = None
     self.LENGTHOFGAME = 90
     self.time = 90
     self.boVoiceCounter = 0
     self.explodeSound = pygame.mixer.Sound("explode.wav")
     self.torpedoSound = pygame.mixer.Sound("torpedoMove.wav")
     self.voiceSink = pygame.mixer.Sound("ShipDestroyed1.wav")
     #self.voiceShoot = pygame.mixer.Sound("")
     self.voicePowerPlus = pygame.mixer.Sound("HavePower.wav")
     self.voicePowerGone = pygame.mixer.Sound("NoPower.wav")
     #self.voiceTorp = pygame.mixer.Sound("Torpedo1.wav")
     self.cooldown = 300
     self.voiceCounter = 0
     self.voiceTorpedo = pygame.mixer.Sound("firingTorpedo.wav")
     self.channel1 = pygame.mixer.Channel(0)
     self.channel2 = pygame.mixer.Channel(1)
     self.channel3 = pygame.mixer.Channel(2)
     self.channel4 = pygame.mixer.Channel(3)
     self.channel5 = pygame.mixer.Channel(4)
コード例 #2
0
ファイル: context.py プロジェクト: frapa/gala
    def __init__(self, parent_ctx=None):
        self.parent_ctx = parent_ctx

        self.data = dict(parent_ctx.data) if parent_ctx is not None else {}

        if parent_ctx is None:
            self.scope = scope.Scope()
        else:
            self.scope = parent_ctx.get_scope()
コード例 #3
0
ファイル: function.py プロジェクト: scttnlsn/daffy
 def __call__(self, scope, cells):
     values = map(lambda x: x.eval(scope), cells)
     if callable(self.body):
         return self.body(*values)
     else:
         import scope
         inner = scope.Scope(self.scope)
         for i, param in enumerate(self.params):
             inner[param] = values[i]
         return map(lambda x: x.eval(inner), self.body)[-1]
コード例 #4
0
    def apply(self, *args):
        s = scope.Scope(self.scope)

        if not isinstance(args, list):
            args = [args]

        if not len(*args) == len(self.params):
            raise Exception("Func called with mismatched args and params")

        for p in zip(self.params, *args):
            s.bind(p[0], p[1])

        return self.expr_lambda(s)
コード例 #5
0
def confirm_align(star):
    result = tkMessageBox.askyesno("Align Telescope", "Are you sure?")
    if result is True:
        # Check if encoders are available
        try:
            ra = enc.Enc('RAEncoder')
            dec = enc.Enc('DECEncoder')
        except:
            log_action('ALIGN', 'Scope', 'Encoder(s) not found')
        else:
            # Initialize encoders
            ra = enc.Enc('RAEncoder')
            success = ra.connect()
            if not success:
                log_action('Connect', 'Encoder',
                           'RAEncoder failed to initialize')
            dec = enc.Enc('DECEncoder')
            success = dec.connect()
            if not success:
                log_action('Connect', 'Encoder',
                           'DECEncoder failed to initialize')

            # Look up the star
            try:
                ephem.star(star)  # Check if 'name' is a named star
            except KeyError:
                obj = read_db(
                    star
                )  # If not, read 'name' from the custom objects database (Weird to do but w/e)
            else:
                obj = ephem.star(star)  # But if it was a star...
            obj.compute(rho)
            # Create Scope object
            scope = sc.Scope(obj, ra, dec)
            position = scope.where()  # Grab scope position to confirm align
            st = rho.sidereal_time()  # Grab RHO sidereal time
            ha = '%s' % ephem.hours(
                st - ephem.hours(position[0]))  # Calc HA of object from RHO
            s_ha.set(ha)
            s_dec.set(str(position[1]))
            s_tick_ha.set(scope.data['Ticks'][-1][0])
            s_tick_dec.set(scope.data['Ticks'][-1][1])
            log_action('Align Success', obj.name,
                       str('HA: ' + position[0] + ' | DEC: ' + position[1]))
            s_ready.set('Telescope Aligned')
            s_scope.config(fg='black')
    else:
        # Do nothing
        return
コード例 #6
0
import numpy as np
import matplotlib.pyplot as plt
import scope

myscope = scope.Scope("COM7", baudrate=9600, debug=False)
#myscope=scope.Scope(u'GPIB0::1::INSTR',debug=True)

#reading 1 channel
#x, data1 = myscope.readScope("CH1")
#reading 2 channels
x, data1, data2 = myscope.readScope("CH1CH2")

plt.plot(x, data1, "r-")
plt.plot(x, data2, "g-")

plt.show()
コード例 #7
0
ファイル: context.py プロジェクト: frapa/gala
 def sub_scope(self):
     self.scope = scope.Scope(self.scope)
コード例 #8
0
#sc is scope
if args.noscope:
    sc = scope.NoScope()
else:
    #i_sc is inscope
    if args.scope is not None:
        i_sc = args.scope  #takes filename or list
    else:
        #if theres no in scope just use the list of domain names
        i_sc = []
        for url in urls:
            #split off http[s]:// and anything after a /
            i_sc.append(url.split("://")[1].split("/")[0])
    if args.outscope is not None:
        sc = scope.Scope(i_sc, args.outscope)
    else:
        sc = scope.Scope(i_sc)

wl = Wordlist(args.regex)

sp = spider.Spider(*urls,
                   scope=sc,
                   max_depth=args.max_depth,
                   threads=args.threads,
                   wordlist=wl,
                   verbose=args.verbose)
sp.run()

if args.write:
    with open(args.write, "w") as f:
コード例 #9
0
ファイル: example.py プロジェクト: philippre/pyScopeTools
import numpy as np
import matplotlib.pyplot as plt
import scope

myscope = scope.Scope("COM1", debug=False)

x, data = myscope.readScope()

plt.plot(x, data)
plt.show()
コード例 #10
0
def main():
    # Serial port communication: look this up in 'device manager'
    port = 'COM6'  # Serial port

    # Basic info about the target cipher
    #As the key is hard-coded in the encryption device, no need to take care of the key
    plain_len = 16  # byte length of the plaintext
    cipher_len = 16  # byte length of the ciphertext

    # Acquisition setup: find this setting through the capturing traces from the setup program
    num_of_traces = 1000000  # number of traces
    num_of_samples = 100000  # number of samples
    sample_rate = 500E6  # Sample Rate
    isshort = False  # Type of the samples: short or float
    vdiv = 42.5E-3  # Vertical resolution: V/div
    trg_delay = "-80.4US"  # Trigger delay: negative means post trigger (S)
    trg_level = "1V"  # Trigger level: start capture when trigger passes it
    isenc = True  # Perform encryption/decryption
    voffset = "-30 mV"  # Vertical Offset
    repeat = 1
    # File name for the trace set file
    # For convenience, please add necessary information to the file name
    filename = 'F://Traces//JoeyAES_{}T_{}S_repeat{}.trs'.format(
        num_of_traces, num_of_samples, repeat)
    # Name of the TRS trace set file

    # In most common cases, you do not have to change anything below this line
    # Compute the setup parameters from above
    xscale = 1 / sample_rate  # sampling interval (s)
    duration = xscale * num_of_samples  # sample duration (s)
    # For short type of acquisition, the captured trace is scaled in order to store in a 16 bit integer
    # yscale saves the scale value, in case you need to reconstruct the real traces
    # For float type of acquisition, the samples are exactly the real samples on the trace, so yscale=1
    if (isshort):
        yscale = vdiv / (65536 / 10.0)
    else:
        yscale = 1
    timebase = str(xscale * num_of_samples / 10) + "S"  # timebase: s/div

    #Intiliazed random generator
    random.seed()
    #Open serial port
    ser = serial.Serial(port)
    #Open scope
    oscope = scope.Scope()
    # setup the scope
    oscope.setup(
        str(vdiv) + "V", timebase,
        str(sample_rate / 1E6) + "MS/s",
        str(duration) + "S", voffset)
    # set trigger
    oscope.set_trigger(trg_delay, trg_level)

    #Open Trace Set
    trs = TRS_TraceSet.TRS_TraceSet(filename)
    trs.write_header(num_of_traces, num_of_samples, isshort,
                     plain_len + cipher_len, xscale, yscale)

    # Start acquisition
    for i in range(0, num_of_traces):
        # Generate random plaintext
        plaintext = bytearray(
            [random.getrandbits(8) for j in range(0, plain_len)])
        if (isshort):
            trace = np.zeros(num_of_samples, dtype=np.uint16)
        else:
            trace = np.zeros(num_of_samples, dtype=np.float)
        for j in range(0, repeat):
            # start trigger
            if (oscope.start_trigger() == False):
                print("Triggering Error!")
                return
            # Send plaintext to the device
            ser.write(plaintext)
            # Read out ciphertext.
            ciphertext = bytearray(ser.read(cipher_len))
            # Get trace: if Lecroy has not stopped yet, discard this trace
            if (oscope.wait_for_trigger() == False):
                j = j - 1
                continue
            trc = oscope.get_channel(num_of_samples, isshort, 'C1')
            trace = trace + trc
        trace = trace / repeat
        # Storing plaintext/ciphertext/trace
        trs.write_trace(plaintext, ciphertext, trace, isenc)
        # Print data
        if i % 100 == 0:
            print("i=" + str(i))
            print("plain=")
            PrintHexData(plaintext)
            print("cipher=")
            PrintHexData(ciphertext)
        else:
            pass
    # Close the serial port
    ser.close()
    # Close TRS file
    trs.close()
    return
コード例 #11
0
 def open_scope(self):
     self.scope = scope.Scope(self, self.scope)
コード例 #12
0
 def create_new(self, parser):
     opt = Optimizer(errors=self.errors, parser=parser)
     opt.scope = scope.Scope(opt, self.scope)
     return opt
コード例 #13
0
    lex.TokenType(">", r'^\>'),
    lex.TokenType("<", r'^\<'),
    lex.TokenType("<=", r'^\<\='),
    lex.TokenType(">=", r'^\>\='),
]

with open(sys.argv[1]) as code:

    lexer = lex.Lexer(types)

    tokens = lexer.tokenize(code.read())

    parser = parse.Parser(tokens)
    ast = parser.parse()

    sc = scope.Scope()
    sc.bind("print",
            value.ParamsBuiltinFunctionObject(lambda text: print(str(text))))
    sc.bind(
        "input",
        value.NoParamsBuiltinFunctionObject(
            lambda: value.StringObject(input())))
    sc.bind(
        "int",
        value.ParamsBuiltinFunctionObject(
            lambda s: value.IntObject(int(s.value))))
    sc.bind(
        "string",
        value.ParamsBuiltinFunctionObject(
            lambda i: value.StringObject(str(i.value))))
コード例 #14
0
    def runGame(self):
        pygame.key.set_repeat(500, 30) # Values can be changed as needed. Example values

        startGameTime = time.time()
        self.last = pygame.time.get_ticks()
        rand_blackoutSt = random.randint(5, 8)
        rand_blackoutEnd = random.randint(9, 12)
        blackout2st = random.randint(25, 28)
        blackout2End = random.randint(29, 33)
        blackVocCounter = 0
        blackOut3 = random.randint(50, 52)
        blackout3st = 51
        blackout3End = random.randint(54, 56)
        #print(blackout3)
        while 1:
            for event in pygame.event.get(): # Handles figuring out even 
                if event.type == pygame.QUIT:
                    sys.exit()
            pygame.display.update()
            #seconds = pygame.time.get_ticks()//1000
            self.screen.fill((200,200,200)) # Values can be changed as needed. Example values
            self.time = 90
            self.bg.drawSea()
            self.bg.drawSky()
            self.ship1.draw()
            self.ship2.draw()
            self.ship3.draw()
            secondsPassed = time.time() - startGameTime
            #1st and 2nd Blackout
            if time.time() - startGameTime >= rand_blackoutSt and time.time() - startGameTime <= rand_blackoutEnd or time.time() - startGameTime >= blackout2st and time.time() - startGameTime <= blackout2End:
                if self.voiceCounter == 0:
                    self.channel3.play(self.voicePowerGone, 0)
                if int(time.time()) - int(startGameTime) == int(rand_blackoutEnd) and self.boVoiceCounter == 0:
                    self.channel5.play(self.voicePowerPlus, 0)
                    self.boVoiceCounter += 1
                    print("blackout over")
                startTime = int(time.time())
                endTime = startTime + 10
                while not startTime == endTime:
                    self.screen.fill((0,0,0))
                    startTime += 1
                    self.voiceCounter += 1
            #3rd blackout
            if time.time() - startGameTime >= blackOut3 and time.time() - startGameTime <= blackout3End and blackOut3 == 51:
                if self.voiceCounter == 0:
                    self.channel3.play(self.voicePowerGone, 0)
                if int(time.time()) - int(startGameTime) == int(rand_blackoutEnd) and self.boVoiceCounter == 0:
                    self.channel5.play(self.voicePowerPlus, 0)
                    self.boVoiceCounter += 1
                    print("blackout over")
                startTime = int(time.time())
                endTime = startTime + 10
                while not startTime == endTime:
                    self.screen.fill((0,0,0))
                    startTime += 1
                    self.voiceCounter += 1
            print(pygame.time.get_ticks())
            #if time.time()*1000%1000 ==0:
                #self.time -= 1
            self.scope.move()
            self.moveShips()
            self.screenWrap()
                   

            if time.time() - startGameTime >= self.LENGTHOFGAME and self.torpedo == None:
                pygame.mixer.music.stop()
                pygame.mixer.music.load("menu_bgm.wav")
                pygame.mixer.music.play(-1, 0.0)
                go = gameover.GameOver(self.score)
                g = go.runGameOver()
                if g:
                    return
                else:
                    pygame.init()
                    # re-setup the class game to play the  game
                    self.score = 0
                    self.scoreText = pygame.font.Font("Minecraft.ttf", 30)
                    self.width = 1000
                    self.height = 700
                    self.screen = pygame.display.set_mode((self.width, self.height))
                    self.background = pygame.Surface(self.screen.get_size())
                    self.background = self.background.convert()
                    self.screen.fill((200,200,200)) # Values can be changed as needed. Example values
                    self.bg = background.Background(self.screen, 0, 375)
                    self.ship1Y = random.randint(340, 375)
                    self.ship2Y = random.randint(350, 385)
                    self.ship3Y = random.randint(360, 395)
                    self.ship1 = ships.Ship(self.screen, 0, self.ship1Y)
                    self.ship2 = ships.Ship(self.screen, -200, self.ship2Y)
                    self.ship3 = ships.Ship(self.screen, -400, self.ship3Y) 
                    self.scope = scope.Scope(self.screen)
                    self.linev = scope.Scope(self.screen)
                    self.lineh = scope.Scope(self.screen)
                    self.P1 = (500, 700)
                    self.dx = 0
                    self.dy = 0
                    self.torpedo = None
                    self.ship1Speed = random.randint(1,3)
                    self.ship2Speed = random.randint(1,3)
                    self.ship3Speed = random.randint(1,3)
                    self.explosionLocX = None
                    self.explosionLocY = None
                    self.explosion = None
                    startGameTime = time.time()


            
            key = pygame.key.get_pressed()
            # Catching the ZeroDivisionError using an exception
            self.now = pygame.time.get_ticks()
            try:
                if key[pygame.K_SPACE]:
                    print(self.calculateSlope())
                    #self.torpedoSound.play()
                    if time.time() - startGameTime <= self.LENGTHOFGAME:
                        self.torpedo = torpedo.Torpedo(self.screen, self.dx, self.dy)
                        self.channel1.play(self.torpedoSound, 0)
                        self.channel4.play(self.voiceTorpedo, 0)
                        #self.channel2.play(self.voiceTorp, 0)
                        self.torpedoSound.set_volume(1.0)
            except ZeroDivisionError:
                if time.time() - startGameTime <= self.LENGTHOFGAME:
                    self.torpedo = torpedo.Torpedo(self.screen, self.dx, self.dy)
                    self.torpedo.move()
                    self.channel1.play(self.torpedoSound, 0)
                    #self.channel2.play(self.voiceTorp, 0)
                    self.torpedoSound.set_volume(1.0)
                    pass
            if not self.torpedo == None:
                oldVolume = self.torpedoSound.get_volume()
                self.torpedoSound.set_volume(oldVolume - .005)
                self.torpedo.move()
                if self.collision() or self.torpedo.rect.top < 440:
                    self.collisionShip1()
                    self.collisionShip2()
                    self.collisionShip3()
                    del(self.torpedo)
                    self.torpedoSound.stop()
                    time.sleep(.03)
                    self.torpedo = None
                #if self.torpedo.rect.top < 420:
                    #print("="*15)
                    #del(self.torpedo)
                    #self.torpedo = None
            self.updateScore()
            self.time = self.time - secondsPassed
            self.time = int(self.time)
            #if time.time() - startGameTime <= self.LENGTHOFGAME:
            if time.time() - startGameTime >= self.LENGTHOFGAME:
                self.screen.blit(self.textDis,(830, 35))
            else:
                self.updateTime()
コード例 #15
0
import accelerometer_MPU6050
import scope
import time, utime


def print_data(item):
    print("Data: {0:.3f} {1:.3f} {2:.3f} {3:.3f} {4:.3f} {5:.3f} {6:.3f} {7:d}".\
          format(item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7]))


if __name__ == "__main__":
    actuator = solenoid.Solenoid(pyb.Pin.board.PA8)
    accel = accelerometer_MPU6050.Accelerometer(pyb.Pin.board.PB8,\
        pyb.Pin.board.PB9)
    tim = pyb.Timer(2)
    oscope = scope.Scope(pyb.Pin.board.PA0, pyb.Pin.board.PC1,
                         pyb.Pin.board.PC0)
    while (True):
        cycles = input()
        frequency = input()
        period = 1000.0 / (float(frequency) * 2.0)
        #oscope.set_timer(tim)
        for i in range(0, int(cycles)):
            end_time = utime.ticks_ms() + period
            count = 0
            actuator.start()

            while utime.ticks_ms() < end_time:
                if count < 100:
                    print_data(accel.read_data())
                count += 1
            end_time = utime.ticks_ms() + period
コード例 #16
0
python quickScope.py COM1
"""

import scope
import sys
import numpy as np
import matplotlib.pyplot as plt
import time

args = sys.argv[1:]
port = "COM1"
if len(args) > 0:
    port = args[0]
print("Reading scope using: " + port)

sc = scope.Scope(port, baudrate=9600)
time.sleep(0.5)

#x, y1, y2 = sc.readScope("CH1Ch2")
result = sc.readScope("CH1Ch2")
x = result[0]
y1 = result[1]
y2 = None
if len(result) == 3 and result[2] is not None:
    y2 = result[2]

dataname = time.strftime("%x").replace('/',
                                       '-') + "_" + time.strftime("%H-%M-%S")

data1 = np.vstack((x, y1)).T
np.savetxt("./" + dataname + "_CH1.txt", data1)