/* * these are explicitly positioned. */ function drawHouse_absolute(img, x, y, width, height) { imageDrawRect(img, x, y + height * ROOF_PROPORTION, width, height * (1 - ROOF_PROPORTION)); imageDrawLine(img, x + width / 2, y, x, y + height * ROOF_PROPORTION); imageDrawLine(img, x + width / 2, y, x + width, y + height * ROOF_PROPORTION); } function drawWindow_absolute(img, x, y, width, height) { imageDrawRect(img, x, y, width, height); imageDrawLine(img, x, y + height / 2, x + width, y + height / 2); imageDrawLine(img, x + width / 2, y + 0, x + width / 2, y + height); } /* * these assume the origin to be at the top left corner of the * item to be drawn's bounding box. */ ROOF_PROPORTION = 0.35; function drawHouse(img, width, height) { imageDrawRect(img, 0, height * ROOF_PROPORTION, width, height * (1 - ROOF_PROPORTION)); imageDrawLine(img, width / 2, 0, 0, height * ROOF_PROPORTION); imageDrawLine(img, width / 2, 0, width, height * ROOF_PROPORTION); } function drawHouseWithWindows(img, width, height) { var i = 0; // same three lines as drawHouse imageDrawRect(img, 0, height * ROOF_PROPORTION, width, height * (1 - ROOF_PROPORTION)); imageDrawLine(img, width / 2, 0, 0, height * ROOF_PROPORTION); imageDrawLine(img, width / 2, 0, width, height * ROOF_PROPORTION); for (i = 5; i LTE arrayLen(arguments); i += 2) { // we have pairs of window coordinates, so lets draw windows imageTranslateDrawingAxis(img, arguments[i - 1], arguments[i] + height * ROOF_PROPORTION); drawWindow(img, width / 5, width / 5); imageTranslateDrawingAxis(img, -1 * arguments[i - 1], -1 * (arguments[i] + height * ROOF_PROPORTION)); } } function drawWindow(img, width, height) { imageDrawRect(img, 0, 0, width, height); imageDrawLine(img, 0, height / 2, width, height / 2); imageDrawLine(img, width / 2, 0, width / 2, height); }

Raw positioning of everything. Correct, but unscalable:

House is relative, but the window is wrong:

Now it's all relative, but window remains globally relative:

House relative to image, windows relative to wall of house:

// utility functions function new(width, height) { var img = imageNew("", width, height, "rgb", "ffffff"); imageSetDrawingColor(img, "000000"); imageSetAntialiasing(img, "on"); return img; } function render(img) { var fn = getDirectoryFromPath(getCurrentTemplatePath()) & "#createUuid()#.png"; imageWrite(img, fn); writeOutput(''); fileDelete(fn); }