-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
348 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# BackgroundColor.groovy | ||
**Source code:** | ||
```groovy | ||
@Grab(group='org.openscience.cdk', module='cdk-bundle', version='2.9') | ||
import java.util.List; | ||
import java.awt.*; | ||
import java.awt.image.*; | ||
import javax.imageio.*; | ||
import org.openscience.cdk.*; | ||
import org.openscience.cdk.interfaces.*; | ||
import org.openscience.cdk.layout.*; | ||
import org.openscience.cdk.renderer.*; | ||
import org.openscience.cdk.renderer.font.*; | ||
import org.openscience.cdk.renderer.generators.*; | ||
import org.openscience.cdk.renderer.visitor.*; | ||
import org.openscience.cdk.templates.*; | ||
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.ZoomFactor; | ||
int WIDTH = 600; | ||
int HEIGHT = 600; | ||
backgroundColor = Color.lightGray; | ||
// the draw area and the image should be the same size | ||
Rectangle drawArea = new Rectangle(WIDTH, HEIGHT); | ||
Image image = new BufferedImage( | ||
WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB | ||
); | ||
IAtomContainer triazole = MoleculeFactory.make123Triazole(); | ||
StructureDiagramGenerator sdg = new StructureDiagramGenerator(); | ||
sdg.setMolecule(triazole); | ||
sdg.generateCoordinates(); | ||
triazole = sdg.getMolecule(); | ||
// generators make the image elements | ||
List<IGenerator> generators = new ArrayList<IGenerator>(); | ||
generators.add(new BasicSceneGenerator()); | ||
generators.add(new BasicBondGenerator()); | ||
generators.add(new BasicAtomGenerator()); | ||
// the renderer needs to have a toolkit-specific font manager | ||
AtomContainerRenderer renderer = | ||
new AtomContainerRenderer(generators, new AWTFontManager()); | ||
model = renderer.getRenderer2DModel() | ||
model.set( | ||
BasicSceneGenerator.BackgroundColor.class, | ||
backgroundColor | ||
) | ||
model.set(ZoomFactor.class, (double)3.0); | ||
// the call to 'setup' only needs to be done on the first paint | ||
renderer.setup(triazole, drawArea); | ||
// paint the background | ||
Graphics2D g2 = (Graphics2D)image.getGraphics(); | ||
g2.setColor(backgroundColor); | ||
g2.fillRect(0, 0, WIDTH, HEIGHT); | ||
// the paint method also needs a toolkit-specific renderer | ||
visitor = new AWTDrawVisitor(g2) | ||
visitor.setRendererModel(model) | ||
renderer.paint(triazole, visitor); | ||
ImageIO.write((RenderedImage)image, "PNG", new File("BackgroundColor.png")); | ||
``` | ||
**Output:** | ||
```plain | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# CreateAtom4.groovy | ||
**Source code:** | ||
```groovy | ||
@Grab(group='org.openscience.cdk', module='cdk-bundle', version='2.9') | ||
import org.openscience.cdk.Atom; | ||
import org.openscience.cdk.interfaces.IElement; | ||
atom = new Atom(IElement.C); | ||
assert atom.atomicNumber == 6; | ||
assert atom.symbol == "C"; | ||
``` | ||
**Output:** | ||
```plain | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# LargerRedSelection.groovy | ||
**Source code:** | ||
```groovy | ||
@Grab(group='org.openscience.cdk', module='cdk-bundle', version='2.9') | ||
import java.util.List; | ||
import java.awt.*; | ||
import java.awt.image.*; | ||
import javax.imageio.*; | ||
import org.openscience.cdk.*; | ||
import org.openscience.cdk.interfaces.*; | ||
import org.openscience.cdk.layout.*; | ||
import org.openscience.cdk.renderer.*; | ||
import org.openscience.cdk.renderer.font.*; | ||
import org.openscience.cdk.renderer.generators.*; | ||
import org.openscience.cdk.renderer.visitor.*; | ||
import org.openscience.cdk.templates.*; | ||
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.Margin; | ||
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.ZoomFactor; | ||
int WIDTH = 600; | ||
int HEIGHT = 600; | ||
// the draw area and the image should be the same size | ||
Rectangle drawArea = new Rectangle(WIDTH, HEIGHT); | ||
Image image = new BufferedImage( | ||
WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB | ||
); | ||
IAtomContainer triazole = MoleculeFactory.make123Triazole(); | ||
StructureDiagramGenerator sdg = new StructureDiagramGenerator(); | ||
sdg.setMolecule(triazole); | ||
sdg.generateCoordinates(); | ||
triazole = sdg.getMolecule(); | ||
// generators make the image elements | ||
List<IGenerator> generators = new ArrayList<IGenerator>(); | ||
generators.add(new BasicSceneGenerator()); | ||
generators.add(new ExternalHighlightGenerator()); | ||
generators.add(new BasicBondGenerator()); | ||
generators.add(new BasicAtomGenerator()); | ||
IAtomContainer selection = new AtomContainer(); | ||
for (int i=0; i<2; i++) { | ||
bond = triazole.getBond(i); | ||
selection.addAtom(bond.getAtom(0)); | ||
selection.addAtom(bond.getAtom(1)); | ||
selection.addBond(bond); | ||
} | ||
// the renderer needs to have a toolkit-specific font manager | ||
AtomContainerRenderer renderer = | ||
new AtomContainerRenderer(generators, new AWTFontManager()); | ||
// the call to 'setup' only needs to be done on the first paint | ||
renderer.setup(triazole, drawArea); | ||
model = renderer.getRenderer2DModel(); | ||
model.set(Margin.class, (double)0.1); | ||
model.set(ZoomFactor.class, (double)3.0); | ||
model.setExternalSelectedPart(selection); | ||
model = renderer.getRenderer2DModel(); | ||
model.set( | ||
ExternalHighlightGenerator | ||
.ExternalHighlightDistance.class, | ||
(double)24 | ||
); | ||
model.set( | ||
RendererModel.ExternalHighlightColor.class, | ||
Color.red | ||
); | ||
// paint the background | ||
Graphics2D g2 = (Graphics2D)image.getGraphics(); | ||
g2.setColor(Color.WHITE); | ||
g2.fillRect(0, 0, WIDTH, HEIGHT); | ||
// the paint method also needs a toolkit-specific renderer | ||
renderer.paint(triazole, new AWTDrawVisitor(g2)); | ||
ImageIO.write( | ||
(RenderedImage)image, "PNG", | ||
new File("LargerRedSelection.png") | ||
); | ||
``` | ||
**Output:** | ||
```plain | ||
``` |
Oops, something went wrong.