Advertisement
tuomasvaltanen

Untitled

Nov 11th, 2024 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. # Introduction to Programming, 11.11.2024, external modules
  2. print("Welcome!")
  3.  
  4. # NEW FILE
  5. # see installation instructions in the external module materials
  6. from colorama import Fore, Back, Style
  7.  
  8. # Change the text color to magenta
  9. print(Fore.MAGENTA + "Different text color!")
  10.  
  11. # since we didn't change anything, same colors apply
  12. print("Same rules for colors still apply!")
  13.  
  14. # change also the background, the text color remains the same
  15. # (since we didn't change the foreground)
  16. print(Back.LIGHTBLACK_EX + "Change the background too!")
  17.  
  18. # reset all back to default
  19. print(Style.RESET_ALL)
  20. print("Back to normal text representation!")
  21.  
  22. # NEW FILE
  23.  
  24. from colorama import Fore, Back, Style
  25.  
  26. # ask user for a number
  27. number = input("Give a number:\n")
  28. number = int(number)
  29.  
  30. # check if user gave a positive number (or negative)
  31. if number >= 0:
  32.     print(Fore.BLACK + Back.LIGHTGREEN_EX + "Positive number!")
  33. else:
  34.     print(Fore.BLACK + Back.LIGHTRED_EX + "Negative number...")
  35.  
  36. # return to default style and thank the user
  37. print(Style.RESET_ALL + "\nThank you for using this application!")
  38.  
  39. # NEW FILE
  40.  
  41. # install the module "Pillow" instead of PIL
  42. from PIL import Image, ImageDraw
  43.  
  44. # create a new image
  45. img = Image.new('RGB', (500, 300), color=(73, 109, 137))
  46.  
  47. # create a drawing object
  48. d = ImageDraw.Draw(img)
  49.  
  50. # draw some text into the picture
  51. d.text((10, 10), "Hello World", fill=(255, 255, 0))
  52.  
  53. # save image to file
  54. img.save('pil_text.png')
  55.  
  56. # NEW FILE
  57.  
  58. # install the module "Pillow" instead of PIL
  59. from PIL import Image, ImageDraw
  60.  
  61. # create a new image
  62. img = Image.new('RGB', (500, 300), color=(73, 109, 137))
  63.  
  64. # create a drawing object
  65. d = ImageDraw.Draw(img)
  66.  
  67. # the logic is this:
  68. # xy = starting point is in point 100, 100 => bottom right
  69. # is in point 200, 200
  70. # means the ellipse size is 100 x 100 (200 - 100 = 100)
  71. d.ellipse((100, 100, 200, 200), fill=(208, 141, 240), outline=(0, 0, 0))
  72.  
  73. # "draw" some text into the picture
  74. # in mathematics we are used to start drawing (0, 0)
  75. # from bottom left, in computer graphics 0, 0 is top left
  76. # e.g. 100, 200 means literally:
  77. # 100 pixels to right, 200 pixels down
  78. d.text((10, 10), "Hello World", fill=(255, 255, 0))
  79.  
  80. # save image to file
  81. img.save('pil_text.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement