사용자 도구

사이트 도구


plotille:rotating_cube

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
plotille:rotating_cube [2020/06/17 13:15] rex8312plotille:rotating_cube [2024/03/23 02:42] (현재) – 바깥 편집 127.0.0.1
줄 9: 줄 9:
 # drawille의 rotating cube를 plotille를 사용하도록 포팅 # drawille의 rotating cube를 plotille를 사용하도록 포팅
  
-import sys 
 import math import math
-import time 
-from IPython import embed 
 import random import random
-import numpy as np+import sys 
 +import threading 
 +import time 
 +from queue import Queue
  
 +import numpy as np
 import plotille import plotille
 +from IPython import embed
 from plotille import Canvas from plotille import Canvas
  
 +
 +def keyboard(queue):
 +    import platform
 +
 +    if platform.system() == 'Windows':
 +        import msvcrt
 +        from msvcrt import kbhit
 +        from msvcrt import getch
 +    
 +        while True:
 +            if msvcrt.kbhit():
 +                queue.put(msvcrt.getch())
 +    
 +    elif platform.system() == 'Linux':
 +        import curses
 +        import time
 +
 +        stdscr = curses.initscr()
 +        stdscr.refresh()
 +
 +        while True:
 +            queue.put(stdscr.getch())
 +    
  
 class Screen: class Screen:
줄 137: 줄 162:
     # 변환 행렬     # 변환 행렬
     TR = R(2, 3, 5) @ T(0, 0, 0)     TR = R(2, 3, 5) @ T(0, 0, 0)
 +
 +    key = Queue()
 +    threading.Thread(target=keyboard, args=(key,), daemon=True).start()
 +
 +    colors = ['white', 'yellow', 'green', 'blue', 'red']
  
     while True:     while True:
 +        if not key.empty() and key.get() == b' ':
 +            colors = colors[1:] + colors[:1]
 +            
         canvas = Canvas(height=screen.height, width=screen.width)         canvas = Canvas(height=screen.height, width=screen.width)
  
줄 155: 줄 188:
  
         for f in faces:         for f in faces:
-            canvas.line(t[f[0]].x, t[f[0]].y, t[f[1]].x, t[f[1]].y) +            canvas.line(t[f[0]].x, t[f[0]].y, t[f[1]].x, t[f[1]].y, color=colors[0]
-            canvas.line(t[f[1]].x, t[f[1]].y, t[f[2]].x, t[f[2]].y) +            canvas.line(t[f[1]].x, t[f[1]].y, t[f[2]].x, t[f[2]].y, color=colors[0]
-            canvas.line(t[f[2]].x, t[f[2]].y, t[f[3]].x, t[f[3]].y) +            canvas.line(t[f[2]].x, t[f[2]].y, t[f[3]].x, t[f[3]].y, color=colors[0]
-            canvas.line(t[f[3]].x, t[f[3]].y, t[f[0]].x, t[f[0]].y)+            canvas.line(t[f[3]].x, t[f[3]].y, t[f[0]].x, t[f[0]].y, color=colors[0])
  
         screen.write(canvas.plot())         screen.write(canvas.plot())
 +
 </code> </code>
plotille/rotating_cube.1592399736.txt.gz · 마지막으로 수정됨: 2024/03/23 02:38 (바깥 편집)