Spaces:
Sleeping
Sleeping
Upload app.py
Browse files75 unmodified lines767778798081828384858687261 unmodified lines34935035135235335435554 unmodified lines410411412413414415416417418419113 unmodified lines53353453553653753853954075 unmodified linesself.prev_pos = Noneself.passed_goals = []self.last_action = 0self.reset()def generate_new_map(self):start_pos, start_dir = self.map_generator.update()self.start_pos = pygame.math.Vector2(start_pos)self.start_dir = pygame.math.Vector2(start_dir).normalize()def reset_car(self):if self.start_pos is None or self.start_dir is None:261 unmodified linesreturn frame_array# Use numpy for fast scaling# Simple downsampling by taking every nth pixelscale_x = SCREEN_WIDTH // DISPLAY_WIDTHscale_y = SCREEN_HEIGHT // DISPLAY_HEIGHT54 unmodified linesif stream_counter >= stream_interval:stream_counter = 0# Render framescreen.fill((255, 255, 255))env.map_generator.draw(screen)env.car.draw(screen)# Draw raysfor i, (angle, offset) in enumerate(zip([-60, -30, -15, 0, 15, 30, 60], [14, 22, 27, 26, 27, 22, 14])):113 unmodified lineswith gr.Column(scale=1):gr.Markdown("### Controls")start_btn = gr.Button("🚀 Start Simulation", variant="primary")stop_btn = gr.Button("⏹️ Stop Simulation", variant="secondary")gr.Markdown("### Settings")difficulty_slider = gr.Slider(75 unmodified lines7677787980818283848586878889909192261 unmodified lines35435535635735835954 unmodified lines414415416417418419420421422113 unmodified lines53653753853954054154254375 unmodified linesself.prev_pos = Noneself.passed_goals = []self.last_action = 0# NEW: Cached map surfaceself.map_surface = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))self.reset()def generate_new_map(self):start_pos, start_dir = self.map_generator.update()self.start_pos = pygame.math.Vector2(start_pos)self.start_dir = pygame.math.Vector2(start_dir).normalize()# NEW: Draw map onto cached surface once after generationself.map_surface.fill((255, 255, 255)) # Clear previous mapself.map_generator.draw(self.map_surface) # Render map to cached surfacedef reset_car(self):if self.start_pos is None or self.start_dir is None:261 unmodified linesreturn frame_array# Use numpy for fast scalingscale_x = SCREEN_WIDTH // DISPLAY_WIDTHscale_y = SCREEN_HEIGHT // DISPLAY_HEIGHT54 unmodified linesif stream_counter >= stream_interval:stream_counter = 0# Render frame using cached map surfacescreen.blit(env.map_surface, (0, 0)) # Blit cached mapenv.car.draw(screen) # Draw dynamic car# Draw raysfor i, (angle, offset) in enumerate(zip([-60, -30, -15, 0, 15, 30, 60], [14, 22, 27, 26, 27, 22, 14])):113 unmodified lineswith gr.Column(scale=1):gr.Markdown("### Controls")start_btn = gr.Button("Start Simulation", variant="primary")stop_btn = gr.Button("Stop Simulation", variant="secondary")gr.Markdown("### Settings")difficulty_slider = gr.Slider(
app.py+10-7