Phone AI (no libraries) · Part 2 · HTML + JavaScript
Can my phone AI learn a SPIRAL?FREE
Part 2: the Part 1 brain can't learn a spiral. 24 neurons and more practice, and it bends itself around both arms. Change the numbers and watch it learn.
<style>body { margin: 0; background: #0b0f17; display: grid; place-items: center; height: 100vh; }</style>
<canvas id="c"></canvas>
<script>
const c = document.getElementById("c");
const g = c.getContext("2d");
const S = c.width = c.height = Math.min(innerWidth, innerHeight);
// two spiral arms: yellow = 1, blue = 0
const pts = [];
for (let i = 0; i < 100; i++) {
const a = i / 100 * 9, d = i / 100 * 0.9;
pts.push([Math.cos(a) * d, Math.sin(a) * d, 1]);
pts.push([-Math.cos(a) * d, -Math.sin(a) * d, 0]);
}
// a bigger brain: 24 neurons
const H = 24, r = () => Math.random() * 4 - 2;
+ 60 more lines in the app
Open code AI2 in Pocket Compiler
Download the Pocket Compiler app — free
No app yet? Install it, then open the app and type the code AI2 in Code Library.