Skip to content
Kyuchumimo edited this page Jul 9, 2022 · 17 revisions

print

print text [x=0 y=0] [color=12] [fixed=False] [scale=1] [smallfont=False] -> text width

Parameters

  • text : any string to be printed to the screen
  • x, y : coordinates for printing the text
  • color : the color to use to draw the text to the screen
  • fixed : a flag indicating whether fixed width printing is required
  • scale : font scaling
  • smallfont : use small font if True

Output

  • text width : returns the width of the text in pixels.

Description

This will simply print text to the screen using the font defined in assets. When set to True, the fixed width option ensures that each character will be printed in a 'box' of the same size, so the character 'i' will occupy the same width as the character 'w' for example. When fixed width is False, there will be a single space between each character. Refer to the example for an illustration.

  • To use a custom rastered font, check out font.
  • To print to the console, check out trace.

Example 1

_TIC["PALETTE"] = [[0x14,0x0c,0x1c], [0x44,0x24,0x34], [0x30,0x34,0x6d], [0x4e,0x4a,0x4e], [0x85,0x4c,0x30], [0x34,0x65,0x24], [0xd0,0x46,0x48], [0x75,0x71,0x61], [0x59,0x7d,0xce], [0xd2,0x7d,0x2c], [0x85,0x95,0xa1], [0x6d,0xaa,0x2c], [0xd2,0xaa,0x99], [0x6d,0xc2,0xca], [0xda,0xd4,0x5e], [0xde,0xee,0xd6]] #DB16
# title:  print centered
# author: Vadim, edited by Kyuchumimo
# desc:   print text perfectly centered
# script: python
# input:  gamepad

cls()
string="my perfectly centered text"
width=print(string,0,-6)
print(string,(240-width)//2,(136-6)//2)

def TIC():
#Prints text where x is the center of text.
def printc(s,x,y,c=15):
    w=print(s,0,-8)
    print(s,x-(w/2),y,c)

Example 2

_TIC["PALETTE"] = [[0x14,0x0c,0x1c], [0x44,0x24,0x34], [0x30,0x34,0x6d], [0x4e,0x4a,0x4e], [0x85,0x4c,0x30], [0x34,0x65,0x24], [0xd0,0x46,0x48], [0x75,0x71,0x61], [0x59,0x7d,0xce], [0xd2,0x7d,0x2c], [0x85,0x95,0xa1], [0x6d,0xaa,0x2c], [0xd2,0xaa,0x99], [0x6d,0xc2,0xca], [0xda,0xd4,0x5e], [0xde,0xee,0xd6]] #DB16
# title:  Fixed width demo
# author: PaulR, edited by Kyuchumimo
# desc:   Show effect of fixed width flag
# script: Python

def TIC():
    cls(0)
    print('FIXED',0,0,15,True)
    print('FIXED',0,8,15,False)
    print('width',0,32,15,True)
    print('width',0,40,15,False)
    for i in range(0,31,6):
        line(i,0,i,6,8)
        line(i,8,i,16,9)
        line(i,32,i,40,8)
        line(i,40,i,48,9)

Example 3

import math
_TIC["PALETTE"] = [[0x14,0x0c,0x1c], [0x44,0x24,0x34], [0x30,0x34,0x6d], [0x4e,0x4a,0x4e], [0x85,0x4c,0x30], [0x34,0x65,0x24], [0xd0,0x46,0x48], [0x75,0x71,0x61], [0x59,0x7d,0xce], [0xd2,0x7d,0x2c], [0x85,0x95,0xa1], [0x6d,0xaa,0x2c], [0xd2,0xaa,0x99], [0x6d,0xc2,0xca], [0xda,0xd4,0x5e], [0xde,0xee,0xd6]] #DB16
# title:  print demo
# author: Filippo, edited by Kyuchumimo
# desc:   print matrix
# script: python
# input:  gamepad
# pal:00000000ff0000e50000cc0000b200009900007f00006600004c00003300001900000000b2ffb2ccffcce5ffe5ffffff

msg="FNORD                      "
t=0
def TIC():
    cls()
    c=1
    for x in range(0,30):
        for y in range(0,17):
            c=(c+1)%len(msg)
            l=(c-math.floor(t))%len(msg)
            print(msg[l:l+1],x*8,y*8,y%12,False,1)
    t=t+0.15

Example 4

import math
_TIC["PALETTE"] = [[0x14,0x0c,0x1c], [0x44,0x24,0x34], [0x30,0x34,0x6d], [0x4e,0x4a,0x4e], [0x85,0x4c,0x30], [0x34,0x65,0x24], [0xd0,0x46,0x48], [0x75,0x71,0x61], [0x59,0x7d,0xce], [0xd2,0x7d,0x2c], [0x85,0x95,0xa1], [0x6d,0xaa,0x2c], [0xd2,0xaa,0x99], [0x6d,0xc2,0xca], [0xda,0xd4,0x5e], [0xde,0xee,0xd6]] #DB16
# title:  print demo scale
# author: Filippo, edited by Kyuchumimo
# desc:   scale print
# script: python
# input:  gamepad

t=0
txt="[TIC]"

def TIC():
    for i in range(1,15):
        TIC["PALETTE"][i][0] = 100+i*10
        TIC["PALETTE"][i][1] = i*5
        TIC["PALETTE"][i][2] = 32+32*math.sin(t/100)

    cls()
    for z in range(15,-1,-1):
        y=12*z*math.sin(z/5+t/50)
        w=print(txt,0,-100,z,False,z)
        print(txt,(240-w)/2,
             68+y/1.5,
             15-z,False,z)
    t=t+1
Clone this wiki locally