Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python-moduulien asentaminen ja käyttäminen
- # kokeillaan värjätä konsolitekstiä
- from colorama import Fore, Back, Style
- print(Fore.LIGHTYELLOW_EX + 'Eri väristä tekstiä!')
- # jos halutaan rivinvaihto pois, laitetaan RESET_ALL aiemman rivin loppuun
- print(Back.LIGHTBLACK_EX + 'Eri taustavärikin!' + Style.RESET_ALL)
- # palautetaan kaikki normaaliksi
- # print(Style.RESET_ALL)
- print('Nyt ollaan taas normaalissa tilassa!')
- # ESIMERKKI 2, colorama
- from colorama import Fore, Back, Style
- number = input("Anna numero:\n")
- number = int(number)
- # muissa ohjelmointikielissä tehdään yleensä näin
- # if number >= 0 and number <= 10:
- # onko luku välillä 0-10
- if 0 <= number <= 10:
- print(Fore.LIGHTGREEN_EX + Back.GREEN + "Luku OK!")
- else:
- print(Fore.BLACK + Back.LIGHTRED_EX + "Luku ei ole OK...")
- print(Style.RESET_ALL + "Kiitos ohjelman käytöstä!")
- # Pillow / PIL, kuvien piirtäminen
- from PIL import Image, ImageDraw
- # tehdään uusi kuva, 300 x 300 pikseliä
- img = Image.new('RGB', (300, 300), color=(73, 109, 137))
- # alustetaan ImageDraw -objekti, jolla voi piirtää
- d = ImageDraw.Draw(img)
- # KAIKKI PIIRTÄMINEN TÄHÄN VÄLIIN
- # piirretään teksti koordinaattiin 10,10, keltaisella värillä
- d.text((10, 10), "Hello World", fill=(255, 255, 0))
- # piirretään ympyrä
- d.ellipse((100, 100, 200, 200), fill=(255, 0, 0), outline=(0, 0, 0))
- # LOPUKSI TALLENNETAAN KUVATIEDOSTO, eli lopputulos
- # tallennetaan lopputulos tiedostoon
- img.save('pil_text.png')
Add Comment
Please, Sign In to add comment