From 1cb6646b81865d1e0d1dbe1c8b9501c916ae570b Mon Sep 17 00:00:00 2001 From: Thxios Date: Sat, 7 Mar 2020 21:26:36 +0900 Subject: [PATCH] . Signed-off-by: Thxios --- src/Brush.py | 2 +- src/Window.py | 8 +++---- src/numpy_test.py | 55 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/Brush.py b/src/Brush.py index 931c6d5..903e5ae 100644 --- a/src/Brush.py +++ b/src/Brush.py @@ -46,7 +46,7 @@ def OnMouseDown(self, clickedPixel, layer: Layer) -> (int, int, int, int): class Brush: - _layer = None + _layer: Layer pencil = _PencilBrush() eraser = _EraserBrush() diff --git a/src/Window.py b/src/Window.py index 9887121..b39b2bb 100644 --- a/src/Window.py +++ b/src/Window.py @@ -15,6 +15,10 @@ class MainWindow: originX, originY = 200, 800 + Brush.SetBrush('Pencil') + # ----- for test ----- + Brush.pencil.SetCurrentColor((255, 0, 127, 255)) + CanvasSection.Setup(originX, 0, w - originX, originY) CanvasSection.SetupCanvas(64, 64) @@ -29,10 +33,6 @@ class MainWindow: mouseButtonCount = len(mouseButton) mouseX, mouseY = 0, 0 mousePreviousX, mousePreviousY = 0, 0 - - Brush.SetBrush('Pencil') - # ----- for test ----- - Brush.pencil.SetCurrentColor((255, 0, 127, 255)) currentSection = None def Run(self): diff --git a/src/numpy_test.py b/src/numpy_test.py index 9e2687c..1f34f7e 100644 --- a/src/numpy_test.py +++ b/src/numpy_test.py @@ -11,17 +11,44 @@ def End(): print(time() - t) -class Boo: - def DoSomething(self): - return - - -class TestClass: - member: [Boo] - - def __init__(self): - self.member = [] - - -a = TestClass() -print(a.member) +def draw(arr, x0, y0, x1, y1): + dx = x1 - x0 + dy = y1 - y0 + e = 0 + if abs(dy) > abs(dx): + if y0 > y1: + x0, x1 = x1, x0 + y0, y1 = y1, y0 + x = x0 + slope = abs(dx / dy) + print(slope) + for y in range(y0, y1 + 1): + arr[x, y] = 1 + print(x, y, e) + e += slope + if e > 0.5: + x += 1 + e -= 1 + else: + if x0 > x1: + x0, x1 = x1, x0 + y0, y1 = y1, y0 + y = y0 + slope = abs(dy / dx) + print(slope) + for x in range(x0, x1 + 1): + arr[x, y] = 1 + print(x, y, e) + e += slope + if e > 0.5: + y += 1 + e -= 1 + + +a = np.zeros((32, 32), dtype=np.int8) +for i in a: + print(*i) +print('------------------------------------') +draw(a, 31, 0, 10, 31) +for i in a: + print(*i)