def __init__(self): self.num_of_vehs = 10 self.vehicles = [] for i in range(self.num_of_vehs): self.vehicles.append( Vehicle(random_uniform(width), random_uniform(height))) self.debug = False
def clone(self, w, h): if random_uniform(1) < self.clone_rate and self.health > 0.9: x = random_uniform(w) y = random_uniform(h) print("Hey, cloned") return Evolver(x, y, self.dna) else: return False
def populate(self): self.points = [] self.points.append(self.first_point) for point in range(self.num_of_paths): self.points.append( Vector(((point + 1) * width / self.num_of_paths), random_uniform(height, 0)))
def setup(): size(640, 360) no_stroke() background(0) global perlx global perly perlx = random_uniform(1000) perly = 0
def __init__(self, x, y, dna=False): self.pos = Vector(x, y) self.acc = Vector(0, 0) self.vel = Vector(0, -2) self.__health = 1 if not dna: self.dna = [] for _ in range(4): self.dna.append(random_uniform(-2, 2)) else: self.dna = [] for gene in dna: if random_uniform(1) < self.mutation_rate: self.dna.append((gene + random_uniform(-1, 1)) / 2) else: self.dna.append(gene)
def disperse(self): """ Move the letter randomly on the window. """ self.x += random_uniform(-2, 2) self.y += random_uniform(-2, 2)
def __init__(self, num_of_paths=4): self.num_of_paths = num_of_paths self.radius = 5 self.first_point = Vector(0, random_uniform(height, 0)) self.points = []
def generate_random_dna(): alelos = [random_uniform(-1, 1) for _ in range(4)] dna = DNA(alelos) return dna
def update_path(self): self.point_a = Vector(0, random_uniform(height)) self.point_b = Vector(width, random_uniform(height))