Skip to content

Instantly share code, notes, and snippets.

@mitchallen
mitchallen / index.html
Created January 9, 2022 10:47
HTML file used to display a canvas
<html>
<head>
<title>js-coinFlip-01</title>
<link rel="stylesheet" href="./app.css">
</head>
<body>
<canvas id="canvas" width="300" height="300" />
<script type="module" src="./app.js">
@mitchallen
mitchallen / app.css
Last active January 9, 2022 14:43
A CSS file for centering a canvas element in a browser window
/**
* Author: Mitch Allen
* File: app.css
*/
canvas {
padding: 0;
margin: auto;
display: block;
width: 400px;
@mitchallen
mitchallen / app.js
Created January 9, 2022 10:52
A browser app file for visualizing coin flip results
// Author: Mitch Allen
// File: app.js
import { coinFlip } from './coinflip.js';
let canvas = document.getElementById("canvas");
const SCREEN_SIZE = 300;
const DIM = 10;
const CELL_SIZE = SCREEN_SIZE / DIM;
const BORDER = 1;
@mitchallen
mitchallen / weighted-coinflip.js
Created January 10, 2022 03:23
Weighted Coin Flip
// Author: Mitch Allen
// File: weighted-coinflip.js
// weightedCoinFlip - return a random 1 or 0 based on weight
export const weightedCoinFlip = (weight) => Math.random() <= weight;
@mitchallen
mitchallen / test-weighted-coinflip.js
Last active January 10, 2022 03:29
Test Weighted Coin Flip
// Author: Mitch Allen
// File: test-weighted-coinflip.js
import {weightedCoinFlip} from './weighted-coinflip.js';
// define test function for weightedCoinFlip()
function testWeightedCoinFlip() {
// define the number of weighted coin flips to generate
const LIMIT = 100;
@mitchallen
mitchallen / index.html
Created January 10, 2022 03:30
Weighted Code Flip visualizer index.html
<html>
<head>
<title>js-weightedCoinFlip-01</title>
<link rel="stylesheet" href="./app.css">
</head>
<body>
<canvas id="canvas" width="300" height="300" />
<script type="module" src="./app.js">
@mitchallen
mitchallen / app.js
Created January 10, 2022 03:34
Weighted Random Boolean visualizer app file
// Author: Mitch Allen
// File: app.js
import { weightedCoinFlip } from './weighted-coinflip.js';
let canvas = document.getElementById("canvas");
const SCREEN_SIZE = 300;
const DIM = 10;
const CELL_SIZE = SCREEN_SIZE / DIM;
const WEIGHT = 0.1;
// Author: Mitch Allen
// File: rolldice.js
export const rollDice = (list) => list[Math.floor(Math.random() * list.length)];
// Author: Mitch Allen
// File: test-rolldice.js
import { rollDice } from './rolldice.js';
function testRollDice() {
// create a source list for testing
const source = ['A','B','C','D','E'];
@mitchallen
mitchallen / index.html
Created January 11, 2022 09:18
Display rollDice results in a grid
<html>
<head>
<title>js-rollDice-01</title>
<link rel="stylesheet" href="./app.css">
</head>
<body>
<canvas id="canvas" width="300" height="300" />
<script type="module" src="./app.js">