-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawer.py
49 lines (46 loc) · 1.67 KB
/
drawer.py
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
from colored import fg,bg,attr
from console import console
import os, sys
font_size = [8.2,15.5]
class canvas:
def __init__(self,width,height):
self.sp = (width*font_size[0],height*font_size[1])
self.width, self.height = width, height
self.changed = True
self.pixels = [[" " for i in range(self.width)] for i in range(self.height)]
console.set_size(self.sp[0]+30,self.sp[1]+10)
def clear(self):
# os.system("cls")
print("\033[H\033[J",end="")
def fill(self,symbol=" ",update=True):
self.pixels = [[symbol for i in range(self.width)] for i in range(self.height)]
self.changed = True
if update: self.update()
def update(self):
self.changed = False
out = ""
for y in self.pixels:
for x in y:
out += x
out += "\n"
self.clear()
print(out,end="")
def set(self,x,y,symbol,update=True):
if x < self.width and y < self.height:
self.pixels[y][x] = symbol
self.changed = True
if update: self.update()
def write(self,x,y,text,update=True):
self.changed = True
for n,s in enumerate(text):
self.set(x+n,y,s,False)
if update: self.update()
def get(self,x,y):
return self.pixels[y][x]
def all(self):
return self.pixels
def get_mouse_position(self):
return (console.get_mouse_position()[0]/self.sp[0]*self.width,
(console.get_mouse_position()[1]/(self.sp[1]-font_size[1]*4)*self.height))
def color_symbol(color):
return fg(color)+bg(color)+"#"+attr('reset')