Пример #1
0
def explosion():
        global config

        if(config.useMassager == True) : 
                messenger.soliloquy(True)

        #image = Image.new("RGBA", (32, 32))
        #draw  = ImageDraw.Draw(image)

        ## Uses the same "global" image to draw to
        image = config.image
        #config.matrix.SetImage(image.im.id, 0,0)
        particles = []
        # Traces / no traces
        traces = False
        if(random.random() > .98) : traces = True
        # Number of sparks
        p = int(50 + (random.uniform(10,90)))
        angle = 2 * math.pi/p

        # initial center position
        x = int(random.random()*config.screenWidth)
        y = int(random.random()*16)

        brightness = config.brightness
        sparkleBrightness = config.brightness
        brightness = .9
        sparkleBrightness = .8

        for n in range (0, p) :
                # variation in initial velocity
                f = random.random() * 4
                vx = math.cos(angle * n) * f
                vy = math.sin(angle * n) * f
                r = int(random.uniform(0,255)* brightness)
                g = int(random.uniform(0,255)* brightness)
                b = int(random.uniform(0,255)* brightness)
                particles.append({'id':n,'xpos':x,'ypos':y,'vx':vx,'vy':vy, 'c':[r,g,b]})

        for i in range (0,50) :
                if(traces == False) : config.matrix.Clear()
                #config.matrix.SetImage(config.image.im.id, 0,0)
                if(random.random() > .98) : traces = True
                decr = 20
                decr = int(random.uniform(1,15))        

                for q in range (0, p) :
                        ref = particles[q]
                        ref['xpos'] = ref['vx'] + ref['xpos']
                        ref['ypos'] = ref['vy'] + ref['ypos']

                        # deacelleration
                        ref['vy'] = ref['vy']* .9
                        ref['vx'] = ref['vx']* .9

                        # pseudo gravity
                        ref['vy'] = ref['vy'] + .1

                        particles[q]['c'][0] = particles[q]['c'][0] - decr
                        particles[q]['c'][1] = particles[q]['c'][1] - decr
                        particles[q]['c'][2] = particles[q]['c'][2] - decr

                        if(particles[q]['c'][0] <= 0) : particles[q]['c'][0] = 0
                        if(particles[q]['c'][1] <= 0) : particles[q]['c'][1] = 0
                        if(particles[q]['c'][2] <= 0) : particles[q]['c'][2] = 0

                        r = particles[q]['c'][0]
                        g = particles[q]['c'][1]
                        b = particles[q]['c'][2]

                        # Sparkles!!
                        if(random.random() > .9) :
                                r = int(220 * sparkleBrightness)
                                g = int(220 * sparkleBrightness)
                                b = int(255 * sparkleBrightness)

                        #if (q ==0) : print (particles[q]['c'][0])
                        xDisplayPos = ref['xpos']
                        yDisplayPos = ref['ypos']

                        if(xDisplayPos > config.screenWidth) :
                                xDisplayPos += config.screenWidth

                        if(yDisplayPos > 32 and yDisplayPos <64) :
                                yDisplayPos -=32
                                xDisplayPos += config.screenWidth
                        if(yDisplayPos > 64) :
                                yDisplayPos -=64
                                xDisplayPos += config.screenWidth*2

                        config.matrix.SetPixel(int(xDisplayPos),int(yDisplayPos),r,g,b)
                        
                time.sleep(0.015)
        if(random.random() > .8) : explosion()
Пример #2
0
def soliloquy(override = False,arg = "") :
	global useMassager
	if (useMassager) : messenger.soliloquy(override,arg)