Skip to content

Instantly share code, notes, and snippets.

@urish
Last active January 10, 2021 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urish/f4b8df859bbef164cf620a3a738cba56 to your computer and use it in GitHub Desktop.
Save urish/f4b8df859bbef164cf620a3a738cba56 to your computer and use it in GitHub Desktop.
Generate Wokwi diagram with Fibonacci LED pattern
// Sample output: https://wokwi.com/arduino/projects/287356481917944333
const size = 256;
const center = [150, 150];
const c = 16;
const data = {
version: 1,
author: 'Uri Shaked',
editor: 'wokwi',
parts: [
{
id: 'uno',
type: 'wokwi-arduino-nano',
top: 440,
left: 20,
},
],
connections: [
['uno:GND.1', 'p1:VSS', '', []],
['uno:3', 'p1:DIN', '', []],
['uno:5V', 'p1:VDD', '', []],
],
};
for (let n = 1; n <= size; n++) {
const r = c * Math.sqrt(n);
const theta = ((n * 137.508) / 180) * Math.PI;
const x = center[0] + r * Math.cos(theta);
const y = center[1] + r * Math.sin(theta);
data.parts.push({
id: `p${n}`,
type: 'wokwi-neopixel',
top: parseFloat(y.toFixed(1)),
left: parseFloat(x.toFixed(1)),
});
data.connections.push([`p${n}:DOUT`, `p${n + 1}:DIN`, '', []]);
}
console.log(JSON.stringify(data, null, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment