tuomasvaltanen

Untitled

Oct 29th, 2021 (edited)
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. # Python-moduulien asentaminen ja käyttäminen
  2.  
  3. # kokeillaan värjätä konsolitekstiä
  4.  
  5. from colorama import Fore, Back, Style
  6. print(Fore.LIGHTYELLOW_EX + 'Eri väristä tekstiä!')
  7.  
  8. # jos halutaan rivinvaihto pois, laitetaan RESET_ALL aiemman rivin loppuun
  9. print(Back.LIGHTBLACK_EX + 'Eri taustavärikin!' + Style.RESET_ALL)
  10.  
  11. # palautetaan kaikki normaaliksi
  12. # print(Style.RESET_ALL)
  13. print('Nyt ollaan taas normaalissa tilassa!')
  14.  
  15. # ESIMERKKI 2, colorama
  16.  
  17. from colorama import Fore, Back, Style
  18.  
  19. number = input("Anna numero:\n")
  20. number = int(number)
  21.  
  22. # muissa ohjelmointikielissä tehdään yleensä näin
  23. # if number >= 0 and number <= 10:
  24.  
  25. # onko luku välillä 0-10
  26. if 0 <= number <= 10:
  27.     print(Fore.LIGHTGREEN_EX + Back.GREEN + "Luku OK!")
  28. else:
  29.     print(Fore.BLACK + Back.LIGHTRED_EX + "Luku ei ole OK...")
  30.  
  31. print(Style.RESET_ALL + "Kiitos ohjelman käytöstä!")
  32.  
  33. # Pillow / PIL, kuvien piirtäminen
  34.  
  35. from PIL import Image, ImageDraw
  36.  
  37. # tehdään uusi kuva, 300 x 300 pikseliä
  38. img = Image.new('RGB', (300, 300), color=(73, 109, 137))
  39.  
  40. # alustetaan ImageDraw -objekti, jolla voi piirtää
  41. d = ImageDraw.Draw(img)
  42.  
  43. # KAIKKI PIIRTÄMINEN TÄHÄN VÄLIIN
  44.  
  45. # piirretään teksti koordinaattiin 10,10, keltaisella värillä
  46. d.text((10, 10), "Hello World", fill=(255, 255, 0))
  47.  
  48. # piirretään ympyrä
  49. d.ellipse((100, 100, 200, 200), fill=(255, 0, 0), outline=(0, 0, 0))
  50.  
  51. # LOPUKSI TALLENNETAAN KUVATIEDOSTO, eli lopputulos
  52.  
  53. # tallennetaan lopputulos tiedostoon
  54. img.save('pil_text.png')
Add Comment
Please, Sign In to add comment