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