
    j$                        S r SSKrSrSrSrS rSS jr\S:X  a  SSKr\R                  R                  \R                  R                  \R                  R                  \5      S	S
5      5      r\R                  " \SS9  / SQr\" \S5       H[  u  ru  rr\R                  R                  \S\ S35      r\" \SSS9 r\R1                  \" \\5      5        SSS5        \" S\5        M]     gg! , (       d  f       N= f)a  Two-pan balance scale SVG generator for AGS Math instruments.

generate(left_value, right_value) -> str  (self-contained SVG)

Tilt formula:
  The beam tilts toward the heavier side. Tilt angle (deg) is proportional
  to the signed difference (left - right):

      tilt = clamp(K * (left - right), -MAX, +MAX)

  with K = 3.0 deg per unit and MAX = 15 deg. Positive tilt lowers the LEFT
  pan (heavier-left dips down). When left == right the beam is level (0 deg).

  Sign convention for SVG (y grows downward): the beam is rotated about the
  central fulcrum by `tilt` degrees. The left end goes DOWN when left heavier.
  In screen rotation terms, rotating by +tilt (clockwise) raises the left and
  lowers the right, so we apply a rotation of -tilt to dip the heavier side.

The pans hang from the beam ends and move up/down with the tilt, but the pan
faces stay horizontal (they are not rotated, only translated to the rotated
beam-end positions).
    Nz<style>svg{--crimson:#960000;--gold:#BF9237;--lime:#88C808;--steel:#4A6488;--cream:#FAF5EE;--ink:#2A2A2A;--border:#D0ACAC;}</style>g      @g      .@c                 ,    [        U[        X 5      5      $ )N)maxmin)vlohis      >C:\allgifted\mathapi11v2\tools/svg_generators/balance_scale.py_clampr
   "   s    r3r:    c                    [        U 5      [        U5      -
  n[        [        U-  [        * [        5      nUS-  nSnSn/ n	U	R	                  SU SU SU SU S3	5        U	R	                  [
        5        U	R	                  S	US
-
   SUS
-
   S35        US-
  n
U	R	                  SUS
-
   SU SX-
   S35        U	R	                  SUS-
   SU
 S35        [        R                  " U* 5      nXh* [        R                  " U5      -  -   nXx* [        R                  " U5      -  -   nXh[        R                  " U5      -  -   nXx[        R                  " U5      -  -   nU	R	                  SUS SUS SUS SUS S3	5        U	R	                  SUS-
   SUS-    SUS-    SUS-    SU SUS
-
   S35        SnSnX4X44 H  u  nnUU-   nU	R	                  SUS SUS SUUS-  -
  S SUS S3	5        U	R	                  SUS SUS SUUS-  -   S SUS S3	5        U	R	                  S UUS-  -
  S SUS S!US SUS"-   S SUUS-  -   S SUS S#35        U	R	                  S$US S%US S&US-  S S'35        M     U	R	                  S(US SUU-   S-   S S)U  S*35        U	R	                  S(US SUU-   S-   S S)U S*35        U	R	                  S+5        S,R                  U	5      $ )-N   Z   x   z/<svg xmlns="http://www.w3.org/2000/svg" width="z
" height="z" viewBox="0 0  z">z<rect x="3" y="3" width="   zG" rx="18" ry="18" fill="none" stroke="var(--border)" stroke-width="4"/>   z	<rect x="z" y="z" width="12" height="z" fill="var(--ink)"/>2   z4" width="100" height="14" rx="6" fill="var(--ink)"/>z
<line x1="z.2fz" y1="z" x2="z" y2="zA" stroke="var(--steel)" stroke-width="8" stroke-linecap="round"/>z<polygon points="   ,   F   P   z*" stroke="var(--steel)" stroke-width="2"/>z<path d="M z Q    z? Z" fill="var(--gold)" stroke="var(--ink)" stroke-width="1.5"/>z<ellipse cx="z" cy="z" rx="zD" ry="5" fill="var(--gold)" stroke="var(--ink)" stroke-width="1.5"/>z	<text x="zd" font-family="sans-serif" font-size="20" font-weight="bold" fill="var(--ink)" text-anchor="middle">z</text>z</svg>
)floatr
   K_DEG_PER_UNITMAX_TILTappendSTYLEmathradianscossinjoin)
left_valueright_valuewidthheightdifftiltcxfyarmpartsbase_yalxlyrxrypan_droppan_wexeypys                        r	   generater:   &   s   u[11D.4'(H=D	B	B
CE	LL
9%
6( Swaxr	+ 
LL 
LL
#E!G9Jvaxj A@ 	A b[F	LL
BqD6rd"7	{ C 	 
LL
BrE7%x ( 	 	dUA	ttxx{"	"B	ttxx{"	"B	dhhqk!	!B	dhhqk!	!B 
LL
RHF2c(&Cr#h GJ 	K 
LL
BrE7!BrE7!BrE7!BrE7!B4qA G 	 HEXx(R(]Cr#hfRaZ4DF2c( S7 8	
 	Cr#hfRaZ4DF2c( S7 8	

 	"U1W*S)2c( 3C"R%Abqj%5Qr#h ?JK	

 	Bs86"Sa} EJ K	
# ). 
LL
Bs85HR 4 5  *|7	4
 
LL
Bs85HR 4 5  +}G	5 
LL99Ur   __main__z..samplesT)exist_ok))   r>   )      )r   	      balance_scale_z.svgwzutf-8)encodingwrote)r>   r>   ih  i@  )__doc__r    r   r   r   r
   r:   __name__ospathabspathr$   dirname__file__outmakedirsr<   	enumerateilrpopenfwriteprint r   r	   <module>rZ      s   , O 
 \~ z
''//"'',,rwwx'@$	R
SCKKd#&Gw*	6AqGGLLqc67!S7+qGGHQN# ,gq	 +  ,+s   =C--
C;	