#Rendering stuff on the terminal doesnt go as expected - python

268 messages ยท Page 1 of 1 (latest)

fast linden
#

I am displaying sprites on the terminal but things dont go as expected when im displaying multiple, the second sprite (if on the same line) is displayed at <x> - <width of the sprite> for some reason.

#
def render(image, x, y, width, height):
    tmpx = 0
    tmpy = 0
    if x > 126:
        x = 126 - width
    if y > 16:
        y = 16 - height
        
    for line in image:
        for char in line:
            bitmap[y + tmpy][x+tmpx] = char
            tmpx+=1
        tmpx=0
        tmpy +=1

render(water, 6, 3, 6, 3)
render(tree, 129, 5, 21, 9)
for line in bitmap:
    for char in line:
        print(char, end='')
    print('')
#
tree = ["      caecceqeao     ",
        "    acqqgpwdoOeoOa   ",
        "   eaaOoropOacWacdQ  ",
        " opao#ppo\@|a/aoqaoO ",
        "   #aOd@@@\|/@o##@$  ",
        "          }|{        ",
        "          }|{        ",
        "          }|{        ",
        "          }|{        "
]

here is tree, for an example, for how the sprites look

naive bobcat
#

๐Ÿ’€

#

i thought u were helping

fast linden
#

it displays somewhat like this

fast linden
naive bobcat
#

didnt know this was ur thread

fast linden
#

i dont know ngrok

#

thats why i asked if you knew

naive bobcat
#

nah nah this thread. i thought someon else needed help

#

and u were helping

fast linden
#

oh wait

#

๐Ÿ’€

#

im the one that needs help tflmao

naive bobcat
#

also is it suppose to render at the end

#

i mean right

#

and not center?

fast linden
#

thats what is supposed to

#

the x position gets clamped to width of the terminal (129) - width of the sprite

#

so it should display right at the end

fast linden
naive bobcat
#

i will run it and see

#

but my guess is its cause of the way you're calculating the x pos

#
if x > 126:
    x = 126```
#

@fast linden

fast linden
#

wont they

naive bobcat
#

the code adjusts the x coords if it exceeds 126. However, it sets the x-coordinate to 126 - width, which is causing the second sprite to be shifted to the left by the width of the sprite.

fast linden
naive bobcat
#

gotta do some wrapping to fix it

fast linden
#

the size of the list is only 126 wide

naive bobcat
#

try this

#
render(tree, 100, 5, 21, 9)  # Adjusted x-coordinate to 100
fast linden
#

oh wait that makes more sense

#

we are still getting the same problem

#

oh wait btw

#

is it worth noting that im using sty

#

because somehow it isnt there without sty

#

without color

naive bobcat
#

sty handles stuff differently

#

like the positioning

#

it works

fast linden
naive bobcat
#

yea

fast linden
#

no color for me or

naive bobcat
#

you gotta find a way around it

#

try some other libraries

#

colorama

fast linden
#

okay lets give that a try

naive bobcat
#

wait a sec

#

doesn't python version 10.x+ comes with rich

#

library

#

it can be used to color too

fast linden
#

3.10+ you mean btw?

naive bobcat
#

yea

#

๐Ÿ’€

#

i accidently created python 10

#

dunno how that suppose to look

#

prolly will come with gpt models inside of it

#

or quantum computing

fast linden
#

๐Ÿ’€

#

probably will be voice-typed

#

if that makes sense

#

anyway, rich only supports print

naive bobcat
#

makes much more sense lmfao

fast linden
#

so i will have to tweak the renderer to directly print it out

#

but that makes the bitmap useless mhmadidas

naive bobcat
#

soorry i thought u wrote twerk

fast linden
#

twerk the renderer lmfao

naive bobcat
#

too much social media :p

naive bobcat
#

if so then yea

#

but rich isnt the oonly option

#

there are others

fast linden
#

im looking into colorama atm

naive bobcat
#

or what you can do it when you print the output from bitmap

#

then color it

#

at that moment

fast linden
#

okay so

#

colorama had better results

#

the offset is still there though

#

but its less?

naive bobcat
#

ss will help

#

if little then ig we can do sometehing about it

fast linden
#

yes give me a moment

#

the blue is hard to see just bare with it

naive bobcat
#

hmmm well honestly i dont think the render function there does anything to fck this up mhm

#

i doubt its the bitmap thing

#

so the code for bitmap might actually help

fast linden
#

its the color module

naive bobcat
#

but where do you use it

#

bitmap

#

or render

fast linden
naive bobcat
#

the colorama

#

you used it to color? even tho the trees still white

#

..

#

so u used it somewhere

fast linden
#

no i only colored the water

#

do u want me to color the whole thing

naive bobcat
#

....in the sky

fast linden
#

i mean i only wanted to test

fast linden
naive bobcat
#

nvm art is art ๐Ÿ’€

fast linden
#

the Fore.[color] is adding an extra character

#

same with sty i presume

naive bobcat
#

im not sure if we can push that chunk of the tree

#

in the render thing

#

by setting it back to 186

#

or 126

#

wut it was earlier

fast linden
#

126

naive bobcat
#

yea try that

fast linden
#

not helping mhmadidas

naive bobcat
fast linden
naive bobcat
#

ig a colorless life isnt that bad either

#

wad do u say

naive bobcat
fast linden
naive bobcat
#

water is not blue either way

#

so lets just stick with white

fast linden
#

trees are green mhmadidas

naive bobcat
#

lets make an exception for this project mhm

#

its a diff breed

fast linden
#

well its fine

#

its a text game

#

thats my excuse mhmadidas

#

some other day i suppose

#

the colors

naive bobcat
#

yes! mhm

fast linden
#

!! mhm

naive bobcat
#

how to help someone whos in need? simple just tell em to make an exception and forget the issue and the thing that caused the issue mhmadidas

fast linden
#

i'll keep this thread open if some genius decides to help

naive bobcat
#

oh its u

#

i thought someone with the same pfp as urs

fast linden
#

..i

naive bobcat
#

sent a dm

fast linden
#

o h

naive bobcat
#

display names r shit

fast linden
#

indeed they are

fast linden
#

@naive bobcat i figured it out last night

#

every time we concatenate anything from sty or colorama for color, we are adding another character to the bitmap

#

but since the character are empty characters "" they make the spacing error

#

now why did sty have more error than colorama? well because i was adding it continously for every character in the sprite

#

so fg + bg + character + rs.all means 3x the characters than just one character

#

3x6 = 18 so its pretty close to 21, which was the width of the tree sprite, thats why it seemed like that

#

anyway, time to quadruple the size of the bitmap

#

ok turns out i still have the dumb but now it suddenly works somehow

#

whatm.

#

thanks for the help tho @naive bobcat smilecatadidas

#

maybe the world being colorful is naice smilecatadidas

naive bobcat
#

sherlock

naive bobcat
#

still the water is floating in the sky

fast linden
#

it sounds cooler

#

@naive bobcat

#

HHAA LOOK

naive bobcat
#

wtf is that iosskull

#

dont tell me its ur cmd

#

not some gui app

#

thats really sick

fast linden
#

and i added layers

naive bobcat
#

damn did you turn an image into ascii?

#

it would take alot more time to draw ascii art by hand

fast linden
fast linden
#

most of it is copy pasted

#

although some of the simpler ones were by hand

naive bobcat
#

works. r u making a tui library? mhm

#

by any chance

fast linden
naive bobcat
#

minecraft rpg

#

in terminal

fast linden
#

although if it becomes polished, and people want it, i'd post it on github

naive bobcat
#

cool

fast linden
naive bobcat
#

is definitely helpful to someone out there

fast linden
#

without them being too verbose

naive bobcat
#

tho how are you going to make the charcter move?

#

if you are making a charc

fast linden
fast linden
#

the typing-effect for the text just broke

#

so

#

i'll see if i can get a better input system

naive bobcat
#

;-;

#

pygame

#

keyboard

fast linden
#

no

#

oh wiat

#

o h y ea h

naive bobcat
#

gotta manually implement tho

fast linden
naive bobcat
#

input listerners

#

for your game

#

keystrokes

fast linden
#

u h hh hu h

#

something like cbreak in curses would work

#

but without curses

naive bobcat
#

sometimes you gotta buy the jam with the bread. mhm

#

you cant get one ๐Ÿ’€

fast linden
#

except the jam corrodes the bread mhm

#

that makes no sense but

#

curses is breaking my text system

#

thats all

#

and if it does that then, my whole rendering library is gone

naive bobcat
#

;-;

#

you gotta make your own jam

#

for the bread

fast linden
#

i baked my own bread too ๐Ÿ˜ญ

#

lets see how it goes

#

or else i just give up and make the player press RETURN all the time

naive bobcat
#

yea u never know, afterall its code mhm

fast linden
naive bobcat
#

i didnt find the cow meme

fast linden
#

there is a keyboard module

naive bobcat
naive bobcat
#

tho the thing is its a bit slow

fast linden
fast linden
naive bobcat
#

if you want more low level access and fast try hook

fast linden
naive bobcat
#

if you're a sucker for speed like me then ๐Ÿ’€

fast linden
#

๐Ÿ’€

naive bobcat
#

even tho idk wut i;ll do with so much speed

fast linden
#

u guys are a different breed

#

here i am doing nested loops in python

naive bobcat
#

sociopaths mhm

fast linden
naive bobcat
#

its better tho. my brain just wont let me work with python just cuz someone yt dude said its slow pepehehehe

#

even tho it works just fine

#

who needss code that runs like a rocket

fast linden
#

but C's disastrous libraries made me switch

#

i had over 500 lines in C already done mhm

#

then i rewrote in python with OOP this time mhmadidas

naive bobcat
#

i wouldnt even try

naive bobcat
#

@hexed bear

#

this thread is not for you

#

this is created for someone elses issue

#

you should make your own thread in #1061301409267580988