-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.py
More file actions
executable file
·104 lines (84 loc) · 2.74 KB
/
Copy pathmatrix.py
File metadata and controls
executable file
·104 lines (84 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Esto un programa para simular lo que se
# ve en las pantallas de las computadoras en
# la película "Matrix" que creo esta basado
# en algo que pasa con los créditos en la
# pélicula "Ghost in the Shell". Este es
# un programa que aprendí a hacer en Turbo
# Basic con un amigo de ITESA que se llama
# Emmanuel Abreu (satanclos) ...
# The Matrix by Pablo Mercader Alcántara
import curses
import time
import math
import random
import sys
# inicializando
maxY, maxX = 0, 0
maxE = 20
# caracteres que no se deberían usar porque estan en blanco o son caracteres de control.
excepciones = [0, 3]
class claseColumna:
def __init__(self):
self.reset()
def reset(self):
global maxY, maxX, maxE
self.col = random.randrange(maxX)
self.ya = 0
self.yf = random.randrange(maxY)
self.tono = random.randrange(1, 5)
self.espera = random.randrange(1, maxE)
def seleccionarCar():
return chr(random.randrange(32, 255))
def escenaTitulo(stdscr):
global maxY, maxX
texto = "The Matrix"
x = math.floor((maxX - len(texto))/ 2)
y = math.floor(maxY / 2)
secuencia = [4, 3, 2, 1, 2, 3]
for color in secuencia:
stdscr.addstr(y, x, texto, curses.color_pair(color))
if (color == 1):
curses.flash()
stdscr.refresh()
time.sleep(0.1)
def escenaTexto(stdscr):
global maxY, maxX
totalCar = 255
ccol = 10
columnas = []
for i in range(ccol):
columnas += [claseColumna()]
while (True):
for col in columnas:
if col.ya < col.yf:
car = seleccionarCar()
stdscr.addstr(col.ya, col.col, car,
curses.color_pair(col.tono))
stdscr.refresh()
time.sleep(0.005)
col.ya += 1
elif col.espera > 0:
col.espera -= 1
else:
col.reset()
if (stdscr.getch() != curses.ERR):
break
def matrixMain(stdscr):
global maxY, maxX
# el cuerpo
# por alguna razón desconocida no puedo desaparecer el cursor en windows (cygwin)
if ("linux" in sys.platform):
curses.curs_set(0)
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_BLACK)
stdscr.leaveok(1)
stdscr.nodelay(1)
maxY, maxX = stdscr.getmaxyx()
escenaTitulo(stdscr)
escenaTexto(stdscr)
# la función wrapper hace las inicializaciones y finalizaciones necesarias.
curses.wrapper(matrixMain)