# Import the necessary modules
import random
import pygame
# Initialize Pygame
pygame.init()
# Set the screen dimensions
SCREEN_WIDTH = 500
SCREEN_HEIGHT = 500
# Set the cell dimensions
CELL_SIZE = 5
# Create the screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
# Set the window title
pygame.display.set_caption("DNA Grid")
# Define the DNA bases
bases = ['A', 'C', 'G', 'T']
# Generate a random DNA sequence of length 50
dna = ''.join(random.choices(bases, k=50))
# Create an empty grid
grid = [[False for x in range(SCREEN_WIDTH // CELL_SIZE)] for y in range(SCREEN_HEIGHT // CELL_SIZE)]
# Set the loop variable
running = True
# Start the game loop
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
# Get the position of the mouse click
mouse_pos = pygame.mouse.get_pos()
# Set the corresponding cell in the grid to True
x = mouse_pos[0] // CELL_SIZE
y = mouse_pos[1] // CELL_SIZE
grid[y][x] = True
# Fill the screen with white
screen.fill((255, 255, 255))
# Draw the DNA sequence
for i in range(len(dna)):
x = i * CELL_SIZE
y = SCREEN_HEIGHT - CELL_SIZE
if dna[i] == 'A':
color = (0, 255, 0)
elif dna[i] == 'C':
color = (255, 0, 0)
elif dna[i] == 'G':
color = (0, 0, 255)
else:
color = (255, 255, 0)
pygame.draw.rect(screen, color, pygame.Rect(x, y, CELL_SIZE, CELL_SIZE))
# Draw the grid
for y in range(len(grid)):
for x in range(len(grid[y])):
if grid[y][x]:
color = (0, 0, 0)
else:
color = (255, 255, 255)
pygame.draw.rect(screen, color, pygame.Rect(x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE))
# Update the screen
pygame.display.flip()
# Quit Pygame
pygame.quit()