示例#1
0
文件: oxo.py 项目: MattChu/pycubedemo
 def draw_cursor(pos):
     (x, y, z) = pos
     base = color_lut[self.grid[x, y, z]]
     x *= 2
     y *= 2
     z *= 2
     color = cubehelper.mix_color(base, WHITE, 1.0 - self.ccount)
     (i, j) = self.coffset
     self.cube.set_pixel((x+i,y+j,z), color)
     self.cube.set_pixel((x+1-i,y+1-j,z+1), color)
     color = cubehelper.mix_color(base, WHITE, self.ccount)
     (i, j) = self.cnext
     self.cube.set_pixel((x+i,y+j,z), color)
     self.cube.set_pixel((x+1-i,y+1-j,z+1), color)
示例#2
0
 def draw_cursor(pos):
     (x, y, z) = pos
     base = color_lut[self.grid[x, y, z]]
     x *= 2
     y *= 2
     z *= 2
     color = cubehelper.mix_color(base, WHITE, 1.0 - self.ccount)
     (i, j) = self.coffset
     self.cube.set_pixel((x + i, y + j, z), color)
     self.cube.set_pixel((x + 1 - i, y + 1 - j, z + 1), color)
     color = cubehelper.mix_color(base, WHITE, self.ccount)
     (i, j) = self.cnext
     self.cube.set_pixel((x + i, y + j, z), color)
     self.cube.set_pixel((x + 1 - i, y + 1 - j, z + 1), color)
示例#3
0
 def tick(self):
     color = cubehelper.mix_color((0.0,0.0,0.0), self.color, self.level)
     for y in range(0, self.cube.size):
         for z in range(0, self.cube.size):
             for x in range(0, self.cube.size):
                 self.cube.set_pixel((x, y, z), color)
     self.level += self.delta
     if self.level >= 1.0:
         self.delta = -self.delta
     if self.level <= 0:
         raise StopIteration
示例#4
0
 def tick(self):
     color = cubehelper.mix_color((0.0, 0.0, 0.0), self.color, self.level)
     for y in range(0, self.cube.size):
         for z in range(0, self.cube.size):
             for x in range(0, self.cube.size):
                 self.cube.set_pixel((x, y, z), color)
     self.level += self.delta
     if self.level >= 1.0:
         self.delta = -self.delta
         self.level = 1.0
     if self.level <= 0.0:
         self.delta = -self.delta
         self.level = 0.0
         self.color = cubehelper.random_color()
         raise StopIteration
示例#5
0
 def tick(self):
     self.cube.clear()
     sz = self.cube.size
     y = 0.5
     step = self.offset
     if self.delta > 0:
         cfrac = self.offset
     else:
         cfrac = 2.0 - self.offset
     color = cubehelper.mix_color(self.color, self.next_color, cfrac/2.0)
     cubepos = [0]*3
     for x in range(0, sz):
         if self.mirror0:
             val = (sz - 1) - x
         else:
             val = x
         cubepos[self.axis0] = val
         val = int(y)
         if self.mirror1:
             val = (sz - 1) - val
         cubepos[self.axis1] = val
         for z in range(0, sz):
             cubepos[self.axis2] = z
             self.cube.set_pixel(cubepos, color)
         y += step
     self.offset += self.delta
     if self.offset >= 1.0:
         self.offset = 2.0 - self.offset
         self.delta = -self.delta
         tmp = self.axis0
         self.axis0 = self.axis1
         self.axis1 = tmp
         tmp = self.mirror0
         self.mirror0 = self.mirror1
         self.mirror1 = tmp
     if self.offset < 0.0:
         self.offset = -self.offset
         self.delta = -self.delta
         self.color = self.next_color
         self.next_color = self.pick_color()
         n = random.randrange(3)
         if n > 0:
             tmp = self.axis0
             self.axis0 = self.axis2
             self.axis2 = tmp
         if n < 2:
             self.mirror0 = not self.mirror0
         raise StopIteration
示例#6
0
 def tick(self):
     self.cube.clear()
     sz = self.cube.size
     y = 0.5
     step = self.offset
     if self.delta > 0:
         cfrac = self.offset
     else:
         cfrac = 2.0 - self.offset
     color = cubehelper.mix_color(self.color, self.next_color, cfrac/2.0)
     cubepos = [0]*3
     for x in range(0, sz):
         if self.mirror0:
             val = (sz - 1) - x
         else:
             val = x
         cubepos[self.axis0] = val
         val = int(y)
         if self.mirror1:
             val = (sz - 1) - val
         cubepos[self.axis1] = val
         for z in range(0, sz):
             cubepos[self.axis2] = z
             self.cube.set_pixel(cubepos, color)
         y += step
     self.offset += self.delta
     if self.offset >= 1.0:
         self.offset = 2.0 - self.offset
         self.delta = -self.delta
         tmp = self.axis0
         self.axis0 = self.axis1
         self.axis1 = tmp
         tmp = self.mirror0
         self.mirror0 = self.mirror1
         self.mirror1 = tmp
     if self.offset < 0.0:
         self.offset = -self.offset
         self.delta = -self.delta
         self.color = self.next_color
         self.next_color = self.pick_color()
         n = random.randrange(3)
         if n > 0:
             tmp = self.axis0
             self.axis0 = self.axis2
             self.axis2 = tmp
         if n < 2:
             self.mirror0 = not self.mirror0
         raise StopIteration
示例#7
0
    def tick(self):
        self.cube.clear()
        color = cubehelper.mix_color(
            self.prevColor, self.color,
            (math.sin(self.sinwidth * self.iter) + 1) / 2)
        ran = random.randrange(100)

        for x in range(0, self.cube.size):
            for y in range(0, self.cube.size):
                z = math.floor(
                    math.sin(self.sinwidth * (self.iter + (x + y))) * 3.2 + 4)
                self.cube.set_pixel((x, y, int(z)), rainbow(self.iter + x, 10))

        self.iter += self.delta
        if (math.sin(self.sinwidth * self.iter) + 1) / 2 < 0.1:
            self.prevColor = self.color
            self.color = cubehelper.random_color()
示例#8
0
    def tick(self):
        def draw_cursor(pos):
            (x, y, z) = pos
            base = color_lut[self.grid[x, y, z]]
            x *= 2
            y *= 2
            z *= 2
            color = cubehelper.mix_color(base, WHITE, 1.0 - self.ccount)
            (i, j) = self.coffset
            self.cube.set_pixel((x + i, y + j, z), color)
            self.cube.set_pixel((x + 1 - i, y + 1 - j, z + 1), color)
            color = cubehelper.mix_color(base, WHITE, self.ccount)
            (i, j) = self.cnext
            self.cube.set_pixel((x + i, y + j, z), color)
            self.cube.set_pixel((x + 1 - i, y + 1 - j, z + 1), color)

        color_lut = [0, RED, BLUE]
        dim = 2 - self.current_player
        if self.server is None:
            bright = DIM_AUTO
        else:
            bright = DIM_MANUAL
        color_lut[dim] = cubehelper.mix_color(0, color_lut[dim], bright)
        for y in range(0, 4):
            for z in range(0, 4):
                for x in range(0, 4):
                    color = color_lut[self.grid[x, y, z]]
                    self.box(x, y, z, color)
        if self.winner is None:
            draw_cursor(self.cursor)
        if self.won_line is not None:
            for pos in self.won_line:
                draw_cursor(pos)
        self.ccount += self.cdelta * DT
        if self.ccount > 1.0:
            self.ccount -= 1.0
            self.coffset = self.cnext
            self.cnext = next(self.coffset_iter)
        if (self.current_player
                == 1) or (self.server is None) or (self.winner is not None):
            self.ai_tick -= DT
        if self.ai_tick < 0:
            if self.winner is not None:
                raise StopIteration
            self.ai_tick = TURN_DELAY
            self.do_ai()
示例#9
0
文件: oxo.py 项目: MattChu/pycubedemo
    def tick(self):
        def draw_cursor(pos):
            (x, y, z) = pos
            base = color_lut[self.grid[x, y, z]]
            x *= 2
            y *= 2
            z *= 2
            color = cubehelper.mix_color(base, WHITE, 1.0 - self.ccount)
            (i, j) = self.coffset
            self.cube.set_pixel((x+i,y+j,z), color)
            self.cube.set_pixel((x+1-i,y+1-j,z+1), color)
            color = cubehelper.mix_color(base, WHITE, self.ccount)
            (i, j) = self.cnext
            self.cube.set_pixel((x+i,y+j,z), color)
            self.cube.set_pixel((x+1-i,y+1-j,z+1), color)

        color_lut = [0, RED, BLUE]
        dim = 2 - self.current_player
        if self.server is None:
            bright = DIM_AUTO
        else:
            bright = DIM_MANUAL
        color_lut[dim] = cubehelper.mix_color(0, color_lut[dim], bright)
        for y in range(0, 4):
            for z in range(0, 4):
                for x in range(0, 4):
                    color = color_lut[self.grid[x, y, z]]
                    self.box(x, y, z, color)
        if self.winner is None:
            draw_cursor(self.cursor)
        if self.won_line is not None:
            for pos in self.won_line:
                draw_cursor(pos)
        self.ccount += self.cdelta * DT
        if self.ccount > 1.0:
            self.ccount -= 1.0
            self.coffset = self.cnext
            self.cnext = next(self.coffset_iter)
        if (self.current_player == 1) or (self.server is None) or (self.winner is not None):
            self.ai_tick -= DT
        if self.ai_tick < 0:
            if self.winner is not None:
                raise StopIteration
            self.ai_tick = TURN_DELAY
            self.do_ai()
示例#10
0
 def descend(self):
     color = cubehelper.mix_color((0.0,0.0,0.0), self.bit_color, self.fade)
     for bit in self.bits:
         pos = bit.pos
         v = bit.v
         v[0] *= FRICTION
         v[1] *= FRICTION
         v[2] *= FRICTION
         v[2] -= GRAVITY * DT
         for i in range(0, 3):
             pos[i] += v[i] * DT
             if pos[i] < 0.0:
                 pos[i] = 0.0
                 v[i] = 0
             elif pos[i] > 1.0:
                 pos[i] = 1.0
         self.plot(bit, color)
     self.fade -= FADE * DT
     if self.fade < 0.5 and self.rocket is None:
         self.launch()
     if self.fade <= 0:
         self.bits = None
示例#11
0
 def descend(self):
     color = cubehelper.mix_color((0.0,0.0,0.0), self.bit_color, self.fade)
     for bit in self.bits:
         pos = bit.pos
         v = bit.v
         v[0] *= FRICTION
         v[1] *= FRICTION
         v[2] *= FRICTION
         v[2] -= GRAVITY * DT
         for i in range(0, 3):
             pos[i] += v[i] * DT
             if pos[i] < 0.0:
                 pos[i] = 0.0
                 v[i] = 0
             elif pos[i] > 1.0:
                 pos[i] = 1.0
         self.plot(bit, color)
     self.fade -= FADE * DT
     if self.fade < 0.5 and self.rocket is None:
         self.relaunch = True
     if self.fade <= 0:
         self.bits = None
示例#12
0
 def draw(self):
     c = cubehelper.mix_color((0, 0, 0), self.colour, self.opacity)
     self.cube.set_pixel(self.coords(), c)
示例#13
0
 def draw(self):
     c = cubehelper.mix_color((0, 0, 0), self.colour, self.opacity)
     self.cube.set_pixel(self.coords(), c)
示例#14
0
文件: worm.py 项目: johnl/pycubedemo
 def color_for_energy(self, e):
     if self.cube.color:
         color = self.cube.plasma(e * 5.0)
     else:
         color = (1.0, 1.0, 1.0)
     return cubehelper.mix_color(0, color, e)
示例#15
0
文件: worm.py 项目: hexwab/pycubedemo
 def color_for_energy(self, e):
     if self.cube.color:
         color = color_from_val(int(math.modf(e * 5.0)[0] * 256))
     else:
         color = (1.0, 1.0, 1.0)
     return cubehelper.mix_color(0, color, e)
示例#16
0
 def color_for_energy(self, e):
     if self.cube.color:
         color = self.cube.plasma(e * 5.0)
     else:
         color = (1.0, 1.0, 1.0)
     return cubehelper.mix_color(0, color, e)