类似panda3d文本打印的课程

panda3d-purses3d的Python项目详细描述


购买3d

我们的目标是尽可能地控制panda3d,同时提供打印到的各种控制台,而不是尽可能地模拟ncurses。它目前还很简陋,但是有了一些解决方法,可以做任何ncurses可以做的事情,除了beep()。

  • 仅适用于包含U+2588“全块”Unicode字符的单行距字体(用于实心字符背景)。出于这个原因,hack.ttf在这个repo中,它是麻省理工学院授权的。
  • 用于制作基于ascii/文本的游戏、gui、hud等。
  • 要么结合panda3d的其他功能,要么认为这是将文本绘制到屏幕上的错误方法。

要查看功能的彩色显示,请运行

 $ git clone http://github.com/momojohobo/panda3d-purses
 $ cd panda3d-purses
 $ pip install -r requirements.txt
 $ python purses3d/__init__.py 

它也可以在pypi上使用。

 $ pip install panda3d-purses3d

待办事项:

  • 从ncurses窃取更多方便的功能。

许可证

无论是麻省理工学院还是公共领域(cc0),你都可以选择。

使用方法:

# Import sys, panda3d and purses
import sys
from direct.showbase.ShowBase import ShowBase
from purses3d import Purses, Window

# Run panda3d
base = ShowBase()
base.accept("escape", sys.exit)
base.run()

# Initialize purses with a console size of 40x20 characters
# It will be automatically scaled to fill the entire screen
purses = Purses(40, 20)

# Make a window in the center, taking up half the screen
window = Window(x=10, y=5, columns=20, lines=10)  

# Move that window's cursor to where we want to write
window.move(3, 0)

# Write something in that window
window.addstr("hello world")

# Or move and print in one go
window.addstr(3, 0, "hello world")

# Copy it to the main purses window
purses.copyfrom(window)

# Because Purses() is also a window, we can write something on it too
purses.addstr(0, 0, "purses!")

# Update the screen
purses.refresh()

颜色/属性

要添加颜色(以及其他需要的东西),我们需要panda3d的textpropertiesmanager

from panda3d.core import TextProperties, TextPropertiesManager

# Get panda3d's global property manager
manager = TextPropertiesManager.getGlobalPtr()

# Make some property, in this case something telling it to print the text red (in rgba)
red = TextProperties()
red.setTextColor((1,0,0,1))

# Add it to panda's global mananger
manager.addProperties("myRedColor", red) 

# And use it to print the characters foreground (with a transparent background)
purses.addstr(0, 0, "purses!", ("myRedColor", None))

# ...or to print the characters background in that color
purses.addstr(0, 0, "purses!", (None, "myRedColor"))

purses.refresh()

# We can reposition this purses instance too so it doesn't take up the entire screen
purses.node.setScale(0.5)
purses.node.setPos(-0.3, 0, 0)

# Or parent it to the world as a 3d object COOOL!
purses.node.reparentTo(render)

您可以更改在panda3d textproperties类中找到的任何属性,尽管它们大多未经测试。尤其是改变文本大小可能会把事情搞砸。

文本输入

因为panda3d是一个实时系统,而curses不是,所以文本输入的处理方式有点不同。

# Get user input string at (10, 5) from main purses screen
string = purses.getstr(10, 5)

# You can also supply a different window to echo the string to
# Or give it fg and bg attributes
string = purses.getstr(10, 5, window=my_window, attr=("red", "blue"))

# If the string is closed (with enter), it is returned instead of None.
if string:
    # If used types hello
    if string == "hello":
        # Print this answer
        purses.addstr("why hello there buddy!")

迄今为止的功能

purses.move(x, y) # Place the cursor at position
purses.increment(n=1) # Increment the cursor location

purses.scrollup() # Scroll everything in window up
purses.scrolldown() # Scroll everything in window down

purses.fill(character) # Fills the entire window with a char (or empty if none is specified)
purses.delete(x, y) # Delete a single character
purses.addch(x, y, char, properties) # Add a single character
purses.addstr(x, y, string, properties) # Add a string 

# Draw horizontal and vertical lines respectively
purses.linehori(start_x, start_y, length, character, properties)
purses.linevert(start_x, start_y, length, character, properties)

# Draw a border around the window, left, right, top, bottom and its corners.
# Each character should be complete with properties ("c", (None, None))
purses.border(ls, rs, ts, bs, tl, tr, bl, br) 
purses.box(horizontal_sides, vertical_sides)

# These calls only work from the main Purses() window.
purses.refresh() # Refresh screen (place its state to the screen)
# Return the mouse coordinates in characters, only callable from Purses()
# If window is specified it will return its relative coordinates
purses.getmouse(window) 
# Return a string as written by user
purses.getstr(x, y, window=None, attr=(None, None))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Requestcontextholder在spring 4中具有并发访问权限。IBMWebSphere上的x Web应用程序?   java如何下载、设置和使用Eclipse?   java如何组合这些mysql语句   java JDBC无法连接到openshift上的mysql数据库   如果存在允许正确处理的重载,java对于方便的方法来说是否可行?   使用hibernate序列的java Spring MVC不存在   具有路径的java Selenium ChromeDriver负载扩展问题   读一本书。java中的java文件   退出队列时,Java队列程序结果为空   Java lambda返回带有重复代码问题的列表   java使用意图从其他活动传递数据并在listview中显示   java如何在java中创建JSON输出   java Android:在不破坏或暂停活动的情况下关闭显示   支持Android电视和手机的java多apk   关于Java应用程序测试和调试的一组问题   如何在JavaSE中使用jdbcRealmShiro进行授权   在java中是否有一个无异常检查的URL解析实用程序?   当页面上有多个相同类型的元素时,java会选择一个特定的元素   递归需要帮助发现java代码中的缺陷