diff options
author | Marius <mariausol@gmail.com> | 2012-07-24 12:20:14 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-07-24 12:20:14 +0300 |
commit | b5479d5f43b89e9ce712f0cfa629ccd9c55ac22a (patch) | |
tree | 6da8abd32685ff158d4843e62bf32cfb3377805f /metapost | |
parent | 1258e9df5026925ba69b6184b984d4fa70ed3ffa (diff) | |
download | context-b5479d5f43b89e9ce712f0cfa629ccd9c55ac22a.tar.gz |
beta 2012.07.24 10:59
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mp-chem.mpiv | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/metapost/context/base/mp-chem.mpiv b/metapost/context/base/mp-chem.mpiv index cb595f2c6..066a60bfd 100644 --- a/metapost/context/base/mp-chem.mpiv +++ b/metapost/context/base/mp-chem.mpiv @@ -3,7 +3,7 @@ %D version=2009.05.13, %D title=\CONTEXT\ \METAPOST\ graphics, %D subtitle=chemicals, -%D author=Hans Hagen, +%D author=Hans Hagen \& Alan Braslau", %D date=\currentdate, %D copyright=\PRAGMA] %C @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See licen-en.pdf for %C details. -%D This module in incomplete and experimental. +%D This module is incomplete and experimental. % either consistent setting or not @@ -30,6 +30,9 @@ boolean chem_setting_fixedwidth, chem_setting_fixedheight, chem_doing_pb, chem_text_trace ; +color + chem_axis_color ; + path chem_setting_bbox ; @@ -82,7 +85,7 @@ chem_adjacent := 0 ; chem_substituent := 0 ; chem_direction := 0 ; chem_stack_n := 0 ; -chem_doing_pb := false ; +chem_doing_pb := false ; chem_shift := origin ; chem_dot_factor := 4 ; chem_text_trace := false ; @@ -90,6 +93,7 @@ chem_bd_n := 4 ; chem_bw_n := 4 ; chem_bd_angle := 4 ; chem_bb_angle := 4 ; +chem_axis_color := blue ; % TODO: add "axiscolor=" option in lua... vardef chem_start_structure(expr n, l, r, t, b, scale, axis, fixedwidth, fixedheight, offset) = chem_setting_axis := axis ; @@ -127,17 +131,18 @@ def chem_stop_structure = chem_setting_bbox := (-chem_setting_l,-chem_setting_b) -- ( chem_setting_r,-chem_setting_b) -- ( chem_setting_r, chem_setting_t) -- (-chem_setting_l, chem_setting_t) -- cycle ; - % maybe put it behind the picture - if chem_setting_axis : + if chem_setting_axis : % put it behind the picture + picture chem_picture ; chem_picture := currentpicture ; currentpicture := nullpicture ; save stp ; stp := chem_base_width/ 2 * chem_setting_scale ; - save siz ; siz := chem_base_width/10 * chem_setting_scale ; - draw (-chem_setting_l,0) -- (chem_setting_r,0) withcolor blue ; - draw (0,-chem_setting_b) -- (0,chem_setting_t) withcolor blue ; - for i = 0 step stp until chem_setting_r : draw (i,-siz) -- (i,siz) withcolor blue ; endfor ; - for i = 0 step -stp until -chem_setting_l : draw (i,-siz) -- (i,siz) withcolor blue ; endfor ; - for i = 0 step stp until chem_setting_t : draw (-siz,i) -- (siz,i) withcolor blue ; endfor ; - for i = 0 step -stp until -chem_setting_b : draw (-siz,i) -- (siz,i) withcolor blue ; endfor ; - draw chem_setting_bbox withcolor blue ; + save siz ; siz := stp/5 ; + draw (-chem_setting_l,0) -- (chem_setting_r,0) withcolor chem_axis_color ; + draw (0,-chem_setting_b) -- (0,chem_setting_t) withcolor chem_axis_color ; + for i = 0 step stp until chem_setting_r : draw (i,-siz) -- (i,siz) withcolor chem_axis_color ; endfor ; + for i = 0 step -stp until -chem_setting_l : draw (i,-siz) -- (i,siz) withcolor chem_axis_color ; endfor ; + for i = 0 step stp until chem_setting_t : draw (-siz,i) -- (siz,i) withcolor chem_axis_color ; endfor ; + for i = 0 step -stp until -chem_setting_b : draw (-siz,i) -- (siz,i) withcolor chem_axis_color ; endfor ; + % frame=on: draw chem_setting_bbox withcolor chem_axis_color ; + addto currentpicture also chem_picture ; fi ; setbounds currentpicture to chem_setting_bbox ; enddef ; @@ -146,8 +151,8 @@ def chem_start_component = enddef ; def chem_stop_component = enddef ; def chem_pb = -% draw boundingbox currentpicture withpen pencircle scaled 1mm withcolor blue ; -% draw origin withpen pencircle scaled 2mm withcolor blue ; +% draw boundingbox currentpicture withpen pencircle scaled 1mm withcolor chem_axis_color ; +% draw origin withpen pencircle scaled 2mm withcolor chem_axis_color ; chem_doing_pb := true ; enddef ; @@ -174,6 +179,7 @@ vardef chem_do (expr p) = fi enddef ; +% f_rom, t_o, r_ule, c_olor vardef chem_b (expr n, f, t, r, c) = chem_draw (n, chem_b_path[n], f, t, r, c) ; enddef ; @@ -545,7 +551,7 @@ vardef chem_c_text(expr txt, z) = % adapted copy of thelabel@ enddef ; vardef chem_ang (expr n, d) = - ((-1 * (d-1) * chem_angle[n]) + (-chem_rotation+1) * 90 + chem_start[n]) % no ; + ((1-d)*chem_angle[n] + (1-chem_rotation)*90 + chem_start[n]) % no ; enddef ; vardef chem_rot (expr n, d) = @@ -562,7 +568,7 @@ enddef ; vardef chem_dir (expr n, d) = if n = 1 : - chem_direction_p := (origin - 2*center(chem_b_path[n] rotated chem_ang(n,d+1))) ; + chem_direction_p := (origin - 2*center(chem_b_path[n] rotated chem_ang(n,d))/cosd(chem_angle[n])) ; currentpicture := currentpicture shifted chem_direction_p ; chem_shift := chem_shift + chem_direction_p ; fi ; @@ -580,16 +586,12 @@ vardef chem_mov (expr n, d) = enddef ; vardef chem_off (expr n, d) = - if (d = 1) or (d = 2) or (d = 8) : % positive - currentpicture := currentpicture shifted (-chem_setting_offset,0) ; - chem_shift := chem_shift + (-chem_setting_offset,0) - elseif (d = 4) or (d = 5) or (d = 6) : % negative - currentpicture := currentpicture shifted ( chem_setting_offset,0) ; - chem_shift := chem_shift + ( chem_setting_offset,0) - fi ; + pair o ; o := (-chem_setting_offset,0) rotated chem_ang(1,d+chem_initialmov[1]) ; + currentpicture := currentpicture shifted o ; + chem_shift := chem_shift + o ; enddef ; -vardef chem_set(expr n, m) = +vardef chem_set (expr n, m) = if chem_adjacent > 0 : chem_adjacent_d := xpart chem_b_zero[n] + xpart chem_b_zero[m] ; if chem_adjacent = 1 : chem_adjacent_p := (-chem_adjacent_d, 0) ; @@ -693,14 +695,16 @@ vardef chem_restore = fi ; enddef ; -def chem_init_some(expr n, ratio, start, initialrot, initialmov) = - chem_width [n] := ratio * chem_base_width * chem_setting_scale ; +def chem_init_some(expr n, initialrot, initialmov, front) = chem_angle [n] := 360/abs(n) ; - chem_start [n] := start ; + chem_width [n] := chem_setting_scale * (chem_base_width/2) / sind(chem_angle[n]/2) ; + chem_start [n] := 0 ; chem_initialrot[n] := initialrot ; chem_initialmov[n] := initialmov ; - chem_b_zero [n] := (chem_width[n],0) rotated (chem_angle[n]/2) ; - chem_n_zero [n] := (chem_text_min*chem_width[n],0) rotated (chem_angle[n]/2) ; + chem_b_path [n] := ((chem_width[n],0) rotated -(chem_angle[n]/2))-- + ((chem_width[n],0) rotated +(chem_angle[n]/2)) ; + chem_b_zero [n] := point 1 of chem_b_path [n] ; + chem_n_zero [n] := chem_text_min*chem_b_zero[n] ; chem_r_max [n] := chem_radical_max*chem_b_zero[n] ; chem_r_path [n] := chem_b_zero[n] -- chem_r_max[n] ; chem_mr_path [n] := chem_r_path [n] rotatedaround(chem_b_zero[n], (180-chem_angle[n])/2) ; @@ -714,8 +718,7 @@ def chem_init_some(expr n, ratio, start, initialrot, initialmov) = chem_rt_zero [n] := (((chem_radical_max+chem_radical_min)/2)*chem_width[n],0) rotated (chem_angle[n]/2) ; chem_rtt_zero [n] := chem_rt_zero[n] rotated + 10 ; chem_rbt_zero [n] := chem_rt_zero[n] rotated - 10 ; - chem_b_path [n] := reverse(chem_b_zero[n] -- (chem_b_zero[n] rotated -chem_angle[n])) ; - chem_bx_path [n] := reverse(chem_b_zero[n] -- (chem_b_zero[n] rotated -chem_angle[n])) ; % ? + chem_bx_path [n] := reverse(chem_b_zero[n] -- (chem_b_zero[n] rotated -chem_angle[n])) ; % ? NOT USED... chem_sb_path [n] := subpath (0.25,0.75) of chem_b_path[n] ; chem_s_path [n] := point 0 of chem_b_path[n] -- point 0 of (chem_b_path[n] rotated (2chem_angle[n])) ; chem_ss_path [n] := subpath (0.25,0.75) of (chem_s_path[n]) ; @@ -740,59 +743,56 @@ def chem_init_some(expr n, ratio, start, initialrot, initialmov) = point 0 of chem_sb_path[n] rotatedaround(point 1 of chem_sb_path[n], -4) -- point 0 of chem_sb_path[n] rotatedaround(point 1 of chem_sb_path[n], 4) -- cycle ; chem_rb_path [n] := chem_b_zero[n] -- chem_r_max[n] rotated -2 -- chem_r_max[n] -- chem_r_max[n] rotated 2 -- cycle ; - chem_mrb_path [n] := chem_rb_path[n] rotatedaround(chem_b_zero[n], (180-chem_angle[n])/2) ; + chem_mrb_path [n] := chem_rb_path[n] rotatedaround(chem_b_zero[n],+(180-chem_angle[n])/2) ; chem_prb_path [n] := chem_rb_path[n] rotatedaround(chem_b_zero[n],-(180-chem_angle[n])/2) ; - chem_msr_path [n] := chem_sr_path[n] rotatedaround(chem_b_zero[n], (180-chem_angle[n])/2) ; + chem_msr_path [n] := chem_sr_path[n] rotatedaround(chem_b_zero[n],+(180-chem_angle[n])/2) ; chem_psr_path [n] := chem_sr_path[n] rotatedaround(chem_b_zero[n],-(180-chem_angle[n])/2) ; % not yet ok: % chem_c_path [n] := subpath (30/45, -30/45) of (fullcircle scaled (1.25*chem_circle_radius*chem_width[n])); % chem_cc_path [n] := subpath (30/45,8-30/45) of (fullcircle rotated 90 scaled (1.25*chem_circle_radius*chem_width[n])); chem_c_path [n] := subpath (30/45, -30/45) of (fullcircle scaled (chem_width[n])); chem_cc_path [n] := subpath (30/45,8-30/45) of (fullcircle rotated 90 scaled (chem_width[n])); -enddef ; -def chem_init_three = chem_init_some(3,30/52 ,-60,1,2) ; enddef ; % 60 -def chem_init_four = chem_init_some(4,30/42.5, 0,1,0) ; enddef ; % 45 -def chem_init_five = chem_init_some(5,30/35 , 0,1,0) ; enddef ; % 36 -def chem_init_six = chem_init_some(6, 1 , 0,1,0) ; enddef ; % 30 -def chem_init_eight = chem_init_some(8,30/22.5, 0,1,0) ; enddef ; % 22.5 - -% bb R -R R Z -RZ +RZ - -def chem_init_some_front(expr n, ratio, start, initialrot, initialmov) = - chem_init_some(n, ratio, start, initialrot, initialmov) ; - chem_bb_path [n] := chem_b_path[n] rotated -chem_angle[n] -- chem_b_path[n] -- chem_b_path[n] rotated chem_angle[n] -- + if (front) : + chem_bb_path [n] := chem_b_path[n] rotated -chem_angle[n] -- chem_b_path[n] -- chem_b_path[n] rotated chem_angle[n] -- (reverse(chem_b_path[n] shortened (chem_base_width/20))) paralleled (chem_base_width/20) -- cycle ; - chem_r_max [n] := chem_radical_max*chem_b_zero[n] ; - chem_mr_path [n] := origin -- origin shifted (0,-.25chem_base_width) ; - chem_pr_path [n] := origin -- origin shifted (0, .25*chem_base_width) ; - chem_r_path [n] := point 1 of chem_mr_path[n] -- point 1 of chem_pr_path[n] ; - chem_mr_zero [n] := point 1 of chem_mr_path[n] ; - chem_pr_zero [n] := point 1 of chem_pr_path[n] ; + chem_r_max [n] := chem_radical_max*chem_b_zero[n] ; + chem_mr_path [n] := origin -- origin shifted (0,-.25chem_base_width) ; + chem_pr_path [n] := origin -- origin shifted (0,+.25chem_base_width) ; + chem_r_path [n] := point 1 of chem_mr_path[n] -- point 1 of chem_pr_path[n] ; + chem_mr_zero [n] := point 1 of chem_mr_path[n] ; + chem_pr_zero [n] := point 1 of chem_pr_path[n] ; + fi enddef ; -def chem_init_five_front = chem_init_some_front(-5,30/35,0,2,0) ; enddef ; % 36 -def chem_init_six_front = chem_init_some_front(-6, 1 ,0,2,0) ; enddef ; % 30 +def chem_init_three = chem_init_some(3,1,2,false) ; enddef ; +def chem_init_four = chem_init_some(4,1,0,false) ; enddef ; +def chem_init_five = chem_init_some(5,1,0,false) ; enddef ; +def chem_init_six = chem_init_some(6,1,0,false) ; enddef ; +def chem_init_eight = chem_init_some(8,1,0,false) ; enddef ; +def chem_init_five_front = chem_init_some(-5,2,0,true) ; enddef ; +def chem_init_six_front = chem_init_some(-6,2,0,true) ; enddef ; + +% bb R -R R Z -RZ +RZ vardef chem_init_one = - chem_width [1] := .75 * chem_base_width * chem_setting_scale ; + chem_width [1] := chem_setting_scale * chem_base_width ; chem_angle [1] := 360/8 ; chem_start [1] := 0 ; chem_initialrot[1] := 1 ; - chem_initialmov[1] := 1 ; - chem_b_zero [1] := (1.75*chem_width[1],0) ; + chem_initialmov[1] := 0 ; + chem_b_path [1] := origin -- (chem_width[1],0) ; + chem_b_zero [1] := point 1 of chem_b_path[1] ; chem_r_min [1] := chem_radical_min*chem_b_zero[1] ; chem_r_max [1] := chem_radical_max*chem_b_zero[1] ; chem_r_path [1] := (.5*chem_width[1],0) -- (1.25*chem_width[1],0) ; chem_r_zero [1] := point 1 of chem_r_path [1] ; - chem_b_path [1] := chem_r_path[1] rotated + (chem_angle[1]) ; % used for move here - chem_b_zero [1] := chem_r_zero[1] ; chem_crz_zero [1] := chem_r_zero[1] enlonged chem_center_offset ; chem_e_path [1] := (.5*chem_width[1],-.25*chem_width[1]) -- (.5*chem_width[1],.25*chem_width[1]) ; - chem_sb_path [1] := chem_r_path [1] ; - chem_msb_path [1] := chem_r_path [1] shifted (0,-.1chem_width[1]) ; - chem_psb_path [1] := chem_r_path [1] shifted (0, .1chem_width[1]) ; + chem_sb_path [1] := subpath(.25,.75) of chem_b_path [1] ; + chem_msb_path [1] := subpath (0.00,0.75) of chem_b_path[1] ; + chem_psb_path [1] := subpath (0.25,1.00) of chem_b_path[1] ; chem_ddt_path [1] := subpath(0,.4) of chem_r_path [1] ; chem_ddb_path [1] := subpath(.6,1) of chem_r_path [1] ; chem_ldt_path [1] := chem_ddt_path [1] shifted (0,-.1chem_width[1]) ; % parallel |