Phone AI (no libraries) · Part 1 · HTML + JavaScript

I built an AI on my phone (no libraries)FREE

Watch the video

A tiny brain with 8 neurons learns to tell the inside of a circle from the outside — trained live, right on your phone. About 60 lines of HTML + JavaScript, no libraries.

<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);
// 200 dots: inside the circle = 1
const pts = [];
for (let i = 0; i < 200; i++) {
  const x = Math.random() * 2 - 1;
  const y = Math.random() * 2 - 1;
  pts.push([x, y, x * x + y * y < 0.4 ? 1 : 0]);
}
// a tiny brain: 8 neurons
const H = 8, r = () => Math.random() - 0.5;
+ 53 more lines in the app
Open code AI1 in Pocket Compiler Download the Pocket Compiler app — free

No app yet? Install it, then open the app and type the code AI1 in Code Library.