ZSystem: fractal universe generation
Two OpenGL programs, ZSystem t2 and zterrain, built on the design below. The OpenGL helper library in their MSVC folders carries the line “Copyright (c) 1998 Gremlin Interactive Ltd. Written by Mark Lord”.
ZSYSTEMS
--------
Fractal universe generation system
Terms
-
The SEED of an object is a random seed which is used to create
pseudo-random numbers.
A PARAM is a named piece of data.
The PARAMLIST of an object is a set of named pieces of data.
The INDEX of an object is it's position in it's parent's list
of objects.
The ADDRESS of an object is a string of INDEXes. This uniquely
defines it and it's PARAMLIST - object can be generated from
this information.
An OBJECT is stored as a pointer to it's object function.
An OBJECTLIST is a list of OBJECTs each with their own
PARAMLIST.
The CACHE is a set of OBJECTLISTs stored against their
ADDRESSes. The cache is a fixed size and a least recently
used scheme will probably be used to expire entries when space
is needed.
An object function creates a set of subobjects from it's SEED
and PARAMs. This set is cached using the ADDRESS as a key and
the object function is only called again if that entry has been
removed from the cache.
The ZSYSTEM object which is passed around to all functions
contains global state information for the system like the CACHE
and the universal OBJECT. (Each ZYSTEM has it's own cache -
it's not global to the program)
The cache
-
Cache operation:
Given an ADDRESS returns an OBJECTLIST if one is stored for that ADDRESS
Can add an OBJECTLIST for a given ADDRESS
Object functions
-
An object function creates an OBEJCTLIST from a PARAMLIST and a SEED.
This is then cached against the ADDRESS of that object. If the
OBJECTLIST is already cached then the object function does not need to
be called. If a function does not produce an object list then
At the lowest level objects give way to primitives. How does this work?
ZSystem code
-
There is a lot of global state (which is passed around as a ZSYSTEM
object)
You create a ZSystem with a specific entrypoint which is a universe
object function. And then you can render this universe from any
viewpoint.
ZSystem data
-
A ZSystem object has associated with it some dynamic data:
Cache - stores subobjects and parameters so they don't need to be
recalculated.
Params - Parameters for the current object function
Seed - Current random seed
ZSystem state
-
An object function
ZREGION
void MySubObject(ZSYSTEM zs)
{
}
void MyObject(ZSYSTEM zs)
{
ZREGION *r = ZsGetParam("region");
ZSystem_Param(zs, "colour", 0xFF6699);
ZSystem_Param(zs, "shape", 5);
ZsObject(zs, MySubObject);
ZSystem_Begin(zs, ZSubObject);
ZSystem_Param(zs, "region", r2);
ZSystem_End(zs);
// ...
}
Source
- ZSystem t2: ZSystem.txt · ZSystem.cpp · ZSystem.h · MSVC/test.cpp · Vars.h · qe_ogl.cpp · qe_ogl.h · Winmain.cpp · WINMAIN.H
- zterrain: ZSystem.txt · ZSystem.cpp · ZSystem.h · MSVC/test.cpp · Vars.h · qe_ogl.cpp · qe_ogl.h · Winmain.cpp · WINMAIN.H
Lewpen's pattern generator
“Lewpen's pattern generator” is the window title of a family of programs that each compute a 256 × 256 animated pattern every frame: Pattern, New Stylee and PatternsMK2. The first PatternsMK2 build survives in several named variants (“3 differences - spots before your eyes”, “4 differences - coloured 3d”, “6 differences - mad”), and as this capture:

Source
- Pattern v1: Main.cpp · Pattern.cpp · Pattern.h
- Pattern v2: Main.cpp · Pattern.cpp · Pattern.h
- Pattern v3: Main.cpp · Pattern.cpp · Pattern.h · script.txt
- Pattern v4: Main.cpp · Pattern.cpp · Pattern.h · script.txt
- New Stylee v1: Main.cpp · Pattern.cpp · Pattern.h · script.txt
- New Stylee v2: Main.cpp · Pattern.cpp · Pattern.h · script.txt
- PatternsMK2 v1: Main.cpp · Pattern.cpp · Pattern.h
- PatternsMK2 v2: Main.cpp · Pattern.cpp · Pattern.h · Pattern2.cpp · Pattern2.h · functions_alpha.h · functions_drums.h · functions_real.h · functions_rgb.h · functions_simple3d.h · functions_vis.h · type_simple3d.h
- PatternsMK2 v3: Main.cpp · zn.cpp · zn.h
ZGo: networks of functions
ZGo takes the pattern generator a step further. Its design notes, in four parts:
ZGO
---
The basis for ZGo is a network of functions which generate a piece of graphics.
By modifying the initial parameters to the network over time the graphics will animate.
DATA TYPES
----------
With ZGo 1 I'm going to stick to 256x256 images
Integer
-
A 32-bit integer
Real
-
A floating-point value
Channel
-
256x256 array of unsigned bytes
Image
-
Array of up to 4 channels:
1 Channel - Greyscale
2 Channels - Greyscale, Alpha
3 Channels - Red, Green, Blue
4 Channels - Red, Green, Blue, Alpha
IMPLEMENTATION
--------------
Data items will be described using a common structure:
typedef struct
{
char name[64];
int type;
void *item;
}
ZGO_DATAITEM;
FUNCTIONS
---------
A function takes a set of data items, performs some operation on them and returns a set of data items.
eg.
Fade (IMAGE im1, IMAGE im2, REAL alpha) -> (IMAGE im3)
There are two types of function - native functions and user functions.
Native functions are stored in DLLs which have a defined interface (see below)
User functions are networks of functions (both native and user) which have an input and output interface
All will be made clear
IMPLEMENTATION
--------------
Functions are stored one per DLL in a functions folder. The DLL contains a function to perform
the ZGo function on the input data and some functions to get information about the ZGo function.
DLL Exported Functions
-
function
DATASET WRAPPER
-
ZGO_DATASET* ZGo_DataSet_Create()
void ZGo_DataSet_Delete(ZGO_DATASET* ds)
void ZGo_DataSet_AddItem(ZGO_DATAITEM* di)
int ZGo_DataSet_NumItems()
ZGO_DATAITEM* ZGo_DataSet_GetItem(int index)
FUNCTION WRAPPER
-
There is a wrapper on top of the DLLs to call the ZGo functions.
ZGO_DATASET* ZGo_Function_Call(char* fname, ZGO_DATASET* in)
NETWORKS
--------
A network is a set of connected functions. The outputs of functions are connected to the inputs of others.
NETWORK WRAPPER
---------------
ZGO_NETWORK* ZGo_Network_Create()
void ZGo_Network_Delete()
ZEffect, an early Java version
ZEffectZGo in Java: PatternsMK2 version 4
ZGoTest

ZGo in C++: PatternsMK2 versions 5 to 8
Back in C++, ZGo became a class per function: reals, images, matrices, cameras, 3D objects, distortions, faders and the arithmetic between them. Version 7 is saved as “just before complete scene 1”; version 8 adds MakeCamera1, MakeObject1 and MakeScene1. Alongside sit ZGo1, a first C++ program with a plugin, and ZGoBuilder, a Java applet titled “LKS Site3D v0.01” with the comment “Zero-Now 3D Web site v0.01” (only its source survives).
Source
- Design notes: 1. Introduction.txt · 2. Data Types.txt · 3. Functions.txt · 4. Networks.txt
- ZEffect: ZEffect.java · z.htm
- ZGo1: code/main/main.cpp · main.h · main.rc · resource.h · StdAfx.cpp · StdAfx.h · code/plugin/plugin.cpp · plugin.h · StdAfx.cpp · StdAfx.h
- ZGoBuilder: ZGoBuilder.java · ZGoBuilder.html
- PatternsMK2 v4 (Java): ZGoTest.java · tinyptc.java · index.html
- PatternsMK2 v5: Main.cpp · AnimatedRotationMatrix.cpp · .h · Subdivide3DObject.cpp · .h · ZGo.cpp · .h · ZGo3DOBJECT.cpp · .h · ZGoBOOL.cpp · .h · ZGoCAMERA.cpp · .h · ZGoChecker.cpp · .h · ZGoDistort3D.cpp · .h · ZGoDISTORTION3D.cpp · .h · ZGoFader.cpp · .h · ZGoIMAGE.cpp · .h · ZGoINT.cpp · .h · ZGoKeyPressed.cpp · .h · ZGoMain.cpp · .h · ZGoMATRIX.cpp · .h · ZGoMatrixMul.cpp · .h · ZGoNAME.cpp · .h · ZGoPARAMS.cpp · .h · ZGoREAL.cpp · .h · ZGoRender.cpp · .h · ZGoSine.cpp · .h · ZGoTile.cpp · .h · ZGoTransform.cpp · .h
- PatternsMK2 v6: Main.cpp · AnimatedRotationMatrix.cpp · .h · Subdivide3DObject.cpp · .h · ZGo.cpp · .h · ZGo3DOBJECT.cpp · .h · ZGoBOOL.cpp · .h · ZGoCAMERA.cpp · .h · ZGoChecker.cpp · .h · ZGoDistort3D.cpp · .h · ZGoDISTORTION3D.cpp · .h · ZGoFader.cpp · .h · ZGoIMAGE.cpp · .h · ZGoINT.cpp · .h · ZGoKeyPressed.cpp · .h · ZGoMain.cpp · .h · ZGoMATRIX.cpp · .h · ZGoMatrixMul.cpp · .h · ZGoMerge3D.cpp · .h · ZGoNAME.cpp · .h · ZGoPARAMS.cpp · .h · ZGoPointCamera.cpp · .h · ZGoREAL.cpp · .h · ZGoRender.cpp · .h · ZGoSine.cpp · .h · ZGoTile.cpp · .h · ZGoTransform.cpp · .h · ZGoVECTOR.cpp · .h
- PatternsMK2 v7, just before complete scene 1: Main.cpp · Scene1.cpp · .h · AnimatedRotationMatrix.cpp · .h · Subdivide3DObject.cpp · .h · ZGo.cpp · .h · ZGo3DOBJECT.cpp · .h · ZGoARRAY2D.cpp · .h · ZGoBOOL.cpp · .h · ZGoCAMERA.cpp · .h · ZGoChecker.cpp · .h · ZGoDistort3D.cpp · .h · ZGoDISTORTION3D.cpp · .h · ZGoFader.cpp · .h · ZGoIMAGE.cpp · .h · ZGoINT.cpp · .h · ZGoIsRealIncreasing.cpp · .h · ZGoKeyPressed.cpp · .h · ZGoMain.cpp · .h · ZGoMakeShiftMatrix.cpp · .h · ZGoMakeVector.cpp · .h · ZGoMATRIX.cpp · .h · ZGoMatrixMul.cpp · .h · ZGoMerge3D.cpp · .h · ZGoNAME.cpp · .h · ZGoPARAMS.cpp · .h · ZGoPointCamera.cpp · .h · ZGoRandom.cpp · .h · ZGoRANDOMARRAY2D.cpp · .h · ZGoREAL.cpp · .h · ZGoRealAdd.cpp · .h · ZGoRealDiv.cpp · .h · ZGoRealFloor.cpp · .h · ZGoRealFreezer.cpp · .h · ZGoRealMod.cpp · .h · ZGoRealMul.cpp · .h · ZGoRealSqrt.cpp · .h · ZGoRealSub.cpp · .h · ZGoRender.cpp · .h · ZGoSine.cpp · .h · ZGoTile.cpp · .h · ZGoTransform.cpp · .h · ZGoVECTOR.cpp · .h
- PatternsMK2 v8: Main.cpp · MakeCamera1.cpp · .h · MakeObject1.cpp · .h · MakeScene1.cpp · .h · Scene1.cpp · .h · AnimatedRotationMatrix.cpp · .h · Subdivide3DObject.cpp · .h · ZGo.cpp · .h · ZGo3DOBJECT.cpp · .h · ZGoARRAY2D.cpp · .h · ZGoBOOL.cpp · .h · ZGoCAMERA.cpp · .h · ZGoChecker.cpp · .h · ZGoDistort3D.cpp · .h · ZGoDISTORTION3D.cpp · .h · ZGoFader.cpp · .h · ZGoIMAGE.cpp · .h · ZGoINT.cpp · .h · ZGoIsRealIncreasing.cpp · .h · ZGoKeyPressed.cpp · .h · ZGoMain.cpp · .h · ZGoMakeShiftMatrix.cpp · .h · ZGoMakeVector.cpp · .h · ZGoMATRIX.cpp · .h · ZGoMatrixMul.cpp · .h · ZGoMerge3D.cpp · .h · ZGoNAME.cpp · .h · ZGoPARAMS.cpp · .h · ZGoPointCamera.cpp · .h · ZGoRandom.cpp · .h · ZGoRANDOMARRAY2D.cpp · .h · ZGoREAL.cpp · .h · ZGoRealAdd.cpp · .h · ZGoRealDiv.cpp · .h · ZGoRealFloor.cpp · .h · ZGoRealFreezer.cpp · .h · ZGoRealMod.cpp · .h · ZGoRealMul.cpp · .h · ZGoRealSqrt.cpp · .h · ZGoRealSub.cpp · .h · ZGoRender.cpp · .h · ZGoSine.cpp · .h · ZGoTile.cpp · .h · ZGoTransform.cpp · .h · ZGoVECTOR.cpp · .h
Triangle rendering in Windows
A Win32 program for drawing texture-mapped triangles; its About box reads “Copyright (C) 2000”. The work is in the Heffer library, with two text files of triangle fillers for 16-bit screens. triangle.cpp opens with a hand-scheduled inner loop:
VERSION 1 - 8 clocks
;AGI
mov eax, ebx
add edx, 0x00000000 // SM
START:
rol eax, width
and eax, mask
adc ebx, 0x00000000 // SM
add esi, 0x00000000 // SM
mov ax, [eax+0x00000000] // SM
mov [edi+ebp], ax
mov eax, ecx
rol eax, width
and eax, mask
adc ecx, 0x00000000 // SM
add edx, 0x00000000 // SM
mov ax, [eax+0x00000000] // SM
mov [edi+ebp+1], ax
mov eax, ebx
add ebp, 2
jnc start
Source
- triangle.cpp C++ · 1820 lines
- Heffer.cpp C++ · 2643 lines
- Heffer.h C++ header · 203 lines
- texture mapped triangle.txt Text · 133 lines
- texture mapped triangles.txt Text · 1302 lines
- triangle.h · triangle.rc · resource.h · StdAfx.cpp · StdAfx.h
PixelText
PixelText 001
-------------
. Basic render framework
The font is drawn in a text file, one letter beside the next:
aaa aaaa aaa aaaa aaaaa aaaaa aaa a a aaaaa aaaaa a a a a a a a aaa aaaa aaa aaaa aaa aaaaa a a a a a a a a a a aaaaa
a a a a a a a a a a a a a a a a a a aa aa aa a a a a a a a a a a a a a a a a a a a a a a
aaaaa aaaa a a a aaaa aaaa a aa aaaaa a a aaa a a a a a a a a a aaaa a a aaaa aaa a a a a a a a a a a a
a a a a a a a a a a a a a a a a a a a a a a a aa a a a a a a a a a a a a a aa aa a a a a
a a aaaa aaa aaaa aaaaa a aaa a a aaaaa aa a a aaaaa a a a a aaa a aa a a a aaa a aaa a a a a a a aaaaa
Source
- 001/PixelText.cpp C++ · 278 lines
- font.txt Text
PolyCSG: boolean operations on polygons August 2002
Constructive solid geometry for 2D polygons: XOR, AND, subtract and OR of polygons, rendered a scanline at a time. The changelog at the top of PolyCSG.cpp runs through the eleven versions; version 007 is dated 26 August 2002:
PolyCSG 001
-----------
. Basic render framework up and running
PolyCSG 002
-----------
. Added Image class
. Converted buffer to Image class
> First draft of polygon class
. Polygon edge rendering (scanline based)
. Not yet tested
PolyCSG 003
-----------
. Solid rendering
. Added scanline class
. Use scanline class for polygon rendering
. Moved classes to seperate cpp & h files
. Pass polygon into buffer to render
PolyCSG 004
-----------
. Removed Poly.render - have to use Image.drawPolygon
. Added first CSG option - XOR
. XORPoly.render used to render
PolyCSG 005
-----------
. Get poly subclass rendering working ( Image.drawPolygon )
. Add ANDPoly class
. Polygon intersection (AND) up and running!
PolyCSG 006
-----------
. Fix in ANDPoly class ( oka && okb -> oka || okb )
. Added SUBPoly
. Added ORPoly
PolyCSG 007
-----------
2002/08/26 01:00 (while smackdown was on after playing cards at the house - Steve won)
. Added getVScanline function to all polys
. Added or,and,sub class declarations to main file
. Renamed Image.drawPolygon to Image.fillPolygon
. Renamed Image.drawScanline to Image.fillScanline + made private
. Added Image.drawPolygon, Image.drawScanline, Image.drawVScanline
. Removed Poly.render (use Image.fillPolygon instead)
NOW SUPPORTS RENDERING FILLED AND UNFILLED POLYS
PolyCSG 008
-----------
~ Antialiased poly functions
. Added Image.blendCol
. Initial AA tests.. need edge gradients stored in scanline points
. RotatePoly class added
. Poly.firstPoint, nextPoint & peekPoint added
POLYGON ROTATION WORKING
. Added pixel text functions to Image
PolyCSG 009
-----------
. Added TranslatePoly class
. Fixed memory leak in Redraw() - was not deleting all Poly's
> Interesting poly shapes
TODOs
-----
. Poly.recalc function instead of re-making tree each time
- starts off manual (must be called from main code)
- change to automatic (use frame counter to avoid re-recalc-ing)
. TranslatePoly class
. Predefined polygon classes
. Regular
. Star
. Cog
. Demo showing different effects
. Get translation and rotation working for boolean op polygons
. Optimisation: know v & h bounds of polygon to make render loop quicker
The same class library went on into the RTRay raytracer and the animations below.
Source
- 001: PolyCSG.cpp
- 002: PolyCSG.cpp
- 003: PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h
- 004: PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · XORPoly.cpp · XORPoly.h
- 005: PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · XORPoly.cpp · XORPoly.h · ANDPoly.cpp · ANDPoly.h
- 006: PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · XORPoly.cpp · XORPoly.h · ANDPoly.cpp · ANDPoly.h · SUBPoly.cpp · SUBPoly.h · ORPoly.cpp · ORPoly.h
- 007: PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · XORPoly.cpp · XORPoly.h · ANDPoly.cpp · ANDPoly.h · SUBPoly.cpp · SUBPoly.h · ORPoly.cpp · ORPoly.h
- 008: PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · XORPoly.cpp · XORPoly.h · ANDPoly.cpp · ANDPoly.h · SUBPoly.cpp · SUBPoly.h · ORPoly.cpp · ORPoly.h · RotatePoly.cpp · RotatePoly.h
- 009: PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · Polygon Boolean Ops/ANDPoly.cpp · ANDPoly.h · ORPoly.cpp · ORPoly.h · SUBPoly.cpp · SUBPoly.h · XORPoly.cpp · XORPoly.h · Polygon Geometric Ops/RotatePoly.cpp · RotatePoly.h · TranslatePoly.cpp · TranslatePoly.h · Polygon Shapes/RegularPoly.cpp · RegularPoly.h · StarPoly.cpp · StarPoly.h
- 010: PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · Polygon Boolean Ops/ANDPoly.cpp · ANDPoly.h · ORPoly.cpp · ORPoly.h · SUBPoly.cpp · SUBPoly.h · XORPoly.cpp · XORPoly.h · Polygon Geometric Ops/RotatePoly.cpp · RotatePoly.h · TranslatePoly.cpp · TranslatePoly.h · Polygon Shapes/RegularPoly.cpp · RegularPoly.h · StarPoly.cpp · StarPoly.h
- 011 (clean): PolyCSG.cpp · Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · Polygon Boolean Ops/ANDPoly.cpp · ANDPoly.h · ORPoly.cpp · ORPoly.h · SUBPoly.cpp · SUBPoly.h · XORPoly.cpp · XORPoly.h · Polygon Geometric Ops/RotatePoly.cpp · RotatePoly.h · TranslatePoly.cpp · TranslatePoly.h · Polygon Shapes/RegularPoly.cpp · RegularPoly.h · StarPoly.cpp · StarPoly.h
- Motion 010: Main.cpp · Classes/Image.cpp · Image.h · Poly.cpp · Poly.h · Scanline.cpp · Scanline.h · Polygon Boolean Ops/ANDPoly.cpp · ANDPoly.h · ORPoly.cpp · ORPoly.h · SUBPoly.cpp · SUBPoly.h · XORPoly.cpp · XORPoly.h · Polygon Geometric Ops/RotatePoly.cpp · RotatePoly.h · TranslatePoly.cpp · TranslatePoly.h · Polygon Shapes/RegularPoly.cpp · RegularPoly.h · StarPoly.cpp · StarPoly.h
Circle animation, Oil and Waves
Three small animations on the same Classes library (image, scanline, polygon and raytrace classes), each starting from the PolyCSG / Motion / RTRay changelog. Circle animation adds:
Animation 001
-------------
. Renders scrolling array of circles with pulsing wave
Oil is the “basic image template”, with version 001 dated 5 August 2004; Waves is built from the same template.
Source
- Circle animation 001: Main.cpp · Classes/Image.cpp · Image.h · Poly.cpp · Poly.h · Raytrace.cpp · Raytrace.h · Scanline.cpp · Scanline.h · Classes/Poly/ANDPoly.cpp · ANDPoly.h · ORPoly.cpp · ORPoly.h · RegularPoly.cpp · RegularPoly.h · RotatePoly.cpp · RotatePoly.h · StarPoly.cpp · StarPoly.h · SUBPoly.cpp · SUBPoly.h · TranslatePoly.cpp · TranslatePoly.h · XORPoly.cpp · XORPoly.h
- Oil 001, 5 August 2004: Main.cpp · Classes/Image.cpp · Image.h · Poly.cpp · Poly.h · Raytrace.cpp · Raytrace.h · Scanline.cpp · Scanline.h · Classes/Poly/ANDPoly.cpp · ANDPoly.h · ORPoly.cpp · ORPoly.h · RegularPoly.cpp · RegularPoly.h · RotatePoly.cpp · RotatePoly.h · StarPoly.cpp · StarPoly.h · SUBPoly.cpp · SUBPoly.h · TranslatePoly.cpp · TranslatePoly.h · XORPoly.cpp · XORPoly.h
- Oil 002: Main.cpp · Classes/Image.cpp · Image.h · Poly.cpp · Poly.h · Raytrace.cpp · Raytrace.h · Scanline.cpp · Scanline.h · Classes/Poly/ANDPoly.cpp · ANDPoly.h · ORPoly.cpp · ORPoly.h · RegularPoly.cpp · RegularPoly.h · RotatePoly.cpp · RotatePoly.h · StarPoly.cpp · StarPoly.h · SUBPoly.cpp · SUBPoly.h · TranslatePoly.cpp · TranslatePoly.h · XORPoly.cpp · XORPoly.h
- Waves 001: Main.cpp · Classes/Image.cpp · Image.h · Poly.cpp · Poly.h · Raytrace.cpp · Raytrace.h · Scanline.cpp · Scanline.h · Classes/Poly/ANDPoly.cpp · ANDPoly.h · ORPoly.cpp · ORPoly.h · RegularPoly.cpp · RegularPoly.h · RotatePoly.cpp · RotatePoly.h · StarPoly.cpp · StarPoly.h · SUBPoly.cpp · SUBPoly.h · TranslatePoly.cpp · TranslatePoly.h · XORPoly.cpp · XORPoly.h