use of de.neemann.digital.draw.graphics.GraphicsImage in project Digital by hneemann.
the class TestCaseDescription method testData.
/**
* Runs a 4 bit counter build from JK flip flops 16 ticks.
* The 4 output signals are recoded in a DataSet.
*
* @throws Exception
*/
public void testData() throws Exception {
ToBreakRunner toBreakRunner = new ToBreakRunner("dig/data.dig").runToBreak(29);
// check recorded data
ValueTable dataSet = toBreakRunner.getModel().getObserver(ValueTableObserver.class).getLogData();
assertEquals(29, dataSet.getRows());
int i = 0;
for (Value[] ds : dataSet) {
// clock
assertEquals((~i) & 1, ds[0].getValue());
int s = i / 2 + 1;
// q_0
assertEquals(s & 1, ds[1].getValue());
// q_1
assertEquals((s >> 1) & 1, ds[2].getValue());
// q_2
assertEquals((s >> 2) & 1, ds[3].getValue());
// q_3
assertEquals((s >> 3) & 1, ds[4].getValue());
i++;
}
// try to write data to graphics instance
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new Export(toBreakRunner.getCircuit(), (out) -> new GraphicsImage(out, "PNG", 1)).export(baos);
assertTrue(baos.size() > 15000);
// export data to CSV
StringWriter w = new StringWriter();
dataSet.saveCSV(new BufferedWriter(w));
assertEquals("\"step\",\"C\",\"q_0n\",\"q_1n\",\"q_2n\",\"q_3n\"\n" + "\"0\",\"1\",\"1\",\"0\",\"0\",\"0\"\n" + "\"1\",\"0\",\"1\",\"0\",\"0\",\"0\"\n" + "\"2\",\"1\",\"0\",\"1\",\"0\",\"0\"\n" + "\"3\",\"0\",\"0\",\"1\",\"0\",\"0\"\n" + "\"4\",\"1\",\"1\",\"1\",\"0\",\"0\"\n" + "\"5\",\"0\",\"1\",\"1\",\"0\",\"0\"\n" + "\"6\",\"1\",\"0\",\"0\",\"1\",\"0\"\n" + "\"7\",\"0\",\"0\",\"0\",\"1\",\"0\"\n" + "\"8\",\"1\",\"1\",\"0\",\"1\",\"0\"\n" + "\"9\",\"0\",\"1\",\"0\",\"1\",\"0\"\n" + "\"10\",\"1\",\"0\",\"1\",\"1\",\"0\"\n" + "\"11\",\"0\",\"0\",\"1\",\"1\",\"0\"\n" + "\"12\",\"1\",\"1\",\"1\",\"1\",\"0\"\n" + "\"13\",\"0\",\"1\",\"1\",\"1\",\"0\"\n" + "\"14\",\"1\",\"0\",\"0\",\"0\",\"1\"\n" + "\"15\",\"0\",\"0\",\"0\",\"0\",\"1\"\n" + "\"16\",\"1\",\"1\",\"0\",\"0\",\"1\"\n" + "\"17\",\"0\",\"1\",\"0\",\"0\",\"1\"\n" + "\"18\",\"1\",\"0\",\"1\",\"0\",\"1\"\n" + "\"19\",\"0\",\"0\",\"1\",\"0\",\"1\"\n" + "\"20\",\"1\",\"1\",\"1\",\"0\",\"1\"\n" + "\"21\",\"0\",\"1\",\"1\",\"0\",\"1\"\n" + "\"22\",\"1\",\"0\",\"0\",\"1\",\"1\"\n" + "\"23\",\"0\",\"0\",\"0\",\"1\",\"1\"\n" + "\"24\",\"1\",\"1\",\"0\",\"1\",\"1\"\n" + "\"25\",\"0\",\"1\",\"0\",\"1\",\"1\"\n" + "\"26\",\"1\",\"0\",\"1\",\"1\",\"1\"\n" + "\"27\",\"0\",\"0\",\"1\",\"1\",\"1\"\n" + "\"28\",\"1\",\"1\",\"1\",\"1\",\"1\"\n", w.toString());
}
use of de.neemann.digital.draw.graphics.GraphicsImage in project Digital by hneemann.
the class TestShapes method useShapes.
private void useShapes(boolean ieee) throws Exception {
File filename = new File(Resources.getRoot(), "dig/shapes.dig");
ElementLibrary library = new ElementLibrary();
library.setRootFilePath(new File(Resources.getRoot(), "dig"));
ShapeFactory shapeFactory = new ShapeFactory(library, ieee);
Circuit circuit = Circuit.loadCircuit(filename, shapeFactory);
// try to write circuit to graphics instance
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new Export(circuit, (out) -> new GraphicsImage(out, "PNG", 1)).export(baos);
assertTrue(baos.size() > 30000);
}
use of de.neemann.digital.draw.graphics.GraphicsImage in project Digital by hneemann.
the class GifExporter method createBufferedImage.
private BufferedImage createBufferedImage() throws IOException {
GraphicsImage gri = new GraphicsImage(null, "gif", 1);
gri.setBoundingBox(minMax.getMin(), minMax.getMax());
BufferedImage bi = gri.getBufferedImage();
Graphics gr = bi.getGraphics();
gr.setColor(Color.WHITE);
gr.fillRect(0, 0, bi.getWidth(), bi.getHeight());
GraphicLineCollector glc = new GraphicLineCollector();
circuit.drawTo(glc);
glc.drawTo(gri);
circuit.drawTo(new GraphicSkipLines(gri));
return gri.getBufferedImage();
}
Aggregations