Accueil > Technique > Informatique > Python > Cinéma ascii > Le roflcopter
Le roflcopter
mardi 2 avril 2019, par
Ancêtre de l’Ascii art animé, il méritait largement une version python, ainsi que quelques « adaptations » maison du même tonneau.
« The » original
ROFL ROFL ROFL ROFL ROFL ROFL ROFL ...
Un screencast
de sa version python 3, dans un terminal ouvert avec 80 caractères de large [1].
ROFL ROFL ROFL ROFL ROFL ROFL ROFL ...
Et, en avant première !
le screencast du ROFL PLANE !!!
Et pour les casaniers des années 60
en hommage à Fat’s Freddy cat, le screencast du ROFL FLYING CAT !!!
Et, merveille technologique
la ROFL FLYING MOTO !!!
Le fichier
C’est cette version, que vous trouverez dans le fichier ci-dessous. Déchargez le et en console, entrez :
~$ unzip rolfcopter.zip
~$ cd roflcopter
~/rolfcopter$ python3 roflcopter.py
Choisissez le (c)opter, le (p)lane ou le (f)lying cat. Difficile de faire plus facile !
- MORTIMER DANS LA SPHÈRE QUI BAIGNE DANS UNE ÉTRANGE ET TERRIFIANTE LUEUR VIOLETTE
DANS LE rofl copter SPHERIQUE QUI BAIGNE MAINTENANT DANS UNE ÉTRANGE LUEUR VIOLETTE, MORTIMER, L’ESPRIT HANTÉ D’IMAGES TERRIFIANTES, S’EST AFFALÉ, INERTE SUR SON SIÈGE ... [2]
et le diabolique professeur Miloch de s’écrier sardoniquement :
- Le sardonique professeur Miloch qui rit diaboliquement
BON VOYAGE, CHER LECTEUR, BON VOYAGE ... HAHAHAHA !
Sources
code
roflcopter.py :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fileencoding=utf-8
#
# sans titre.py
#
# Copyright 2019 Robert Sebille <robert@sebille.name>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
import time as t
from couleurs import Csrv
from couleurs import Ccxy2, Ccls
from couleurs import dessine_carre
sep = '#'
if __name__ == '__main__':
# Pub debian
print(Ccls + Ccxy2(0, 0))
with open('debian_pub_en.txt') as d:
p = d.readlines()
for l in p:
print(l, end='')
t.sleep(2)
print(Ccls + Ccxy2(0, 1))
rep = ""
while rep not in ["c", "p"]:
rep = input("COPTER or PLANE [C or P] ?")
rep = rep.lower()
if rep == "c":
engine = " COPTER"
fileengine = "roflcopter"
if rep == "p":
engine = " PLANE"
fileengine = "roflplane"
print(Ccls)
dessine_carre((2, 2), (25, 10), Csrv, " ", 0)
print(Ccxy2(5, 5) + "ROFL" + engine)
print(Ccxy2(5, 6) + "python3 version")
t.sleep(3)
# lecture des données
with open(fileengine) as c:
liste = c.readlines()
s = "".join(liste)
liste = s.split(sep)
myframes = []
for i in liste:
myframes.append(i.split("\n"))
# Initialisation
sequence = 0
dep = -20
for f in myframes:
print(Ccls)
for l in range(len(f)):
print(Ccxy2(0, 2 + l) + "" + f[l], end='')
print("+----------------------+")
print("[ ROFL " + engine + "!!! ]")
print("+----------------------+")
t.sleep(2)
print(Ccxy2(8, 1) + "ROFL" + engine + " engine start")
t.sleep(1)
while True:
try:
# Joue le film et imprime les infos
no_myframe = 0
for f in myframes:
print(Ccls)
for lig in range(len(f)):
if dep >= 0:
depl = dep
else:
depl = 0
message = ""
if dep >= -4 and dep <= 0:
message = "ROFL" + engine + " takeoff"
if dep >= 42 and dep <= 46:
message = "ROFL" + engine + " asks to land"
if dep >= 80 and dep <= 83:
message = " ROFL" + engine + " landed"
if lig == 0:
print(Ccxy2(8 + depl, 1) + message)
if dep < 0:
print(Ccxy2(0 + depl, 2 + lig) + "" + f[lig], end='')
else:
print(Ccxy2(0 + depl, 2 + lig) + "" + f[lig])
# Infos complémentaires durant le film, sinon à la fin du film
if sequence > 120:
print("+---------------------------------------------\
--------+")
print("| We hope you enjoyed this little ROFL" + engine +
" flight! |")
print("+---------------------------------------------\
--------+")
print("ROFL COPTER, https://fr.wikipedia.org/wiki/\
Art_ASCII")
exit("Bye ...")
else:
print("+----------------------+")
print("[ ROFL" + engine + "!!! ]")
print("+----------------------+")
print("Sequence: " + str(sequence) + " Frame: " +
str(no_myframe) + "\nEnd = CTRL+C")
no_myframe += 1
t.sleep(0.10)
sequence += 1
dep += 1
# Interception de CTRL+C
except KeyboardInterrupt:
print("\nCTRL + C received")
print("Bye ...")
input("Press Enter to stop")
exit()
# local encoding
# import sys
# print(sys.getdefaultencoding())
couleurs.py :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fileencoding=utf-8
#
# sans titre.py
#
# Copyright 2019 Robert Sebille <robert@sebille.name>
#
# This program is free software; you can redistribute it and/orm"odify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# m"ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# m"A 02110-1301, USA.
#
#
###############
# Version 1.0 #
###############
# ref: https://gitlab.com/dslackw/colored
# imports
# from couleurs import Csrs, Csbr, Csd, Csu, Csbl, Csrv, Csn
# from couleurs import Cfba, Cfbu, Cfr, Cfy, Cfc, Cfg, Cfm, Cfw, Cfrs
# from couleurs import Cbba, Cbbu, Cbr, Cby, Cbc, Cbg, Cbm, Cbw, Cbrs
# from couleurs import Ccxy1, Ccxy2, Ccu, Ccf, Ccb, Ccd, Ccls, Ccll
# from couleurs import dessine_carre
Csrs = "\033[0m" # reset all (colors and brightness)
Csbr = "\033[1m" # bright
Csd = "\033[2m" # dim (looks same as normal brightness)
Csu = "\033[4m" # UNDERLINED
Csbl = "\033[5m" # BLINK,
Csrv = "\033[7m" # REVERSE
Csn = "\033[22m" # normal brightness
# FOREGROUND:
Cfba = "\033[30m" # black
Cfr = "\033[31m" # red
Cfg = "\033[32m" # green
Cfy = "\033[33m" # yellow
Cfbu = "\033[34m" # blue
Cfm = "\033[35m" # magenta
Cfc = "\033[36m" # cyan
Cfw = "\033[37m" # white
Cfrs = "\033[39m" # reset
# BACKGROUND
Cbba = "\033[40m" # black
Cbr = "\033[41m" # red
Cbg = "\033[42m" # green
Cby = "\033[43m" # yellow
Cbbu = "\033[44m" # blue
Cbm = "\033[45m" # magenta
Cbc = "\033[46m" # cyan
Cbw = "\033[47m" # white
Cbrs = "\033[49m" # reset
# cursor positioning
def Ccxy1(coords): # position cursor at x across, y down
return "\033["+str(coords[1])+";"+str(coords[0])+"H"
def Ccxy2(x, y): # position cursor at x across, y down
return "\033["+str(y)+";"+str(x)+"f"
def Ccu(n):
return "\033["+str(n)+"A" # move cursor n lines up
def Ccd(n):
return "\033["+str(n)+"B" # move cursor n lines down
def Ccf(n):
return "\033["+str(n)+"C" # move cursor n characters forward
def Ccb(n):
return "\033["+str(n)+"D" # move cursor n characters backward
# clear the screen
Ccls = "\033[2J" # clear the screen
# clear the line
Ccll = "\033[K" # clear the line
def dessine_carre(hg, bd, coul=Csrv, car='·', bordure=True):
"""dessine_carre(hg, bd, coul=Csrv, car='·') dessine un rectangle,
et retourne un dict avec les param du rectangle
"""
dictparam = {
'coinexthg': hg,
'coinextbd': bd,
'coinexthd': (bd[0], hg[1]),
'coinextbg': (hg[0], bd[1]),
'coininthg': (hg[0] + 1, hg[1] + 1),
'coinintbd': (bd[0] - 1, bd[1] - 1),
'coininthd': (bd[0] - 1, hg[1] + 1),
'coinintbg': (hg[0] + 1, bd[1] - 1),
'hauteur': bd[1] - hg[1] + 1,
'longueur': bd[0] - hg[0] + 1,
'limiteg': hg[0],
'limited': bd[0],
'limiteh': hg[1],
'limiteb': bd[1]
}
if bordure:
bhb = "-"
bgd = '|'
coin = '+'
else:
bhb = car
bgd = car
coin = car
for j in range(0, dictparam['hauteur']):
for i in range(0, dictparam['longueur']):
#print(i)
if j == 0 or j == (dictparam['hauteur'] - 1):
print(coul + Ccxy2(hg[0], hg[1] + j) + coin + bhb*(dictparam['longueur']-2) + coin, sep='', end='')
else:
print(Ccxy2(hg[0] + i, hg[1] + j), sep='', end='')
if i == 0 or i == (dictparam['longueur'] - 1):
print(coul + bgd + Csrs, sep='', end='')
else:
print(car, sep='', end='')
print()
#if j == 0 or j == (dictparam['hauteur'] - 1):
# print(coul, sep='', end='')
print(Csrs, end='')
return dictparam
if __name__ == '__main__':
pass
données
roflcopter :
:LOL:ROFL:ROFL A L /---------- O === []\ L \ \ \_________ ] I I ----------/ # ROFL:ROFL:LOL: A /---------- LOL=== []\ \ \ \_________ ] I I ----------/
roflplane :
l ,-b o)__ f | |_,.,---|/--0._ o ''' r... `-.r `--- -..,' _'o: `-..._____,,..-' l / \ f lol o r # r ,-\ (o __ o | |_,.,---|/--0._ f ''' ,... `-.l `--- -..,' _'o: `-..._____,,..-' r / \ o lol f l
roflflyingcat :
ROFL:ROFL:LOL: _,,_ L /'' '''\ /\,/\ O |_;;;,, '=( °t° )= L \._,,,_)\._,;,_\) # :LOL:ROFL:ROFL _,,_ /'' '''\ /\,/\ LOL|_;;;,, '=( -t- )= \._,,,_)\._,;,_\)
roflflyingmoto :
__ LOL LOL / R\ _\__/ LOL / \ __ R ___/ _@==\/_o| :\_\__|\___ /_ \\ _ \-/\./\ //_o|/\./\ \/_\/ ---' \/_\/ # ROFL __ ROFL / R\ _\__/ O / \ __ R ___/ _@==\/_o| :\_\__|\___ /_ \\ _ \-/_|_\ //_o|/_|_\ \_|_/ ---' \_|_/ # __ / R\ F _\__/ ROFL O / \ __ R ___/ _@==\/_o| :\_\__|\___ /_ \\ _ \-/\./\ //_o|/\./\ \/_\/ ---' \/_\/ # __ L / R\ LOL F _\__/ O / \ __ R ___/ _@==\/_o| :\_\__|\___ /_ \\ _ \-/_|_\ //_o|/_|_\ \_|_/ ---' \_|_/
debian_pub_en.txt :
_,met$$$$$gg. ,g$$$$$$$$$$$$$$$P. | | __| _ \ ,g$$P"" """Y$$.". | |\__ \ __/ ,$$P' `$$$. \__,_|____/\___| ',$$P ,ggs. `$$b: `d$$' ,$P"' . $$$ _, _, ,'`. $$P d$' , $$P `$$' `$$' `. ,' HEX $$: $$. - ,d$$' $$ $$ `' 64 65 62 69 61 6E $$; Y$b._ _,d$P' $$ $$ _, _ Y$$. `.`"Y$$$$P"' ,d$$$g$$ ,d$$$b. $$,d$$$b.`$$' g$$$$$b.`$$,d$$b. `$$b "-.__ ,$P' `$$ ,$P' `Y$. $$$' `$$ $$ "' `$$ $$$' `$$ `Y$$b $$' $$ $$' `$$ $$' $$ $$ ,ggggg$$ $$' $$ `Y$$. $$ $$ $$ggggg$$ $$ $$ $$ ,$P" $$ $$ $$ `$$b. $$ ,$$ $$. $$ ,$P $$ $$' ,$$ $$ $$ `Y$$b. `$g. ,$$$ `$$._ _., $$ _,g$P' $$ `$b. ,$$$ $$ $$ `"Y$b._ `Y$$P'$$. `Y$$$$P',$$$$P"' ,$$. `Y$$P'$$.$$. ,$$. `""""
Voir en ligne : Le roflcopter
[1] Le script fonctionne mieux dans un terminal ouvert avec 80 caractères de large.
[2] Le piège diabolique, plagiat de la page je ne sais plus combien ;)