import skia, math
def P(cmds):
    p = skia.Path(); it = iter(cmds)
    for c in cmds:
        op = c[0]; a = c[1:]
        if op=='M': p.moveTo(*a)
        elif op=='L': p.lineTo(*a)
        elif op=='C': p.cubicTo(*a)
        elif op=='Z': p.close()
    return p
def jet_parts():
    U = skia.PathOp.kUnion_PathOp; D = skia.PathOp.kDifference_PathOp
    fus = P([('M',100,1),('C',100,-3,97.5,-5.5,93,-6.3),('C',88.5,-7.2,84.5,-9.6,79,-10.6),
             ('C',72,-11.8,60,-11.8,52,-11.2),('C',38,-10,18,-7.5,4,-5.6),('C',0.5,-5.1,0,-2.6,2.5,-2.2),
             ('C',16,0,32,4,46,5.4),('C',62,6.6,80,6.8,91,6),('C',97,5.4,100,4,100,1),('Z',)])
    nac = P([('M',51,-15),('C',51,-17.6,49.6,-19,47,-19),('C',40,-19,30,-18.4,22,-17.2),('C',17,-16.4,14,-15.4,11.6,-14.2),
             ('L',11.6,-11.2),('C',16,-10.6,22,-10.6,30,-10.9),('C',38,-11.2,44,-11.4,47,-11.4),('C',49.6,-11.4,51,-12.6,51,-15),('Z',)])
    pylon = P([('M',45,-12),('L',33,-11.5),('L',33,-9),('L',46,-10.6),('Z',)])
    nac = skia.Op(nac, pylon, skia.PathOp.kUnion_PathOp)
    intake = P([('M',50.2,-17.4),('L',51.6,-17.4),('L',51.6,-12.6),('L',50.2,-12.6),('Z',)])
    far = P([('M',16,-9),('C',14,-16,12.4,-24,11.6,-29.4),('C',11.4,-30.6,9.6,-31.2,8,-30.8),('C',7.2,-30.6,6.8,-30,6.8,-29),('L',5,-6),('Z',)])
    near = P([('M',20,-7.4),('C',14,-12.5,6,-19.5,0.5,-24),('C',-0.6,-24.9,-3.2,-25,-4.6,-24.2),('C',-5.4,-23.8,-5.5,-22.8,-5,-21.8),
              ('L',1.5,-4.6),('Z',)])
    wing = P([('M',65,4.9),('C',57,8.6,47,13.6,38,17.6),('C',36.6,18.2,33.4,18.3,32.6,17.4),('L',45,5.4),('Z',)])
    # separation halo around the near fin so the V reads as two surfaces
    halo = skia.Path(); skia.Paint(Style=skia.Paint.kStroke_Style, StrokeWidth=2.0, StrokeJoin=skia.Paint.kRound_Join).getFillPath(near, halo)
    far = skia.Op(far, halo, D)
    shape = fus
    for q in (nac, far, near, wing): shape = skia.Op(shape, q, U)
    ws = P([('M',91.5,-4.8),('C',87.5,-6,84,-8.2,80,-9.2),('C',79,-9.4,78.4,-8.8,78.8,-8),('L',80.6,-4.6),('Z',)])
    w1 = skia.Path(); w1.addRRect(skia.RRect.MakeRectXY(skia.Rect(67,-8.6,74,-4.6),2,2))
    w2 = skia.Path(); w2.addRRect(skia.RRect.MakeRectXY(skia.Rect(57.5,-8.6,64.5,-4.6),2,2))
    for q in (ws, w1, w2, intake): shape = skia.Op(shape, q, D)
    return shape
def jet(cx, cy, length, angle_deg):
    """place jet: (cx,cy)=nose-ish center, length in units, climb angle (deg, positive = nose up)"""
    s = jet_parts(); m = skia.Matrix()
    sc = length/101.0
    m.setTranslate(cx, cy); m.preRotate(-angle_deg); m.preScale(sc, sc); m.preTranslate(-50, 0)
    s.transform(m); return s
if __name__=='__main__':
    import sys
    surf = skia.Surface(1600, 900); cv = surf.getCanvas(); cv.clear(0xFFFFFFFF)
    j = jet(800, 450, 1200, 0)
    cv.drawPath(j, skia.Paint(AntiAlias=True, Color=0xFF0B1B33))
    j2 = jet(1300, 150, 300, 22); cv.drawPath(j2, skia.Paint(AntiAlias=True, Color=0xFF0B1B33))
    surf.makeImageSnapshot().save(sys.argv[1], skia.kPNG)
