Python war-eeun
21 a viz Gwengolo 2022 -- Barzhonegoù Ankivil
Araok kregiñ gant elfennoù grafik gant Processing eo mad gwelet diazezoù ar yezh Python en un doare simpl.
Ar poelladenn kentañ graet ganeomp a zo un ganer (« générateur ») barzhonegoù karantez ankivil, gant listennoù chadennoù lizherennek, ar modul random
hag ar foñksion choice
.
# Barzhoneg ankivil Gweltaz
import random
tud = ["Marijannig", "Lena", "Stéphanie", "Bruno", "Erel", "Raoul"]
anviou_gwann = ["brav", "souezhus", "pinvidik", "koant", "sebezus", "bammus", "spontus", "mat", "mud", "spontet", "didrouz", "sot pitil", "bamet", "brein", "marvan trum", "da leñvañ", "bout"]
l_anv = ["ul loa", "al loar", "an heol", "ar mor", "un draezenn", "ur poupinell", "mammig", "tadig", "an aotroù prezidant", "ar bed a-bezh"]
lodennou_korf = ["fri", "zaoulagad", "zaouarn", "fas", "vruched", "dreid", "zaoulin", "vlev", "vuzelloù"]
verbou_eil_gour = ["besketez", "lammez", "c'hoariez", "mousc'hoarzez", "leñvez", "dañsez", "kanez"]
anviou_lech = ["e Pariz", "war ar maez", "dindan ar gwele", "war enezenn Eusa", "e kreiz an noz"]
pr_verbou = ["spont", "kouezh", "varv", "kan", "huch", "tañs ar polka", "tres stummoù kalon", "soñj ennout"]
anviou_liester = ["ar pesked", "an aelioù", "ar c'houmoul", "an diamañtoù", "an tonioù karantez"]
def barzhoneg():
den = random.choice(tud)
adj = random.choice(anviou_gwann)
adj2 = random.choice(anviou_gwann)
adj3 = random.choice(anviou_gwann)
anv = random.choice(l_anv)
anv2 = random.choice(l_anv)
anv3 = random.choice(l_anv)
lodenn_korf = random.choice(lodennou_korf)
verb = random.choice(anviou_gwann)
veg = random.choice(verbou_eil_gour)
anv_l = random.choice(anviou_lech)
pr_verb = random.choice(pr_verbou)
anv_liester = random.choice(anviou_liester)
barzhoneg = ""
barzhoneg += "Oh " + den + ", " + adj + "out evel " + anv + " " + adj3 + "!\n"
barzhoneg += f"Pa velan da {lodenn_korf} ken {adj2} hag {anv2}\n"
barzhoneg += "e choman {} evel {}\n".format(verb, anv3)
barzhoneg += "Pa {} {} e {} tout {}\n".format(veg, anv_l, pr_verb, anv_liester)
return barzhoneg
##
## Amañ e vez galvet ar fonksion "barzhoneg" evit genel ur barzhoneg ankiviel
## hag e vez skrivet an dioc'h en terminal
##
print(barzhoneg())
##
## Da-heul e vez skrivet 1000 barzhoneg ankivil disheñvel en ur fichennaoueg
## anvet "levr.txt"
##
f = open("levr.txt", "w")
for i in range(1001):
f.write(barzhoneg())
f.write("\n")
f.close()
Un nebeut disoc’hoù :
Oh Marijannig , souezus out evel tadig brav !
Pa velan da zaoulagad ken pinvidik hag al loar
e choman mud evel ur poupinel
Oh Raoul , pinvidik out evel an aotroù prezidant mad !
Pa velan da zaoulagad ken mad hag ur poupinel
e choman mud evel ar mor
Oh Stéphanie , bamus out evel ul loa brav !
Pa velan da fas ken brav hag ar mor
e choman da leñvañ evel ul loa
# Barzhoneg ankivil Matilin
import random
def barzhoneg():
l_adj = ["brav", "amogus", "souezhus", "kreñv"]
anv = ["Gweltaz", "Mammig", "urzhiataer", "Top1 eus LoL"]
lodenn_korf = ["da fri", "da skouarn", "da zaoulin", "da pellgomz nevez eus Wish", "da poelladenn Peeeeeeeeeeemdas"]
lodenn_douar = ["al leur", "ma zaouarn", "an daol", "da fri"]
verb = ["lammat", "kouezhat", "c'hoari", "kousket", "ijin", "marvel"]
mare = ["d'an noz", "d'ar sadorn", "d'al lun vintin d'a 6eur ha kart eus ar 17 a viz Gwengolo 2021"]
objed = ["d'a evaj diffenet", "d'a chokolad eus Arabia Saoudet aloubet", "d'ar poupinel eus Gweltaz"]
y = random.choice(anv)
x = random.choice(l_adj)
f = random.choice(lodenn_korf)
z = random.choice(lodenn_douar)
e = random.choice(verb)
g = random.choice(mare)
o = random.choice(objed)
print("Oh, ma", y, "moutik, na pegen", x, "out !")
print("Pa velan", f, ", kouezh a ran war", z, ".")
print("Ijin a ran ac'hanout o", e, ",", g, ", gant", o,"en d'a zaouarn.")
Un disoc’h :
Oh, ma urzhiataer moutik, na pegen amogus out !
Pa velan da poelladenn Peeeeeeeeeeemdas , kouezh a ran war an daol .
Ijin a ran ac’hanout o marvel , d’al lun vintin d’a 6eur ha kart eus ar 17 a viz Gwengolo 2021 , gant d’a chokolad eus Arabia Saoudet aloubet en d’a zaouarn.
# Barzhoneg ankivil Paolig
import random
l_adj = ["brav","souezus","pinvidik","sebezus","bamus","spontus", "MAAAAAAAAAAAAD","koant","sexy"]
l_anv = ["an heol","un draezenn","gweltaz", "al loar","d'on","un urzhiataer","un dra"]
lodennou_korf = ["fri", "zaoulagad","zaouarn","fas","vruched","vruched","zreid"]
l_verbou = ["marvan.","lipan al leur!","sachan da diouskouarn!!!!","zan war python!"]
# Diskouez an niver a barzhoneg disheñvel a c'heller kaout
print(len(l_adj)*len(l_adj)*len(l_anv)*len(l_anv)*len(lodennou_korf)*len(l_verbou)*len(l_verbou)*len(l_anv))
def barzhoneg():
adj = random.choice(l_adj)
adj2 = random.choice(l_adj)
anv = random.choice(l_anv)
anv2 = random.choice(l_anv)
anv3 = random.choice(l_anv)
verb = random.choice(l_verbou)
verb2 = random.choice(l_verbou)
lodenn_korf = random.choice(lodennou_korf)
print("o iwan, na pengent", adj , "out evel ",anv,"!")
print("pa velan da ",lodenn_korf, "ken",adj2, "hag",anv2, "e",verb)
print("e",verb,"evel",anv3)
barzhoneg()
Disoc’hoù :
o iwan, na pengent brav out evel d’on !
pa velan da zaoulagad ken pinvidik hag an heol e marvan.
e marvan. evel gweltaz
o iwan, na pengent koant out evel d’on !
pa velan da zaoulagad ken MAAAAAAAAAAAAD hag un draezenn e zan war python!
e zan war python! evel gweltaz
Programiñ grafikel gant Python ha Processing
5 a viz Here 2022 -- Tresañ stummoù diazez gant Processing
def setup():
size(500, 500)
def draw():
background("#F2CF84")
offset = 10 * sin(frameCount * 0.05)
fill(255)
circle(250, 250, 300) # Dremm
fill(255)
ellipse(180, 220, 60, 30) # Lagad kleiz
fill(0)
circle(180 + offset, 220, 20) # Mab-lagad kleiz
fill(255)
ellipse(320, 220, 60, 30) # lagad dehou
fill(0)
circle(320 + offset, 220, 20) # Mab-lagad dehou
fill("#DE65C2")
rect(200, 320, 100, mouseY) # BEG
fill("#8E65DE")
triangle(220, 290, 270, 290, 250, 240)
# Hini Matilin
def setup():
size(500,500)
def draw():
offset = 12 * sin(frameCount * 0.09)
background("#540FF7")
fill("#EDB1E7")
circle(250, 250, 300) #dremm
fill(127)
ellipse(180, 220, 60, 75) #lagad kleiz
fill("#B1EDE5")
circle(180 + offset, 220, 30) #pupille kleiz
fill(0)
circle(180 + offset, 220, 20) #eil pupille kleiz
fill(127)
ellipse(320, 220, 60, 75) #lagad dehoù
fill("#B1EDE5")
circle(320 + offset, 220, 30) #pupille dehoù
fill(0)
circle(320 + offset, 220, 20) #eil pupille dehoù
fill(52, 784, 632)
rect(200, 320, 100, mouseY) #beg
fill(0)
triangle(220, 270, 270, 280, 250, 230) #fri
Trede dae : Ar skeudenn kuzh
Setu ur skeudenn binarel (gant 2 dalvoud nemetken : 0 ha 1) kuzhet en ul listennad :
skeudenn = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Ar skeudenn-se a ra 24 pixels war 24 pixels.
Deoc’h d’ober ur programm bihan evit lakaat war wel ar skeudenn kuzhet.
Tips
Evit lenn un elfenn en ul listenn e c’heller ober evel-se :
elfenn_kentan = skeudenn[0]
eil = skeudenn[1]
...
# Kod Matilin (difaziet)
skeudenn = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,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y = 0
for n in skeudenn:
if n == 0:
# tresañ un dra bennak el lec'h mat (hervez x ha y)
noStroke()
fill(0)
rect(x, y, 1, 1)
else:
# tresañ er memes lec'h met gant un liv all
noStroke()
fill(255)
rect(x, y, 1, 1)
# kreskiñ x pe/ha y
x = x + 1
if x >= 24:
x = 0
y = y + 1
# kreskiñ x pe/ha y
if y > 24:
noLoop()
Pempvet dae : bevaat doare DVD
Grit un animasioñs evel war ar video da-heul (hep ar cheñch liv): https://www.youtube.com/watch?v=5mGuCdlCcNM
# Kod Paolig
"""
Evezhiadennoù:
* Brav !
* Gwelloc'h cheñch talvoud ar variennoù tizh
kentoc'h eget lakaat frameRate(1000) XD
* Domaj eo e stok ar c'helc'h ouzh ar vordoù nemet pa'z eo hanter er maez dija.
Posubl e vefe kemer e kont ment ar c'helc'h evit jediñ peur zo ur stokadenn.
""""
Vx = 3
Vy = 1.2
r = random(0, 255)
g = random(0, 255)
b = random(0, 255)
def setup():
global x, y
size(250, 250)
x = width / 2
y = height / 2
frameRate(1000)
def draw():
background(0)
global x, y, Vx, Vy, r, g, b
x += Vx
y += Vy
fill(r, g, b)
circle(x, y, 20)
#print(r)
if x > width or x < 0:
Vx = Vx * -1
r = random(0, 255)
g = random(0, 255)
b = random(0, 255)
if y > height or y < 0:
Vy = Vy * -1
r = random(0, 255)
g = random(0, 255)
b = random(0, 255)
C’hwervet dae : c’hoari un teul son
Setu penaos kargañ ur restr son gant Processing.py ha c’hoari anezhañ.
add_library('sound')
def setup():
size(500, 500)
global son # Evit ma vefe tu tizout ar varienn deus pep lec'h er program
son = SoundFile(this, "soundfile.wav") # Kargañ ar restr son er varienn
son.play()