Skip to content

Instantly share code, notes, and snippets.

@vladignatyev
Created May 22, 2021 14:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladignatyev/4764dd06ab38288ba6a15fb8255f9174 to your computer and use it in GitHub Desktop.
Save vladignatyev/4764dd06ab38288ba6a15fb8255f9174 to your computer and use it in GitHub Desktop.
Elbrus Bootcamp: Back To The 80's Demo
# MIT License
#
# Copyright (c) 2021 Vladimir Ignatev <ya.na.pochte@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import sys
import time
import os
import math
logo = [
'▀▀▀▀▀▀▀▀▀',
' E L B R ',
' U S / ',
' B O O T ',
' C A M P ',
'▄▄▄▄▄▄▄▄▄'
], 9, 6
car = [
' __________ ',
' / \ ',
'▄░░░░░░░░░░░░░░░░░░▄',
'▓o▓o▓░░░░░░░░░░▓o▓o▓',
'████ O O ████'
], 20, 5
palette = ' .oO░▒▓█▄▀▄■▄▀▄█▓▒░Oo. '
blend_flat = blend_default = lambda s, d: d
blend_mix = lambda s, d: palette[(palette.index(s) + palette.index(d)) % len(palette)]
shader_flat = shader_default = lambda x, y, c: c
shader_gradient = lambda x, y, c: palette[(y + palette.index(c)) % len(palette)]
def circle(vram, x, y, r, color, blend=blend_default, shader=shader_default):
boundary_w = (x - 2 * r) if x - 2 * r >= 0 else 0, (x + 2 * r + 1) if (x + 2 * r + 1) < vram[1] else vram[1] - 1
boundary_h = y - r if y - r >= 0 else 0, y + r + 1 if y + r + 1 < vram[2] else vram[2] - 1
for i in range(boundary_w[0], boundary_w[1]):
for j in range(boundary_h[0], boundary_h[1]):
if (((-x + i) // 2) ** 2 + (-y + j) ** 2) <= r ** 2:
vram[0][j][i] = blend(vram[0][j][i], shader(i, j, color))
def rect(vram, x, y, w, h, color, blend=blend_default, shader=shader_default):
for i in range(w):
for j in range(h):
px = x + i
py = y + j
if 0 <= px < vram[1] and 0 <= py < vram[2]:
vram[0][py][px] = blend(vram[0][py][px], shader(i, j, color))
def draw_image(vram, x, y, image, blend=blend_default, shader=shader_flat):
for i in range(image[1]):
for j in range(image[2]):
px = x + i
py = y + j
if 0 <= px < vram[1] and 0 <= py < vram[2]:
vram[0][py][px] = blend(vram[0][py][px], shader(i, j, image[0][j][i]))
t = 1
while 1:
os.system('cls||echo -e \\\\033c') # clear screen
ts = os.get_terminal_size()
w, h = ts.columns, ts.lines
p = w / h
vram = [[' ' for x in range(w)] for y in range(h)], w, h
# Sun
circle(vram, w // 2, h // 2, 20, palette[(t // 2) % len(palette)], blend_mix, shader_gradient)
rect(vram, 0, h // 2, w, h, palette[1])
# City
for i in range(60):
x = i * 4 - 12
hh = (i ** 2 % 29) // 4
y = h // 2 - hh + 1
rect(vram, x, y, 4, hh, palette[6])
x = (i * 4 - 12 + 42) % w
hh = (i ** 2 % 29) // 5
y = h // 2 - hh + 2
rect(vram, x, y, 4, hh, palette[5])
x = (i * 4 - 12 + 17) % w
hh = (i ** 2 % 29) // 7
y = h // 2 - hh + 2
rect(vram, x, y, 4, hh, palette[4])
# Skyscrappers with Elbrus Bootcamp Ads
sx = 8
rect(vram, w // 2 + 40 - sx, h // 2 - 4, 4, 6, palette[7])
rect(vram, w // 2 + 53 - sx, h // 2 - 6, 5, 8, palette[5])
rect(vram, w // 2 + 58 - sx, h // 2 - 7, 5, 9, palette[6])
rect(vram, w // 2 + 43 - sx, h // 2 - 15, 11, 18, palette[4])
draw_image(vram, w // 2 + 44 - sx, h // 2 - 14, logo)
# Road
for i in range(h // 2):
rect(vram, w // 2 + 3 * i, h // 2 + 2 + i, 3, h // 2 - i, palette[0])
rect(vram, w // 2 - 3 * i, h // 2 + 2 + i, 3, h // 2 - i, palette[0])
# Road stripes
for i in range(5):
z = int((((t) + i * 4) // 4) % (h // 2) ** 0.5)
rect(vram, w // 2 + 1, (t % 4) + h // 2 + 2 + z ** 2, 1, z, palette[5])
# Car
draw_image(vram, w // 2 + w // 10 + 4 - (((t // 4) ** 2) % 8), h // 2 + h // 3, car)
for h in range(len(vram[0])):
for w in range(len(vram[0][0])):
sys.stdout.write(vram[0][h][w])
sys.stdout.flush()
time.sleep(0.1)
t += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment