-- a standing wave of a square drum, sin(2 pi x) sin(3 pi y) with x and y from 0 to 1, -- as a bitmap of 300 by 300 pixels: positive red, negative blue, zero white. -- On a page it fills the rectangle from (0.05, 0.05) to (0.95, 0.85), fractions of the page N = 300 b = BitMap.New(N, N, {{"Canvas.Origin.X",0.05}, {"Canvas.Origin.Y",0.05}, {"Canvas.Size.X",0.9}, {"Canvas.Size.Y",0.8}}) for i = 1, N do for j = 1, N do local x = (i-0.5)/N -- column i, counted from the left local y = 1 - (j-0.5)/N -- row j, counted from the top local f = math.sin(2*Pi*x) * math.sin(3*Pi*y) local c = math.floor(255*(1-math.abs(f)) + 0.5) if f > 0 then BitMap.Pixel(b, i, j, 0xFF0000 + 0x000101*c) -- from white (f = 0) to red (f = 1) else BitMap.Pixel(b, i, j, 0x0000FF + 0x010100*c) -- from white (f = 0) to blue (f = -1) end end end print(b) -- the bitmap as a file of its own BitMap.Save(b, "Drum.bmp") -- the bitmap on a page of 160 mm by 180 mm, with a title above it pl = Graphics.New() pl.SizeX = 160 pl.SizeY = 180 pl.Add(b) pl.Add("sin(2 pi x) sin(3 pi y)", 0.5, 0.9, {{"Size",0.05}, {"Alignment","c"}}) file = io.open("Drum.svg", "w") file:write(Graphics.ToSVG(pl, {{"RelativeSize",true}})) file:close()