Advertisement
Guest User

Untitled

a guest
Feb 1st, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.24 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. from visual import *
  3. import time
  4. import random
  5.  
  6. #scene.autoschale = 0
  7. #scene.range=(191,191,191)
  8.  
  9. change = 1
  10. abweichungll = -30
  11. abweichungrr = -abweichungll
  12. ausweichung = 8 # >=6 ist gut, aber bei 2 sieht man ausweichprozess
  13. ABSTAND = 8
  14. LENGTH = 120
  15. a = []
  16.  
  17. pos0=(0.000000001,0,0)
  18. pos1=(0.000000001,1,0)
  19. pos2=(0.000000001,2,0)
  20. poslist=[(0.0000000011,0,0),(0.0000000012,1,0),(0.0000000013,2,0)]
  21. sphere(pos=pos0,color=color.black)
  22. sphere(pos=pos1,color=color.black)
  23. sphere(pos=pos2,color=color.black)
  24. dx = 0.000000001
  25. dy = 1.0
  26.  
  27. #time.sleep(2)
  28.  
  29. for n in range(10000):
  30.  
  31.     #print '\n'
  32.  
  33.     #time.sleep(.01)
  34.     lcount = 0
  35.     rcount = 0
  36.                    
  37.     # calculate angle
  38.     dx = poslist[-1][0]-poslist[-2][0]
  39.     dy = poslist[-1][1]-poslist[-2][1]
  40.     direction = math.atan(dy*1.0/dx)
  41.     #print 'dx', dx, 'dy', dy, 'tan',
  42.     direction_grad = direction/2.0/math.pi*360.0
  43.  
  44.     if dx >= 0 and dy >= 0:
  45.         pass
  46.     if dx < 0 and dy >= 0:
  47.         direction_grad = direction_grad + 180
  48.     if dx >= 0 and dy < 0:
  49.         pass
  50.     if dx < 0 and dy < 0:
  51.         direction_grad = direction_grad + 180
  52.  
  53.     # is area blocked? --> change abweichung
  54.     abweichungl = abweichungll
  55.     abweichungr = abweichungrr
  56.     for i in range(len(poslist)-1):
  57.         #abstand
  58.         abstand = ((poslist[-1][0]-poslist[i][0])**2 + (poslist[-1][1]-poslist[i][1])**2)**.5
  59.         if abstand <= ABSTAND:
  60.             #print abstand
  61.  
  62.             #nicht die letzten dreizig Punkte beachten
  63.             if i > 31:
  64.                 lcount = 0 #punkte auf linker seite
  65.                 rcount = 0 #punkte auf rechter seite
  66.  
  67.                 #winkel der letzten beiden punkte
  68.                 dx = poslist[-1][0]-poslist[-2][0]
  69.                 dy = poslist[-1][1]-poslist[-2][1]
  70.                 direction1 = math.atan(dy*1.0/dx)
  71.                 direction_grad1 = direction1/2.0/math.pi*360.0
  72.                 if dx >= 0 and dy >= 0:
  73.                     pass
  74.                 if dx < 0 and dy >= 0:
  75.                     direction_grad1 = direction_grad1 + 180
  76.                 if dx >= 0 and dy < 0:
  77.                     pass
  78.                 if dx < 0 and dy < 0:
  79.                     direction_grad1 = direction_grad1 + 180
  80.                 #print '22222', direction_grad1
  81.                    
  82.                 #alle punkte vergleichen
  83.                 for j in range(len(poslist)-30):
  84.                    
  85.                     #winkel des vorletzten und aller punkte
  86.                     dx = poslist[j][0]-poslist[-2][0]
  87.                     dy = poslist[j][1]-poslist[-2][1]
  88.                     direction2 = math.atan(dy*1.0/dx)
  89.                     direction_grad2 = direction2/2.0/math.pi*360.0
  90.                     if dx >= 0 and dy >= 0:
  91.                         pass
  92.                     if dx < 0 and dy >= 0:
  93.                         direction_grad2 = direction_grad2 + 180
  94.                     if dx >= 0 and dy < 0:
  95.                         pass
  96.                     if dx < 0 and dy < 0:
  97.                         direction_grad2 = direction_grad2 + 180
  98.                     #print '11111', direction_grad2
  99.  
  100.                     # xxx muss großer null sein ?
  101.                     if direction_grad1 < 0:
  102.                         direction_grad1 += 360
  103.                         #print 333
  104.                     if direction_grad2 < 0:
  105.                         direction_grad2 += 360
  106.                         #print 444
  107.                     #print direction_grad1, direction_grad2
  108.                        
  109.                     if direction_grad1-100 <= direction_grad2 <= direction_grad1:
  110.                         rcount += 1
  111.                         #print 111
  112.                     if direction_grad1 < direction_grad2 <= direction_grad1+100:
  113.                         lcount += 1
  114.                         #print 222
  115.  
  116.                     #print 'n', n, 'dir1', direction_grad1, 'dir2', direction_grad2, lcount, rcount
  117.  
  118.                     if i > 100:
  119.                         if j == len(poslist)-31:
  120.                             pass
  121.                             #print n,i,j,lcount, rcount
  122.  
  123.     if lcount > rcount:
  124.         abweichungl = -ausweichung-1
  125.         abweichungr = -ausweichung+1
  126.     if lcount < rcount:
  127.         abweichungl = ausweichung-1
  128.         abweichungr = ausweichung+1
  129.  
  130.     # abweichung in grad
  131.     #print 'abweichungl', abweichungl, 'abweichungr', abweichungr
  132.     abweichung = random.randint(abweichungl,abweichungr) # abweichung in grad
  133.     new_direction_grad = direction_grad + abweichung # in grad
  134.     abweichungl = abweichungll
  135.     abweichungr = abweichungrr
  136.  
  137.     # new position
  138.     new_direction = new_direction_grad*2.0*math.pi/360.0
  139.     new_direction_x = math.cos(new_direction)
  140.     new_direction_y = math.sin(new_direction)
  141.     new=(poslist[-1][0] + new_direction_x,poslist[-1][1] + new_direction_y,0) # new value
  142.  
  143.     poslist.append(new) # append new point
  144.     a.append(sphere(pos=new,radius=2,color=(.5+.5*sin(n/7.0),.5+.5*sin(n/11.0),.5+.5*sin(n/13.0)))) # draw
  145.     #scene.center = vector(new)
  146.  
  147.     #print new_direction_grad, new_direction, new_direction_x, new_direction_y
  148.  
  149.  
  150.     if n > LENGTH+1:
  151.         #a[n-(LENGTH+2)].color=color.black
  152.         a[n-(LENGTH+2)].visible = 0
  153.         poslist.pop(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement