Cursor Trajectory

It may seem that everyday interaction with a computer mouse is a routine and unremarkable activity. But what if it were possible to transform these routine movements into something more—something that creates a unique visual representation of computer work? Thanks to code that tracks the mouse cursor’s position and the color of the pixel beneath it, this idea can become a reality.

How does it work?
This code tracks where the mouse cursor is on the screen and what color the pixel beneath it is. This information is then transferred in real time to a virtual canvas with a resolution matching that of the screen. Whenever the mouse moves, the code renders a pixel with the color that was directly beneath the cursor at the position where the cursor was located. This means that as you work and move around on the screen, colorful trajectories are created on the canvas. These trajectories are unique and represent the user’s work and interaction with the computer.

What happens after a while?
If this process runs long enough, the canvas begins to fill up and the trajectories become less noticeable. Instead, most of the canvas begins to look like pseudo-random noise. However, there are certain areas of the screen that do not change much over time. This could be, for example, the Windows taskbar, where software icons are located. These areas on the canvas remain more or less the same.

Conclusion
This code represents a fusion of technology and art that transforms everyday computer interaction into something visually captivating. Although working with a computer may seem routine and monotonous at first glance, this project shows that even such an activity can have its own beauty and rhythm.

Source Code
The Python source code for this project is available here:

 import pygame
import pyautogui
import sys
import time

# Inicializace Pygame
pygame.init()

# Získání rozměrů obrazovky
screen_info = pygame.display.Info()
screen_width = screen_info.current_w
screen_height = screen_info.current_h

# Vytvoření okna o rozměrech shodných s rozměry obrazovky
screen = pygame.display.set_mode((screen_width, screen_height))

# Hlavní smyčka programu
running = True
start_time = time.time()
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:  # Když stisknete klávesu ESC, okno se zavře
                running = False

    # Získání souřadnic kurzoru pomocí PyAutoGUI
    x, y = pyautogui.position()

    # Získání barvy pixelu pod kurzorem
    if 0 <= x < screen_width and 0 <= y < screen_height:  # Zkontrolujte, zda jsou souřadnice v rámci obrazovky
        try:
            r, g, b = pyautogui.pixel(x, y)
            # Nabarvení pixelu na plátně touto barvou
            screen.set_at((x, y), (r, g, b))
        except:
            pass

    # Aktualizace zobrazení
    pygame.display.flip()

    # Uložení záložního obrázku každé 3 minuty
    if time.time() - start_time >= 180:  # 180 sekund = 3 minuty
        pygame.image.save(screen, "output_backup.png")
        start_time = time.time()

# Uložení obrázku
pygame.image.save(screen, "output.png")

# Ukončení Pygame
pygame.quit()
sys.exit()