Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: cp1252 -*-
- from visual import *
- import time
- import random
- #scene.autoschale = 0
- #scene.range=(191,191,191)
- change = 1
- abweichungll = -30
- abweichungrr = -abweichungll
- ausweichung = 8 # >=6 ist gut, aber bei 2 sieht man ausweichprozess
- ABSTAND = 8
- LENGTH = 120
- a = []
- pos0=(0.000000001,0,0)
- pos1=(0.000000001,1,0)
- pos2=(0.000000001,2,0)
- poslist=[(0.0000000011,0,0),(0.0000000012,1,0),(0.0000000013,2,0)]
- sphere(pos=pos0,color=color.black)
- sphere(pos=pos1,color=color.black)
- sphere(pos=pos2,color=color.black)
- dx = 0.000000001
- dy = 1.0
- #time.sleep(2)
- for n in range(10000):
- #print '\n'
- #time.sleep(.01)
- lcount = 0
- rcount = 0
- # calculate angle
- dx = poslist[-1][0]-poslist[-2][0]
- dy = poslist[-1][1]-poslist[-2][1]
- direction = math.atan(dy*1.0/dx)
- #print 'dx', dx, 'dy', dy, 'tan',
- direction_grad = direction/2.0/math.pi*360.0
- if dx >= 0 and dy >= 0:
- pass
- if dx < 0 and dy >= 0:
- direction_grad = direction_grad + 180
- if dx >= 0 and dy < 0:
- pass
- if dx < 0 and dy < 0:
- direction_grad = direction_grad + 180
- # is area blocked? --> change abweichung
- abweichungl = abweichungll
- abweichungr = abweichungrr
- for i in range(len(poslist)-1):
- #abstand
- abstand = ((poslist[-1][0]-poslist[i][0])**2 + (poslist[-1][1]-poslist[i][1])**2)**.5
- if abstand <= ABSTAND:
- #print abstand
- #nicht die letzten dreizig Punkte beachten
- if i > 31:
- lcount = 0 #punkte auf linker seite
- rcount = 0 #punkte auf rechter seite
- #winkel der letzten beiden punkte
- dx = poslist[-1][0]-poslist[-2][0]
- dy = poslist[-1][1]-poslist[-2][1]
- direction1 = math.atan(dy*1.0/dx)
- direction_grad1 = direction1/2.0/math.pi*360.0
- if dx >= 0 and dy >= 0:
- pass
- if dx < 0 and dy >= 0:
- direction_grad1 = direction_grad1 + 180
- if dx >= 0 and dy < 0:
- pass
- if dx < 0 and dy < 0:
- direction_grad1 = direction_grad1 + 180
- #print '22222', direction_grad1
- #alle punkte vergleichen
- for j in range(len(poslist)-30):
- #winkel des vorletzten und aller punkte
- dx = poslist[j][0]-poslist[-2][0]
- dy = poslist[j][1]-poslist[-2][1]
- direction2 = math.atan(dy*1.0/dx)
- direction_grad2 = direction2/2.0/math.pi*360.0
- if dx >= 0 and dy >= 0:
- pass
- if dx < 0 and dy >= 0:
- direction_grad2 = direction_grad2 + 180
- if dx >= 0 and dy < 0:
- pass
- if dx < 0 and dy < 0:
- direction_grad2 = direction_grad2 + 180
- #print '11111', direction_grad2
- # xxx muss großer null sein ?
- if direction_grad1 < 0:
- direction_grad1 += 360
- #print 333
- if direction_grad2 < 0:
- direction_grad2 += 360
- #print 444
- #print direction_grad1, direction_grad2
- if direction_grad1-100 <= direction_grad2 <= direction_grad1:
- rcount += 1
- #print 111
- if direction_grad1 < direction_grad2 <= direction_grad1+100:
- lcount += 1
- #print 222
- #print 'n', n, 'dir1', direction_grad1, 'dir2', direction_grad2, lcount, rcount
- if i > 100:
- if j == len(poslist)-31:
- pass
- #print n,i,j,lcount, rcount
- if lcount > rcount:
- abweichungl = -ausweichung-1
- abweichungr = -ausweichung+1
- if lcount < rcount:
- abweichungl = ausweichung-1
- abweichungr = ausweichung+1
- # abweichung in grad
- #print 'abweichungl', abweichungl, 'abweichungr', abweichungr
- abweichung = random.randint(abweichungl,abweichungr) # abweichung in grad
- new_direction_grad = direction_grad + abweichung # in grad
- abweichungl = abweichungll
- abweichungr = abweichungrr
- # new position
- new_direction = new_direction_grad*2.0*math.pi/360.0
- new_direction_x = math.cos(new_direction)
- new_direction_y = math.sin(new_direction)
- new=(poslist[-1][0] + new_direction_x,poslist[-1][1] + new_direction_y,0) # new value
- poslist.append(new) # append new point
- 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
- #scene.center = vector(new)
- #print new_direction_grad, new_direction, new_direction_x, new_direction_y
- if n > LENGTH+1:
- #a[n-(LENGTH+2)].color=color.black
- a[n-(LENGTH+2)].visible = 0
- poslist.pop(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement