Programming, problem solving, and algorithms

CPSC 203, 2025 W1

October 21, 2025

Announcements

Voronoi Diagrams

Voronoi diagrams

Given a (finite) set of “centres” \(c_{1}, c_{2}, \ldots, c_{k}\), a Voronoi region, \(R_{j}\) consists of the set of points nearer to centre \(c_{j}\), than to any other centre.

Together, the \(R_{j}\) regions compose the Voronoi diagram of a plane.

A map of Vaoncouver on the western part of the Burrard Peninsula with pins marking Tim Hortons locations.

Design an Algorithm

A large grid with 3 colored centers.

Pointillism

The Seurat art piece depicting 1880's park goers.

A Sunday on La Grande Jatte

Algorithmic Art

  1. Select a subset of points from the original image.
  2. Use those points, with their colors, as centers in a new image of the same size.
  3. Build the voronoi diagram in the new image, using the center colors from the original image.

The quality of the new image

depends on ____________________.

Planning

 

  • Point:

  • Color:

  • Center:

  • Centers:

  • Image:

Planning

Data flow:

Demo

PrairieLearn Activity

Analysis

How much work is done? Let \(n\) denote the size of the image, \(n = width \cdot height\)

  1. Read image:

  2. Choose centers:

  3. Build new image:

 

  1. Write out new image: