The simulator starts each generation with Hardy-Weinberg genotype frequencies
p2,
2pq and
q2, where
q=1−p. It weights each by its relative fitness
w. The mean fitness of the population is
wˉ=p2wAA+2pqwAa+q2waa and the frequency of A in the next generation is
p′=wˉp2wAA+pqwAa The numerator counts the A alleles carried by survivors: all of the alleles in AA individuals and half of those in Aa. These equations go beyond the AP course; they show what the graph calculates.
The key idea is what the AP course calls natural selection. Individuals vary, part of that variation is heritable, and some heritable variants survive and reproduce more than others in a given environment. Over generations the favored alleles become more common. Because selection works on phenotypes, it changes allele frequencies only indirectly.
A note on names. In the AP course, directional, stabilizing and disruptive selection describe how the distribution of a trait shifts: toward one extreme, toward the middle, or toward both extremes. This simulator maps those ideas onto a single gene, using the heterozygote to stand for the middle value. Its Stabilizing setting is heterozygote advantage, which keeps both alleles in the population. Its Disruptive setting is heterozygote disadvantage, which pushes p toward 0 or 1.