I am using Python 3 and I am not sure if this is a possible query because I've searching it up and I couldn't find a solution. My question is, I want to learn how to change colour and size of my output.
How to make the size bigger or smaller?
Able to make the font size big
How to change the background colour of shell?
Able to make the background colour, for example, right now, it's all white but I want it black.
How to change the output colour of shell?
I would love to see colourful fonts operating in black background shell
I hope there is a solution to this! Thanks in advance
I know about the color part, but I came for the size.
To start off with, to close the color, use \u001b[0m. If you don't use this, all text will become the color that you started with until you close it.
Green is\u001b[32m
Black is\u001b[30m
Pink is \u001b[35m
There are much more, but is you experiment with different numbers, you can highlight and do different colors.
To make a sentence with color, format it like this:
print("\u001b[35mHi, coders. This is pink output.\u001b[0m")
Test that code. it will come out in pink.
Related
[ See question on Tiled's website : https://discourse.mapeditor.org/t/weird-unexpected-colors-transparent/5173?u=william_bourgeois ]
I never played with Tiled before today. I spent the whole day doing a pretty big map, and everything is wrong when I load it into my pygame RPG. The first image is how I see it in Tiled, the second image is what actually shows up when I load it.
When I say "everything is wrong", I mean some layers are not appearing and transparency is turned into solid colors (sometimes white, black, pink or yellow).
How I see my map in Tiled
How I see my map in my pygame window
I have already tried changing the “trans” argument in the text editor of the .tmx file to “000000”, “ffffff00” and “ff00ff” none of which work, but they have slight variations (some have the glitched parts with pink and yellow, others just white/black).
I tried with other tile sets to make sure it's not a problem with these specific assets. I get the same problem.
In Tiled
In my game (pygame)
Can someone please explain what is going on and how I can fix my map or at least avoid this mistake in future maps?
Turns out I had to completely delete the trans argument in the .tmx file in a text editor. Setting a transparency color causes issues when your assets are already transparent. Good to know! Now everything is working perfeclty!
I'm trying to write a Python program that detects the color of a portion of the screen and puts it in a conditional. The easiest way, I would think, would be to detect the color underneath the cursor (which would work perfectly with my program), but I can't find many up-to-date resources on that. I would like to be able to have the RGB, HEX, or some other type of value in a variable. Some ways that would work for my program: detecting the color under the cursor, detecting the color of a certain pixel, or detecting the color of a portion of pixels. Thanks for your help!
I'm trying to find the dominant color of an image. But not the most present pixel. Indeed, let us imagine that there are many Greens, I would like them to get together', rather than form a competition'.
If I do a simple average, I end up with values that don't match the visible colors that much, but more with a light brown that mixes everything together.
I do everything under python with PIL, but I am also interested in a general "technique" (without language).
Do you have any leads?
Thank you!
For this, it might be useful to note that I'm running python on a Mac in xterm-color
I'm trying to build a chess game with curses in Python, but I can't figure out how to set the color pairs to use bright black or bright white (so I can have better contrast between board and pieces.) The terminal shows the bright colors as being the color + 8 (so the 8-15 range,) but if I try to use those, I get back init_pair() returned ERR (For example, in:)
curses.init_pair(1, 0, 15)
I also thought that using the A_BOLD and A_BLINK attributes might let me set bright colors in curses, but that doesn't appear to have any effect. For example:
pad.addstr(y, x, "qwert", curses.color_pair(1)|curses.A_BOLD)
What do I need to do to get these colors?
Edit:
It turns out that I had a wrong setting in the terminal ("Use bright colors for bold text" was unchecked,) but I still don't seem to have any way to set a bright background color.
I still don't seem to have any way to set a bright background color.
This question is old, but in case someone will look for answer to it, you just have to combine curses.A_BOLD with curses.A_REVERSE, for example:
curses.init_pair(1, curses.COLOR_GREEN, curses.color_BLACK);
// Pair with green as a foreground color and black as a background
curses.color_pair(1);
// Pair with light green as a background color and black as a foreground
curses.color_pair(1) | curses.A_BOLD | curses.REVERSE;
... and now you have 2 × more pairs :)
In this case, the issue is simply that I had "Use bright colors for bold text" unchecked (oops, I was messing with the settings for the wrong terminal style.) It is somewhat worrying that I might not be able to rely on users having these settings on Mac OS however.
My end goal is to find a color in an image (in this case white) and replace it with another color (based on certain circumstances). So, as a certain variable changes the white is replaced with a specific color.
However, to get there I'm currently just playing with images (using tutorials ..etc). I'm trying to use the below code to print the color palette of an image. My understanding is the colors are a "tuple" of 3 integer representing RGB. 0 = darkest, 255 = white. So, the image I'm testing is a black and white image. I'm expecting something like "(0,0,0),(255,255,255)". So, I figured if I could get this far, then I could write a code to replace the "(255,255,255)" with the appropriate color.
I mentioned the end goal because I'm very aware that my approach might not be the best, and that perhaps someone has a better way I can go about this. If not, I'd at least like to be able to print a string referencing the colors an image contains. The "NOFRAME" was a great piece of advice I found on this site, as I'm not actually "using" the images/graphics - just using their attributes.
image1=r"C:\Python27\Lib\site-packages\pygame\examples\data\image1.jpg"
image2=r"C:\Python27\Lib\site-packages\pygame\examples\data\image2.png"
import pygame, sys
from pygame.locals import *
pygame.init()
pygame.display.set_mode((1,1), pygame.NOFRAME)
background = pygame.image.load(image1).convert()
mouse_c=pygame.image.load(image2).convert_alpha()
colorpal = pygame.Surface.get_palette(mouse_c)
print colorpal
What you want to do is going to require a lot of pixel level work, so I recommend that you use a pygame.PixelArray object for direct pixel access of the surface(s).
For what you specifically want to do, it sounds like you could use the pygame.PixelArray.replace() method.
You can get individual pixels on image surfaces by using theget_atmethod of Pygame surfaces - as inmouse_c.get_at((0,0)).
This is strictly what you are asking for -- but it won't suit any real world needs, as it is extremely, and I am saying extremely, slow to process all pixels of an image calling just this.
You could take the image buffer withget_bufferand interpret the data there, raw, or pass the buffer along to a function written in native code to get some speed.
Still, if your goal is to replace a color by another in real time you can resort to use indexed images - that way, each image will have a color table, you just modify,say, the color number 10 to be 0,0,255, and as you render the image, all occurrences of that color become blue. This is fast -- not as efficient as back in the 8 bit video-games time when this was done by hardware -- but it will be orders of magnitude faster any substitutions you try to make in pure Python code.