コード例 #1
0
ファイル: Evolver.py プロジェクト: asaph96/Evolver
    def behaviour(self, good, bad):
        steerG = self.eat(good, 0.2, remap(self.dna[2], (-2, 2), (5, 100)))
        steerB = self.eat(bad, -1, remap(self.dna[3], (-2, 2), (5, 100)))

        steerG *= self.dna[0]
        steerB *= self.dna[1]

        self.applyForce(steerG)
        self.applyForce(steerB)
コード例 #2
0
ファイル: matrices3D.py プロジェクト: rubaimushtaq/python
def draw():
    p.background(0)
    p.translate(width / 2, height / 2)
    # grid(xscl, yscl)

    rot = p.remap(mouse_x, (0, width), (0, p.TWO_PI))
    tilt = p.remap(mouse_y, (0, height), (0, p.TWO_PI))
    rot_matrix = rottilt(rot, tilt)

    newmatrix = multmatrix(fmatrix, rot_matrix)

    p.no_fill()
    p.stroke_weight(2)
    p.stroke(255, 0, 0)
    graphPoints2(newmatrix, edges)
コード例 #3
0
ファイル: vehicle.py プロジェクト: Mgallimore88/NatureOfCode
    def display(self):
        colour_scale = remap(self.lifespan, (0, self.initial_lifespan),
                             (0, 255))
        fill(0, colour_scale, 0, colour_scale)
        stroke(colour_scale, 0, 0, colour_scale)

        theta = self.velocity.angle
        with push_matrix():
            translate(self.location.x, self.location.y)
            rotate(theta + PI / 2)
            triangle(
                (0, -self.size / 2),
                (-self.size / 4, self.size / 2),
                (self.size / 4, self.size / 2),
            )
        circle((self.location.x, self.location.y), 5)
        """
        display debug vector lines.
        Green = acceleration
        Red = velocity
        """

        # line((self.location.x, self.location.y),
        #      (self.location.x + self.velocity.x * 10,
        #       self.location.y + self.velocity.y * 10))
        # stroke(0, 244, 0)
        # line((self.location.x, self.location.y),
        #      (self.location.x + self.acceleration.x * 100,
        #       self.location.y + self.acceleration.y * 100))
        """ Debug end """
コード例 #4
0
 def set_colour(self):
     self.colour = Color(
         remap((self.velocity.angle), (0, TWO_PI), (0, 255)),
         255,
         255,
         color_mode="HSB",
     )
コード例 #5
0
ファイル: vehicle.py プロジェクト: Mgallimore88/NatureOfCode
 def set_colour(self):
     print(self.velocity.x)
     self.colour = Color(
         remap((self.velocity.x), (-10, 10), (0, 255)),
         255,
         255,
         color_mode="HSB",
     )
コード例 #6
0
def draw():
    global perlx
    global perly

    perlx += 0.005
    perly += 0.005
    fill(remap(noise(perlx), (0, 1), (0, 255)), (255), (255), 100, color_mode="HSB")

    rect((width - 10, height), 10, -10, mode="CORNER")

    if mouse_is_pressed:
        fill(remap(noise(perlx), (0, 1), (0, 255)), (255), (255), 100, color_mode="HSB")
    else:
        fill(255, 15)

    circle_size = 25 * (noise(perlx, perly) + 1)

    circle((mouse_x, mouse_y), circle_size)
コード例 #7
0
ファイル: Evolver.py プロジェクト: asaph96/Evolver
    def display(self, window, debug=False):
        gr = Vector(0, 255, 0)
        rd = Vector(255, 0, 0)
        col = tuple([int(i) for i in rd.lerp(gr, self.health)])
        # print(col)
        pg.draw.circle(window, col, self._pos, self.radius * 2)

        angle = self.vel.angle + pi / 2
        pg.transform.rotate(window, angle)

        if debug:
            dna2 = remap(self.dna[2], (-2, 2), (5, 100))
            dna3 = remap(self.dna[3], (-2, 2), (5, 100))
            lineg = tuple(self.pos * dna2)
            liner = tuple(self.pos * dna3)

            pg.draw.aaline(window, tuple(gr), self._pos, (lineg[:2]))
            pg.draw.aaline(window, tuple(rd), self._pos, (liner[:2]))
コード例 #8
0
def draw():
    p.background(255)
    p.translate(width / 2, height / 2)
    grid(xscl, yscl)
    ang = p.remap(mouse_y, (0, width), (0, p.TWO_PI))
    rot_matrix = [[p.cos(ang), -p.sin(ang)], [p.sin(ang), p.cos(ang)]]
    newmatrix = transpose(multmatrix(rot_matrix, transpose(fmatrix)))
    graphPoints(fmatrix)
    p.stroke(255, 0, 0)
    graphPoints(newmatrix)
コード例 #9
0
 def alter_vectors(self):
     self.perl_x = 0
     self.perl_y = 0
     for row in range(self.number_of_rows):
         for column in range(self.number_of_columns):
             perlin_2d = noise(self.perl_x, self.perl_y, self.perl_time)
             theta = remap(perlin_2d, (0, 1), (0, 2 * PI))
             self.field[row][column].angle = theta
             self.perl_y += 0.01
         self.perl_x += 0.01
     self.perl_time += 0.01
コード例 #10
0
ファイル: vehicle.py プロジェクト: Mgallimore88/NatureOfCode
    def seek_and_stop(self, other):
        self.desired_velocity = other.location - self.location
        desired_magnitude = abs(self.desired_velocity.magnitude)
        if desired_magnitude < 100:
            self.arrival_speed = remap(desired_magnitude, (0, 100),
                                       (0, self.max_speed))
            print(desired_magnitude)
            self.desired_velocity.normalize
            self.desired_velocity *= self.arrival_speed
        else:
            self.desired_velocity.normalize
            self.desired_velocity *= self.max_speed

        self.steering_force = self.desired_velocity - self.velocity
        self.steering_force.limit(self.max_turning)
        self.acceleration += self.steering_force
コード例 #11
0
 def __init__(self, vector_strength=1):
     self.resolution = 50
     self.number_of_columns = round(width / self.resolution)
     self.number_of_rows = round(height / self.resolution)
     #  initialize array
     self.field = []
     #  initialise perlin seed
     self.perl_x = 0
     self.perl_y = 0
     self.perl_time = 0
     self.debug = False
     for row in range(self.number_of_rows):
         self.perl_y += 0.05
         self.field.append([])
         for column in range(self.number_of_columns):
             self.perl_x += 0.05
             perlin_2d = noise(self.perl_x, self.perl_y)
             theta = remap(perlin_2d, (0, 1), (0, 2 * PI))
             self.field[row].append(Vector.from_angle(theta) * vector_strength)
コード例 #12
0
    def __init__(self, vector_strength=1):
        self.resolution = 50
        self.number_of_columns = round(width / self.resolution)
        self.number_of_rows = round(height / self.resolution)
        #  initialize array
        self.field = []
        #  initialise perlin seed
        self.perl_x = 0
        self.perl_y = 0
        self.perl_time = 0
        for row in range(self.number_of_rows):
            self.perl_y += 0.05
            self.field.append([])
            for column in range(self.number_of_columns):
                self.perl_x += 0.05
                perlin_2d = noise(self.perl_x, self.perl_y)
                # print(perlin_2d)
                theta = remap(perlin_2d, (0, 1), (0, 2 * PI))

                # print(f"angle_in_Field_init = {degrees(theta)} row{row} column {column} ")

                self.field[row].append(Vector.from_angle(theta) * vector_strength)
        print(self.field)