게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
시뮬??프로그래밍비교?법알려주세요
게시물ID : computer_87615짧은주소 복사하기
작성자 : pysun
추천 : 0
조회수 : 325회
댓글수 : 11개
등록시간 : 2013/05/11 15:30:31

파이썬으로원자를하나만들어두고

그곳에원자가부디치면멈추게해서쌓고있는데요


scene = display(background=color.white, width=800, height=600 \

                , scale=(0.05,0.05,0.05), forward=(0,-2,-3)) 

from visual import * 

from random import *


atom = []


for an in range(10000):                                                                                   #여기에서10000개의공생성하고요

    atom.append(sphere(radius=0.5, color=color.red, opacity=0.7))                #안보이게한다음에

    atom[an].visible = False                                                                             #랜덤으로위치를배정해서요

    atom[an].pos = vector(10*(random()-0.5),55,10*(random()-0.5))               #일단초기에하나를원점에두고요

atom[0].pos = vector(0,0,0)                                                                            #보이게해요

atom[0].visible = True


down = vector(0,-0.1,0)                                                                                   #공내려가는속도구요


for an in range(1,10000):                                                                                #여기서부터공내리는반복문이에요

    loop = True

    atom[an].visible = True                                                                             #내리려는공을보이게하구요   

    while loop:

        atom[an].pos = atom[an].pos + down                                                   #일정한속도로공을아래로내려요

        for nn in range(0,an):

            if type(atom[0])==type(atom[nn]):                                                       #기준공과같은타입이고

                if mag(atom[nn].pos - atom[an].pos)<1:                                        #두공사이거리가반지름의2배가되면

                    loop = False                                                                                 #그공에대한루프를끝내요

                    break

            else:

                if mag(atom[nn] - atom[an].pos)<1:                                                #위랑같은문장

                    loop = False

                    break

            if atom[an].y<-5:                                                                                   #안부디치고-5까지내려가면

                atom[an].visible = False                                                                    #공안보이게하구요    

                atom[an] = vector(0,-100,0)                                                               #비교는해야되니까쩌아래에배정해요

                loop = False

                break



대충이런식으로만들었는데요

초기에는공이별로없어서비교하는연산이금방인데요

나중에는쌓인공들을전부비교해야하니까

연산이오래걸려요

좋은해결방법없을까요??


전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호