I've used Satimage's Smile app to make vector diagrams (for technical illustrations, laser-cutting patterns, etc) via AppleScript augmented with drawing commands. It's like the opposite of PaintCode, which turns drawings into code. (I'm a mathematician, not an artist, so I want/need to describe images with formulas and equations.)
Sadly, macOS Mojave broke OSAX functionality, making Smile completely unusable.[*] Besides, the oh-so-rudimentary Smile UI can be pretty frustrating. It's time to seek an alternative.
The "code" doesn't have to be AppleScript. I've seen a couple of open-source (usually Qt) apps for editing TikZ, a programmatic graphics language. However, these are geared towards tweaking TikZ code for import into a LaTeX documents and whatnot; I'm looking for something more of a stand-alone document editor, capable of exporting to PDF or EPS directly. (But if there's a really good Mac-like TikZ editor, I'd consider it.)
[*] There's apparently an AppleScript workaround using an an auxiliary SatimageOSAX app, but I haven't gotten it to work with Smile. Besides, it's only a patch, doomed to break eventually.
Best Answer
MetaPost
An open source and complete picture drawing language, with plenty of support and documentation, is MetaPost.
MetaPost is capable of creating complex images and shapes:
You can install MetaPost as part of BasicTex.
Sketch
Aimed more at designers than engineers, Sketch offers a programmable interface and AppleScript support.
Side Note
As an aside, Apple once distributed a sample vector drawing application also called Sketch. One purpose of Sketch was to demonstrate how to incorporate AppleScript into an application.