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


Python Canvas.clear方法代码示例

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


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

示例1: __main__

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [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

示例2: main

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [as 别名]
def main(args, opts):
    curses.use_default_colors()
    curses.curs_set(0)

    win = curses.initscr()

    source = Image.open(opts.filename)

    c = Canvas()

    try:
        while True:
            (wh, ww) = win.getmaxyx()

            try:
                source.seek(source.tell() + 1)
            except:
                if opts.onetime:
                    break
                source.seek(0)

            img = (source
                    .resize(((ww - 1) * 2, wh * 4))
                    .convert("1")
                    )
            w = img.width

            (x, y) = (0, 0)
            for v in img.getdata():

                if opts.reverse:
                    if not v:
                        c.set(x, y)

                else:
                    if v:
                        c.set(x, y)

                x += 1

                if w <= x:
                    x = 0
                    y += 1

            for r in range(wh):
                line = c.rows(min_y=(r*4), max_y=((r+1)*4))[0]
                win.addnstr(r, 0, pad(line, ww), ww)

            win.refresh()
            c.clear()
            time.sleep(opts.interval)

    except KeyboardInterrupt:
        pass
开发者ID:zaftzaft,项目名称:terminal-anime,代码行数:56,代码来源:main.py

示例3: main

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [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

示例4: __main__

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [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

示例5: printa_parabola

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [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

示例6: test_clear

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [as 别名]
 def test_clear(self):
     c = Canvas()
     c.set(1, 1)
     c.clear()
     self.assertEqual(c.chars, dict())
开发者ID:Mondego,项目名称:pyreco,代码行数:7,代码来源:allPythonContent.py

示例7: Canvas

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [as 别名]
########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())

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

示例8: Canvas

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [as 别名]
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())

s.clear()

for x in range(0, 360, 4):
    s.set((x/4, 30 + math.sin(math.radians(x)) * 30))
开发者ID:MB6,项目名称:drawille,代码行数:33,代码来源:basic.py

示例9: __init__

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [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

示例10: init

# 需要导入模块: from drawille import Canvas [as 别名]
# 或者: from drawille.Canvas import clear [as 别名]
from drawille import Canvas, line, Turtle, polygon
from colorama import *
from math import sin, radians


init()
c = Canvas()
c.clear()
pnts = []
t = Turtle()
tpos = []


class plot:

	def lnres(inres):
		res = inres
				
	def printc(color):
		for x,y in pnts:
			c.set(x,y)
		if color == 'green':
			print(Fore.GREEN+c.frame())
		if color == 'red':
			print(Fore.RED+c.frame())
		if color == 'yellow':
			print(Fore.YELLOW+c.frame())
		if color == 'blue':
			print(Fore.BLUE+c.frame())
		if color == 'cyan':
			print(Fore.CYAN+c.frame())
开发者ID:Tacolizard,项目名称:arith,代码行数:33,代码来源:lib.py


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