#! /bin/bash

# Draws a sketch of hexagonal cycles for benzene, heptazine, etc.

xsz=1048; xc=524;  # Size and Center X
ysz=1052; yc=526;  # Size and Center Y
ofile="heptazine_guide.png"

# Generate the draw commands with origin at center:
python3 << EOF > .hex.mvg
from math import *
import sys

def hexagon(xc, yc, R, r):
  a60 = 2*3.142591/6; # 60 degrees in radians.
  for k in range(6):
    p = ( xc + R*sin(k*a60),     yc + R*cos(k*a60) )
    q = ( xc + R*sin((k+1)*a60), yc + R*cos((k+1)*a60) )
    sys.stdout.write("stroke-linecap round line %.0f,%.0f %.0f,%.0f\n" % ( p[0], p[1], q[0], q[1] ))
    sys.stdout.write("circle %.0f,%.0f %.0f,%.0f\n" % ( p[0], p[1], p[0]+r, p[1] ))
    sys.stdout.write("circle %.0f,%.0f %.0f,%.0f\n" % ( p[0], p[1], p[0]+0.75*r, p[1] ))
  sys.stdout.write("\n")

def heptazine(xc, yc, R, r):
  Rh = R  # Hexagon radius
  a120 = 2*3.142591/3; # 120 degrees in radians.
  for k in range(3):
    xch = xc + R*sin(k*a120)
    ych = yc - R*cos(k*a120)
    hexagon(xch, ych, Rh, r)
  sys.stdout.write("\n")
 
def main():
  R = 190   # Hexagon radius.
  r = 60    # Atom radius.
  xc = ${xc}; yc = ${yc}
  heptazine(xc, yc, R, r)

main()
EOF

convert \
  -size "${xsz}x${ysz}" canvas:none \
  -fill none -stroke red -strokewidth 3 \
  -draw @.hex.mvg \
  ${ofile}
  
display ${ofile}

