For any finite graph G and any field K of characteristic unequal to 2, we construct an algebraic variety X over K whose K-points parametrize K-Lie algebras generated by extremal elements, corresponding to the vertices of the graph, with prescribed commutation relations, corresponding to the nonedges. After that, we study the case where G is a connected, simply laced Dynkin diagram of finite or affine type. We prove that X is then an affine space, and that all points in an open dense subset of X parametrize Lie algebras isomorphic to a single fixed Lie algebra. If G is of affine type, then this fixed Lie algebra is the split finite-dimensional simple Lie algebra corresponding to the associated finite-type Dynkin diagram. This gives a new construction of these Lie algebras, in which they come together with interesting degenerations, corresponding to points outside the open dense subset. Our results may prove useful for recognizing these Lie algebras.