Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Introduction to Programming, 11.11.2024, external modules
- print("Welcome!")
- # NEW FILE
- # see installation instructions in the external module materials
- from colorama import Fore, Back, Style
- # Change the text color to magenta
- print(Fore.MAGENTA + "Different text color!")
- # since we didn't change anything, same colors apply
- print("Same rules for colors still apply!")
- # change also the background, the text color remains the same
- # (since we didn't change the foreground)
- print(Back.LIGHTBLACK_EX + "Change the background too!")
- # reset all back to default
- print(Style.RESET_ALL)
- print("Back to normal text representation!")
- # NEW FILE
- from colorama import Fore, Back, Style
- # ask user for a number
- number = input("Give a number:\n")
- number = int(number)
- # check if user gave a positive number (or negative)
- if number >= 0:
- print(Fore.BLACK + Back.LIGHTGREEN_EX + "Positive number!")
- else:
- print(Fore.BLACK + Back.LIGHTRED_EX + "Negative number...")
- # return to default style and thank the user
- print(Style.RESET_ALL + "\nThank you for using this application!")
- # NEW FILE
- # install the module "Pillow" instead of PIL
- from PIL import Image, ImageDraw
- # create a new image
- img = Image.new('RGB', (500, 300), color=(73, 109, 137))
- # create a drawing object
- d = ImageDraw.Draw(img)
- # draw some text into the picture
- d.text((10, 10), "Hello World", fill=(255, 255, 0))
- # save image to file
- img.save('pil_text.png')
- # NEW FILE
- # install the module "Pillow" instead of PIL
- from PIL import Image, ImageDraw
- # create a new image
- img = Image.new('RGB', (500, 300), color=(73, 109, 137))
- # create a drawing object
- d = ImageDraw.Draw(img)
- # the logic is this:
- # xy = starting point is in point 100, 100 => bottom right
- # is in point 200, 200
- # means the ellipse size is 100 x 100 (200 - 100 = 100)
- d.ellipse((100, 100, 200, 200), fill=(208, 141, 240), outline=(0, 0, 0))
- # "draw" some text into the picture
- # in mathematics we are used to start drawing (0, 0)
- # from bottom left, in computer graphics 0, 0 is top left
- # e.g. 100, 200 means literally:
- # 100 pixels to right, 200 pixels down
- d.text((10, 10), "Hello World", fill=(255, 255, 0))
- # save image to file
- img.save('pil_text.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement