Exemplo n.º 1
0
    def adjacent(self, x, y):
        up = utils.up(x, y)
        down = utils.down(x, y)
        left = utils.left(x, y)
        right = utils.right(x, y)

        ret = []

        for x, y in (up, down, left, right):
            if x < 0 or x > self.width - 1:
                continue

            if y < 0 or y > self.height - 1:
                continue

            ret.append((x, y))

        return ret
line_level = env_config["line_level"]
world_im_name = env_config["world_im_name"]
fps = env_config["fps"]
omega = env_config["omega"]
radius = env_config["radius"]
l1 = env_config["l1"]
l2 = env_config["l2"]
shoulder = [im_width//2, D+line_level]
color = tuple(env_config["color"])
thickness = env_config["thickness"]

### Setting objects:

objs = list(sample([(i,j) for i in range(margin, im_width-margin) for j in range(line_level//4, line_level)], N_objs))
theta_d = [atan((shoulder[1]-obj[1])/(obj[0]-shoulder[0]))+pi*int(obj[0]<=shoulder[0]) for obj in objs]
delta_theta_d = [(right(theta_d[idx], theta_d, epsilon), left(theta_d[idx], theta_d, epsilon)) for idx in range(len(theta_d))]
env_config['theta_d'] = theta_d
env_config['delta_theta_d'] = delta_theta_d

### Simulation class and methods:

def draw_world(objs, T, world) -> None:

    # cv.line(world, (0, line_level), (im_width, line_level), [255, 255, 255], 1)

    for idx, obj in enumerate(objs):
        cv.line(world, (int(shoulder[0]+(shoulder[1]-obj[1])/tan(theta_d[idx]-T*delta_theta_d[idx][0])), obj[1]), (int(shoulder[0]+(shoulder[1]-obj[1])/tan(theta_d[idx]+T*delta_theta_d[idx][1])), obj[1]), [0, 0, 255], 1)
        cv.circle(world, obj, radius, [0, 255, 0], -1)

class Robot(RetinaAndArm):
Exemplo n.º 3
0
from utils import correct_it, game_over, right, wrong, welcome, get_tip
import data

points = 0
asks = 0
total_types = len(data.exercises)

if __name__ == '__main__':
    welcome()
    while True:
        collection = data.exercises[randrange(total_types)]
        questions = collection["questions"]
        type_of_collection = collection["type"]
        question, answers = questions[randrange(len(questions))]

        print(question)
        get_tip(collection["tip"])
        your_answer = input()

        if your_answer == "exit":
            break

        asks += 1
        if correct_it(type_of_collection, question, your_answer, answers):
            right()
            points += 1
        else:
            wrong(type_of_collection, question, answers)

    game_over(asks, points)
Exemplo n.º 4
0
l1 = env_config["l1"]
l2 = env_config["l2"]
shoulder = [im_width // 2, D + line_level]
color = tuple(env_config["color"])
thickness = env_config["thickness"]

### Setting objects:

objs = list(
    sample([(i, j) for i in range(margin, im_width - margin)
            for j in range(line_level // 4, line_level)], N_objs))
theta_d = [
    atan((shoulder[1] - obj[1]) / (obj[0] - shoulder[0])) +
    pi * int(obj[0] <= shoulder[0]) for obj in objs
]
delta_theta_d = [(right(theta_d[idx], theta_d,
                        epsilon), left(theta_d[idx], theta_d, epsilon))
                 for idx in range(len(theta_d))]
env_config['theta_d'] = theta_d
env_config['delta_theta_d'] = delta_theta_d

fourcc = cv.VideoWriter_fourcc(*'XVID')
cap = cv.VideoCapture(0)
out = cv.VideoWriter('simulation_fixed_object.avi', fourcc, fps,
                     (im_width, im_height))

### Simulation class and methods:


def draw_world(objs, T, world) -> None:

    # cv.line(world, (0, line_level), (im_width, line_level), [255, 255, 255], 1)