def initialize_gas(container): """ Initial configuration of particles in the gas """ lx = width - radius ly = height - radius gas = [] np.random.seed(1) for n in range(N): rx, ry = randm(), randm() x = rx * radius + (1 - rx) * lx y = ry * (container.y + radius) + (1 - ry) * ly #v = rnorm((2/np.sqrt(np.pi))*np.sqrt(T), np.sqrt(T)) v = chidf2(np.sqrt(kT_m)) angle = 2 * np.pi * randm() gas.append(Particle((x, y), (v, angle), black, radius, True)) return gas
def __init__(self, endup, endown): self.endup_x = endup[0] self.endup_y = endup[1] self.endown_x = endown[0] self.endown_y = endown[1] self.angle = np.arctan2(self.endown_y - self.endup_y, self.endown_x - self.endup_x) self.knot_x, self.knot_y = self.knot_string(randm()) self.knot_where = np.sqrt((self.knot_x - self.endup_x)**2 + (self.knot_y - self.endup_y)**2) self.endMidup_x, self.endMidup_y = self.knot_x, self.knot_y self.knot_y0 = self.knot_y self.endown_y0 = self.endown_y self.tension = 0 self.max_tension = 375 self.broken = False
(right_rect[0] + sq_size + self.diameter, self.y), (right_rect[0] + sq_size + self.diameter, height), 2) white = (255, 255, 255) blue = (0, 0, 255) red = (255, 0, 0) g = 3.7 gamma = 0.01 screen_size = width, height = 320 * 4, 240 * 4 screen = pygame.display.set_mode(screen_size) pygame.display.set_caption('Playing basketballwith drag') # Create basket basket_pos = randm() * width, randm() * height basket = Basket(basket_pos, 20) # Create and launch basketball basketball = Ball((0, height)) basketball.launch(basket_pos) t = 0 clock = pygame.time.Clock() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() dt = 0.01 * clock.tick() screen.fill(white) basketball.draw(screen, blue)
if strings[0].is_broken(): strings[0].broken = True if strings[1].is_broken(): strings[1].broken = True white = (255, 255, 255) blue = (0, 0, 255) red = (255, 0, 0) screen_size = width, height = 320 * 4, 240 * 4 screen = pygame.display.set_mode(screen_size) pygame.display.set_caption('Breaking the knotted strings') # Ends of the strings l_up = l_up_x, l_up_y = 0.5 * randm() * width, 0 r_up = r_up_x, r_up_y = (1 - 0.5 * randm()) * width, 0 l_down = l_down_x, l_down_y = 0.5 * width, 0.5 * height r_down = r_down_x, r_down_y = 0.5 * width, 0.5 * height # Build strings string = [KnottedString(l_up, l_down), KnottedString(r_up, r_down)] # Block dimensions and position of its center block_width, block_height = 100, 100 pos_x, pos_y = l_down_x, l_down_y + 0.5 * block_height block = HangingBlock((block_width, block_height), (pos_x, pos_y)) block_weight = float(sys.argv[1]) # Apply tension to strings apply_tension(string, block_weight) dragging_string_end = False # gravitational acceleration
screen_size = width, height = 320 * 4, 240 * 4 screen = pygame.display.set_mode(screen_size) pygame.display.set_caption('Adding vectors graphically') # Create and draw grading buttons #project = grading.Grade(screen, width, height) # Interval of allowed lengths for vectors max_length = np.sqrt(width**2 + height**2) length_inf, length_sup = int(0.125 * max_length), int(0.25 * max_length) num_vec = 2 vector, vec_tail, vec_rect = [], [], [] for n in range(num_vec): vector.append( Vector([randint(length_inf, length_sup), randm() * 2 * np.pi], comp="polar")) vec_tail.append([randm() * width, randm() * height]) vec_rect.append(vector[n].draw(vec_tail[n], blue, screen_size)) vec_sum = add_vectors(vector) # Keep track of active heads and tails active_head, active_tail = [1] * num_vec, [1] * num_vec vec_dragging = False while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: