태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

Spiral number galaxy

Tech 2008. 8. 9. 17:37
http://codingdojo.metaschool.org/5198
http://gall.dcinside.com/list.php?id=programming&no=84262&page=1&search_pos=-80935&k_type=1000

따라해봤음. ㅋㅋㅋ 나의 첫 curses 프로그램임 >_</ 재밌네 ~

import math
import time
import curses

def close_to_center(polar):
    return polar[0] < 1

def get_next_coord(polar):
    r = polar[0]
    theta = polar[1]
    r -= 0.2
    theta += (math.pi / 2.0) + 0.2
    return (r, theta)

def polar_to_euclid(polar):
    r = polar[0]
    theta = polar[1]
    return (int(r * math.cos(theta)), int(r * math.sin(theta)))

def draw(start, center):
    current = start
    i = 1
    while not close_to_center(current):
        pos = polar_to_euclid(current)
        stdscr.addstr(pos[1] + center[1], pos[0]*2 + center[0], "%s" % i, curses.A_NORMAL)
        current = get_next_coord(current)
        i += 1

if __name__ == '__main__':
    try:
        stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        stdscr.keypad(1)
        stdscr.timeout(0)
        r, theta = 0, 0

        while True:
            max_y, max_x = stdscr.getmaxyx()
            center = (max_x/2, max_y/2)
            r = min(center) - 1
            theta += 0.03

            stdscr.clear()
            draw((r, theta), center)
            stdscr.addstr(1, 1, "Ctrl-C to quit")
            time.sleep(0.005)
            stdscr.refresh()
    except KeyboardInterrupt:
        pass
    finally:
        stdscr.keypad(0)
        curses.echo()
        curses.nocbreak()
        curses.endwin()


뱅글뱅글

뱅글뱅글




'Tech' 카테고리의 다른 글

MySQL -> XML: CDATA Sanitize?  (2) 2008.09.26
하위 디렉토리에 있는 모든 .svn 을 날리는 법  (5) 2008.09.11
Spiral number galaxy  (4) 2008.08.09
투명 필름 문제(Scheme)  (4) 2008.08.01
Statement vs Expression  (4) 2008.07.22
emacs: switch indentation  (0) 2008.07.18
Trackbacks 1 : Comments 4
  1. Favicon of http://shurain.egloos.com 슈레인 2008.08.11 11:19 Modify/Delete Reply

    변태같은 모양이 나오네여

  2. Favicon of http://deisys.net deisys 2008.08.11 12:27 Modify/Delete Reply

    슈레인 // 나선력이야 ㅋㅋㅋ

  3. Favicon of http://etnalry.textcube.com/ etnalry 2008.08.12 23:07 Modify/Delete Reply

    반대로 돌렸네. ㅎㅎ

  4. Favicon of http://deisys.net dgoon 2008.08.13 01:43 Modify/Delete Reply

    etnalry // 오리지널이 이렇게 돌아 ㅋㅋ

Write a comment