[NTG-context] draw random branched hydrocarbons

2014-02-04 Thread DesdeChaves
I wrote this code to randomly draw organic branched structures.
Since the organic structures have different dimensions I'm using the scale
function to normalize the width.
The result is a rather ugly because the structures are displayed with fonts
with different sizes.
Is there a way to normalize the structures width only when it exceeds a
certain size?

Thanks a lot

Jorge


\usemodule[chemie]
 \usemodule[fullpage][style={margin,empty},margin=15mm]

\starttext

\startluacode
context.bTABLE()
beginchemical={\\scale[width=.40\\textwidth]{\\startchemical[height=fit,width=fit,frame=off]

endchemical=\\stopchemical}}


firstC=\\chemical[ONE, Z0, SAVE][H_3C]

-- go and branch below
skeletonforBELOW={\\chemical[RESTORE,MOV1,Z0,SB153,SAVE][CH],
\\chemical[RESTORE,MOV1,Z0,SB5][CH_2]\\chemical[MOV1,Z0,SB153,SAVE][CH]}
-- 
\\chemical[RESTORE,MOV1,Z0][CH_2]\\chemical[MOV1,Z0,SB5][CH_2]\\chemical[MOV1,Z0,SB153,SAVE][CH]}

-- go and branch above
skeletonforABOVE={\\chemical[RESTORE,MOV1,Z0,SB517,SAVE][CH],
\\chemical[RESTORE,MOV1,Z0,SB5][CH_2]\\chemical[MOV1,Z0,SB517,SAVE][CH]}



-- go and not branch

skeletonnobranched={\\chemical[RESTORE,MOV1,Z0,SB5,SAVE][CH_2],
\\chemical[RESTORE, MOV1,Z0,SB5][CH_2]\\chemical[MOV1,Z0,SB5,SAVE][CH_2]}


-- last C: two ways

lastC={\\chemical[RESTORE,MOV1, Z0, SB5][CH_3],
\\chemical[RESTORE,MOV1,Z0,SB5][CH_2]\\chemical[MOV1, Z0, SB5][CH_3]}


-- branch below

branchedBELOW={\\chemical[MOV3, Z0, SB7][CH_3],
\\chemical[MOV3,Z0,SB7][CH_2]\\chemical[MOV3,Z0,SB7][CH_3],
\\chemical[MOV3,Z0,SB7][CH_2]\\chemical[MOV3,Z0,SB7][CH_2]\\chemical[MOV3,Z0,SB7][CH_3],
\\chemical[MOV3,Z0][Cl],
\\chemical[MOV3,Z0][F],\\chemical[MOV3,Z0][I]}

-- branch above

branchedABOVE={\\chemical[MOV7, Z0, SB3][CH_3],
\\chemical[MOV7,Z0,SB3][CH_2]\\chemical[MOV7,Z0,SB3][CH_3],
\\chemical[MOV7,
Z0,SB3][CH_2]\\chemical[MOV7,Z0,SB3][CH_2]\\chemical[MOV7,Z0,SB3][CH_3],
\\chemical[MOV7,Z0][Cl],
\\chemical[MOV7,Z0][F],\\chemical[MOV7,Z0][I]}

-- rows
for j=1,5 do
context.bTR()

-- columns
for i=1,2 do
context.bTD()

-- begin chemical
context(beginchemical)

-- draw the first CH3
context(firstC)

-- define the maximum for branches
for k=1,3 do

-- linear or branched
branched=math.random(1,100)30

if branched then

-- below or above
 branchedBA=math.random(1,100)30

 if branchedBA then
branch=branchedBELOW[math.random(1,6)];
skeleton=skeletonforBELOW[math.random(1,2)]
 else
branch=branchedABOVE[math.random(1,6)];
skeleton=skeletonforABOVE[math.random(1,2)]
 end
context(skeleton)
context(branch)
else

-- no branch
context(skeletonnobranched[math.random(1,2)])
end


end

-- draw the last CH3
last=lastC[math.random(1,2)]
context(last)

-- end chemical
context(endchemical)
context.eTD()
end
context.eTR()
end
context.eTABLE()

\stopluacode

\stoptext
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] draw random branched hydrocarbons

2014-02-04 Thread Alan BRASLAU
On Tue, 4 Feb 2014 19:55:41 +
DesdeChaves desdecha...@gmail.com wrote:

 I wrote this code to randomly draw organic branched structures.
 Since the organic structures have different dimensions I'm using the
 scale function to normalize the width. The result is a rather ugly
 because the structures are displayed with fonts with different sizes.
 Is there a way to normalize the structures width only when it exceeds
 a certain size?

Why do you normalize the width?
If you set a fixed width (rather than width=fit), then the bounding box
will be normalized whatever is the size of the chemical structure.

Alan
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___