当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.frame方法代码示例

本文整理汇总了Python中drawille.Canvas.frame方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.frame方法的具体用法?Python Canvas.frame怎么用?Python Canvas.frame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在drawille.Canvas的用法示例。


在下文中一共展示了Canvas.frame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: image2term

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
def image2term(image, threshold=128, ratio=None):
    if image.startswith('http://') or image.startswith('https://'):
        i = Image.open(StringIO(urllib2.urlopen(image).read())).convert('L')
    else:
        i = Image.open(open(image)).convert('L')
    w, h = i.size
    if ratio:
        w = int(w * ratio)
        h = int(h * ratio)
        i = i.resize((w, h), Image.ANTIALIAS)
    else:
        tw, th = getTerminalSize()
        tw *= 2
        th *= 2
        if tw < w:
            ratio = tw / float(w)
            w = tw
            h = int(h * ratio)
            i = i.resize((w, h), Image.ANTIALIAS)
    can = Canvas()
    x = y = 0
    for pix in i.tobytes():
        if ord(pix) < threshold:
            can.set(x, y)
        x += 1
        if x >= w:
            y += 1
            x = 0
    return can.frame()
开发者ID:MB6,项目名称:drawille,代码行数:31,代码来源:image2term.py

示例2: __main__

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
def __main__(stdscr, projection=False):
    angleX, angleY, angleZ = 0, 0, 0
    c = Canvas()
    while 1:
        # Will hold transformed vertices.
        t = []

        for v in vertices:
            # Rotate the point around X axis, then around Y axis, and finally around Z axis.
            p = v.rotateX(angleX).rotateY(angleY).rotateZ(angleZ)
            if projection:
                # Transform the point from 3D to 2D
                p = p.project(50, 50, 50, 50)
             #Put the point in the list of transformed vertices
            t.append(p)

        for f in faces:
            for x,y in line(t[f[0]].x, t[f[0]].y, t[f[1]].x, t[f[1]].y):
                c.set(x,y)
            for x,y in line(t[f[1]].x, t[f[1]].y, t[f[2]].x, t[f[2]].y):
                c.set(x,y)
            for x,y in line(t[f[2]].x, t[f[2]].y, t[f[3]].x, t[f[3]].y):
                c.set(x,y)
            for x,y in line(t[f[3]].x, t[f[3]].y, t[f[0]].x, t[f[0]].y):
                c.set(x,y)

        f = c.frame(-40, -40, 80, 80)
        stdscr.addstr(0, 0, '{0}\n'.format(f))
        stdscr.refresh()

        angleX += 2
        angleY += 3
        angleZ += 5
        sleep(1.0/20)
        c.clear()
开发者ID:Mondego,项目名称:pyreco,代码行数:37,代码来源:allPythonContent.py

示例3: update

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
def update(im, delay=0.1):

  im = im.resize((CANVAS_W, CANVAS_H))
  canvas = Canvas()
  any(canvas.set(i % CANVAS_W, i // CANVAS_W)
      for i, px in enumerate(im.tobytes()) if px)
  print(canvas.frame(0, 0, CANVAS_W, CANVAS_H), end='')
  time.sleep(delay)
开发者ID:livibetter,项目名称:READYT,代码行数:10,代码来源:trailer.py

示例4: setup

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
def setup():
    # set the size of the board to the size of the terminal at ther start
    width, height = os.popen('stty size', 'r').read().split()
    height, width = 50, 50
    board = Canvas()
    frame = (0, 0, width, height)
    assert(frame[YSEC] == height)
    board.frame(*frame)
    draw_bounds(board, frame)

    # get some paddles
    lpaddle = Paddle('left', board, frame)
    rpaddle = Paddle('right', board, frame)
    ball = Ball(board, frame)

    # get some output!
    stdscr = curses.initscr()
    stdscr.refresh()
    return (lpaddle, rpaddle, ball), board, frame, stdscr
开发者ID:tomparks,项目名称:Terminal-pong,代码行数:21,代码来源:pong.py

示例5: main

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
def main(stdscr):
    global frame_no, speed, fps, position, delta, score
    c = Canvas()
    bar_width = 16
    bars = [Bar(bar_width)]
    stdscr.refresh()

    while True:
        frame_no += 1
        for bar in bars:
            if check_collision(position, bar):
                return
        while not keys.empty():
            if keys.get() == 113:
                return
            speed = 32.0

        c.set(0,0)
        c.set(width, height)
        if frame_no % 50 == 0:
            bars.append(Bar(bar_width))
        for x,y in bird:
            c.set(x,y+position)
        for bar_index, bar in enumerate(bars):
            if bar.x < 1:
                bars.pop(bar_index)
                score += 1
            else:
                bars[bar_index].x -= 1
                for x,y in bar.draw():
                    c.set(x,y)
        f = c.frame()+'\n'
        stdscr.addstr(0, 0, f)
        stdscr.addstr(height/4+1, 0, 'score: {0}'.format(score))
        stdscr.refresh()
        c.clear()

        speed -= 2

        position -= speed/10

        if position < 0:
            position = 0
            speed = 0.0
        elif position > height-13:
            position = height-13
            speed = 0.0


        sleep(1.0/fps)
开发者ID:Mondego,项目名称:pyreco,代码行数:52,代码来源:allPythonContent.py

示例6: __main__

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
def __main__(projection=False):
    angleX, angleY, angleZ = 0, 0, 0
    c = Canvas()
    while 1:
        # Will hold transformed vertices.
        t = []

        for v in vertices:
            # Rotate the point around X axis, then around Y axis, and finally around Z axis.
            p = v.rotateX(angleX).rotateY(angleY).rotateZ(angleZ)
            if projection:
                # Transform the point from 3D to 2D
                p = p.project(50, 50, 50, 50)
            # Put the point in the list of transformed vertices
            t.append(p)

        for f in faces:
            for x, y in line(t[f[0]].x, t[f[0]].y, t[f[1]].x, t[f[1]].y):
                c.set(x, y)
            for x, y in line(t[f[1]].x, t[f[1]].y, t[f[2]].x, t[f[2]].y):
                c.set(x, y)
            for x, y in line(t[f[2]].x, t[f[2]].y, t[f[3]].x, t[f[3]].y):
                c.set(x, y)
            for x, y in line(t[f[3]].x, t[f[3]].y, t[f[0]].x, t[f[0]].y):
                c.set(x, y)

        f = c.frame(-20, -20, 20, 20)
        s = 'broadcast "\\n\\n\\n'
        for l in format(f).splitlines():
            s += l.replace(" ", "  ").rstrip("\n") + "\\n"
        s = s[:-2]
        s += '"'
        print(s)
        sys.stdout.flush()

        angleX += 2
        angleY += 3
        angleZ += 5
        sleep(1.0 / 10)
        c.clear()
开发者ID:Ryozuki,项目名称:ddnet-scripts,代码行数:42,代码来源:rotating_cube.py

示例7: image2term

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
def image2term(image, threshold=128, ratio=None, invert=False):
    if image.startswith('http://') or image.startswith('https://'):
        i = Image.open(StringIO(urllib2.urlopen(image).read())).convert('L')
    else:
        i = Image.open(open(image)).convert('L')
    w, h = i.size
    if ratio:
        w = int(w * ratio)
        h = int(h * ratio)
        i = i.resize((w, h), Image.ANTIALIAS)
    else:
        tw = getTerminalSize()[0]
        tw *= 2
        if tw < w:
            ratio = tw / float(w)
            w = tw
            h = int(h * ratio)
            i = i.resize((w, h), Image.ANTIALIAS)
    can = Canvas()
    x = y = 0

    try:
         i_converted = i.tobytes()
    except AttributeError:
         i_converted = i.tostring()

    for pix in i_converted:
        if invert:
            if ord(pix) > threshold:
                can.set(x, y)
        else:
            if ord(pix) < threshold:
                can.set(x, y)
        x += 1
        if x >= w:
            y += 1
            x = 0
    return can.frame(0, 0)
开发者ID:ChrisOHu,项目名称:vimrc,代码行数:40,代码来源:image2term.py

示例8: Canvas

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
    lt = left
    bk = back

########NEW FILE########
__FILENAME__ = basic
from __future__ import print_function
from drawille import Canvas
import math


s = Canvas()

for x in range(1800):
    s.set(x/10, math.sin(math.radians(x)) * 10)

print(s.frame())

s.clear()

for x in range(0, 1800, 10):
    s.set(x/10, 10 + math.sin(math.radians(x)) * 10)
    s.set(x/10, 10 + math.cos(math.radians(x)) * 10)

print(s.frame())

s.clear()

for x in range(0, 3600, 20):
    s.set(x/20, 4 + math.sin(math.radians(x)) * 4)

print(s.frame())
开发者ID:Mondego,项目名称:pyreco,代码行数:33,代码来源:allPythonContent.py

示例9: printa_parabola

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
def printa_parabola(lado):
    s = Canvas()
    s.clear()
    for x in range(0, 180):
        s.set(x / 4, lado + sin(radians(x)) * lado)
    return s.frame()
开发者ID:vasartori,项目名称:parabola,代码行数:8,代码来源:parabola.py

示例10: int

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
		if (dither or trippy) :
			#because you can't divide by zero
			if (sum == 0) :
				canvo.unset(x,y)
			else:
				#the RGB scale is exponential , so the ratio of light from 255 to 80 would be 255^2/80^2
				# however since the image is 3 dimensional, then the dither turns on in 1/mod * 1/mod
				# so mod should be 255/80 instead
				mod = int(255 / sum)
				# the ratio here is (2x-1)/x^2 where x is 255/sum
				if (trippy) :
					if (((x % mod) == 0) or ((y % mod) == 0)) :
						canvo.set(x,y)
					else:
						canvo.unset(x,y)
				#ratio is 1/x^2
				elif (dither) :
					if (((x % mod) == 0) and ((y % mod) == 0)) :
						canvo.set(x,y)
					else:
						canvo.unset(x,y)
		else:
			if (threshup >=  sum >= threshdown ) :
				# turns the dot on at x,y
				canvo.set(x,y)
			else :
				# it seems if an entire character is blank, draille does not print it regardless of this
				canvo.unset(x,y)
#prints the final product
print(canvo.frame())
开发者ID:knolax,项目名称:dotfiles,代码行数:32,代码来源:imagetobraile.py

示例11: __init__

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
class GameOfLife:

    def __init__(self, rows, cols):
        self.rows = rows
        self.cols = cols
        self.can = Canvas()
        self.state = [[bool(random.getrandbits(1)) for y in range(rows)] for x in range(cols)]

    def tick(self):
        next_gen = [[False for y in range(self.rows)] for x in range(self.cols)]

        for y in range(self.rows):
            for x in range(self.cols):
                nburs = self._ncount(x, y)
                if self.state[x][y]:
                    # Alive
                    if nburs > 1 and nburs < 4:
                        self.can.set(x,y)
                        next_gen[x][y] = True
                    else:
                        next_gen[x][y] = False
                else:
                    # Dead
                    if nburs == 3:
                        self.can.set(x,y)
                        next_gen[x][y] = True
                    else:
                        next_gen[x][y] = False

        self.state = next_gen

    def draw(self):
        f = self.can.frame(0,0,self.cols,self.rows)
        stdscr.addstr(0, 0, '{0}\n'.format(f))
        self.can.clear()

    def put(self, matrix, x, y):
        for mx in range(len(matrix)):
            for my in range(len(matrix[0])):
                self.state[min(x+my,self.cols-1)][min(y+mx,self.rows-1)] = matrix[mx][my]


    def _ncount(self, x, y):
        nburs = 0

        # Left
        if x > 0:
            if self.state[x-1][y]:
                nburs += 1
            # Top
            if y > 0:
                if self.state[x-1][y-1]:
                    nburs += 1
            # Bottom
            if y < self.rows-1:
                if self.state[x-1][y+1]:
                    nburs += 1

        # Right
        if x < self.cols-1:
            if self.state[x+1][y]:
                nburs += 1
            # Top
            if y > 0:
                if self.state[x+1][y-1]:
                    nburs += 1
            # Bottom
            if y < self.rows-1:
                if self.state[x+1][y+1]:
                    nburs += 1

        # Top
        if y > 0:
            if self.state[x][y-1]:
                nburs += 1
        # Bottom
        if y < self.rows-1:
            if self.state[x][y+1]:
                nburs += 1

        return nburs
开发者ID:glindste,项目名称:gol,代码行数:83,代码来源:game_of_life.py

示例12: getTerminalSize

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
    else:
        url = 'http://xkcd.com/%s/' % argv[1]
    c = urllib2.urlopen(url).read()
    img_url = re.findall('http:\/\/imgs.xkcd.com\/comics\/.*\.png', c)[0]
    i = Image.open(StringIO(urllib2.urlopen(img_url).read())).convert('L')
    w, h = i.size
    tw, th = getTerminalSize()
    tw *= 2
    th *= 2
    if tw < w:
        ratio = tw / float(w)
        w = tw
        h = int(h * ratio)
        i = i.resize((w, h), Image.ANTIALIAS)
    can = Canvas()
    x = y = 0

    try:
         i_converted = i.tobytes()
    except AttributeError:
         i_converted = i.tostring()

    for pix in i_converted:
        if ord(pix) < 128:
            can.set(x, y)
        x += 1
        if x >= w:
            y += 1
            x = 0
    print(can.frame())
开发者ID:Rocknrenew,项目名称:drawille,代码行数:32,代码来源:xkcd.py

示例13: test_max_min_limits

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
 def test_max_min_limits(self):
     c = Canvas()
     c.set(0, 0)
     self.assertEqual(c.frame(min_x=2), '')
     self.assertEqual(c.frame(max_x=0), '')
开发者ID:Mondego,项目名称:pyreco,代码行数:7,代码来源:allPythonContent.py

示例14: test_frame

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
 def test_frame(self):
     c = Canvas()
     self.assertEqual(c.frame(), '')
     c.set(0, 0)
     self.assertEqual(c.frame(), 'РаЂ')
开发者ID:Mondego,项目名称:pyreco,代码行数:7,代码来源:allPythonContent.py

示例15: test_set_text

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import frame [as 别名]
 def test_set_text(self):
     c = Canvas()
     c.set_text(0, 0, "asdf")
     self.assertEqual(c.frame(), "asdf")
开发者ID:Mondego,项目名称:pyreco,代码行数:6,代码来源:allPythonContent.py


注:本文中的drawille.Canvas.frame方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。