The ‘superellipse’ function there is ‘the actual code’ that handles the math, and the cell with the drawing has ‘the actual code’ that handles the drawing. It uses DOM.svg which is part of the Observable standard library, but you could make your own svg element some other way (e.g. by putting it in your html).
If you want to use sliders to adjust a, b, and n, you need to make input elements on your page, and then write your own code to hook up the sliders to trigger re-drawing and set the relevant parameters. Observable makes this nicer by handling the reactivity in a convenient way.
For a fixed value of a, b, and n, you could just set those directly in your code (and also w, h, for the width and height of the plot).
If you just want one function outputting points on the superellipse when you pass in a, b, n, and a parameter t in [0, 1], here is a single-function version cut down to just that:
function superellipse(a, b, n, t) {
t = 2 * Math.PI * t;
const x = Math.cos(t), y = Math.sin(t),
sx = Math.sign(x), sy = Math.sign(y);
return [a*sx * (x*sx)**(2/n),
b*sy * (y*sy)**(2/n)];
}
Can you please Explain it, like just like the video on YouTube I attached in my Question.
With Sliders (All of then are not necessary, but only the ‘n’ slider).
Please Help, as I am a newbie to d3.js.
I don’t know how to integrate sliders and to draw a superellipse in d3.js.
What is the context? Do you have a website where you are trying to add a drawing of a superellipse?
D3 is a library that can help with the drawing (as seen in Torben’s notebook), but D3 doesn’t set up your html and javascript files or hook sliders up to code.
You could also take a look at https://bl.ocks.org or https://vizhub.com to find examples of plain javascript and html with sliders hooked up to dynamic drawings. Perhaps there is an example at one of those sites you could fork to apply Torben’s superellipse drawing code.