Skip to content

Commit

Permalink
Merge pull request #76 from o-p-e-n-s-e-t/0.5.20
Browse files Browse the repository at this point in the history
0.5.20
  • Loading branch information
scottpdo authored Apr 2, 2021
2 parents 52b325e + 37ba914 commit e07ea02
Show file tree
Hide file tree
Showing 41 changed files with 539 additions and 477 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions __tests__/canvasrenderer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const fs = require("fs");
const PNG = require("pngjs").PNG;
const pixelmatch = require("pixelmatch");
const puppeteer = require("puppeteer");
let browser, page;

it("Renders Agents correctly when they wrap in a torus Environment", async () => {
browser = await puppeteer.launch({
defaultViewport: {
height: 200,
width: 800
}
});
page = await browser.newPage();
try {
await page.goto("http://localhost:3000/canvas-wrap", {
waitUntil: "networkidle2"
});
} catch {
console.warn(
"Could not connect to localhost:3000, so skipping a CanvasRenderer test. Run `npm run dev` in a separate terminal window to make sure all tests run."
);
return await browser.close();
}
const filePath = __dirname + "/screenshots/canvas-wrap.png";
const existingImage = fs.existsSync(filePath)
? PNG.sync.read(fs.readFileSync(filePath))
: null;
await page.screenshot({ path: filePath });
if (!existingImage) {
return await browser.close();
}
const { width, height } = existingImage;
const newImage = PNG.sync.read(fs.readFileSync(filePath));
const diff = new PNG({ width, height });
expect(
pixelmatch(existingImage.data, newImage.data, diff.data, width, height)
).toBe(0);

await browser.close();
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion tests/linechart.test.js → __tests__/linechart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const pixelmatch = require("pixelmatch");
const puppeteer = require("puppeteer");
let browser, page;

const color = "#ff0000";
const width = 200;
const height = 400;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added __tests__/screenshots/canvas-wrap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/screenshots/flocking-histogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/screenshots/heatmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/screenshots/linechart1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/screenshots/linechart2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions client/models/canvas-wrap.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<style>
canvas {
margin: 0;
}
</style>

<div style="display: flex">
<div id="upper-left"></div>
<div id="upper-right"></div>
<div id="lower-left"></div>
<div id="lower-right"></div>
</div>

<script>
const [width, height] = [200, 200];
const agents = [
// large yellow circle
new Agent({
color: "yellow",
size: 80
}),
// medium-large black arrow
new Agent({
shape: "arrow",
vx: -1,
vy: -1,
size: 25
}),
// medium green triangle
new Agent({
color: "green",
shape: "triangle",
size: 80
}),
// small purple rectangle
new Agent({
color: "purple",
shape: "rect",
width: 20,
height: 40
})
];
const coords = [
{
x: 0,
y: 0
},
{
x: width,
y: 0
},
{
x: 0,
y: height
},
{
x: height,
y: height
}
];
["upper-left", "upper-right", "lower-left", "lower-right"].forEach(
(id, i) => {
const environment = new Environment({ width, height });
const renderer = new CanvasRenderer(environment, { width, height });
renderer.mount("#" + id);
agents.forEach(agent => {
agent.set(coords[i]);
environment.addAgent(agent);
});
environment.tick();
}
);
</script>
Loading

0 comments on commit e07ea02

Please sign in to comment.