# Constellation network

> Floating dots joined by thin lines that drift apart when your mouse gets close.

- Category: [Backgrounds](https://library.aimran.es/components/patterns)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/pt-constellation
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Connected particles say “network” without drawing a diagram, so they suit the hero of a data consultancy, a blockchain project or the landing page of a community app. Move the cursor and nearby points step aside and link up to it, which people love playing with. Think of it as an interactive particles background, a lighter take on particles.js.

On phones there’s no hover, so the lines just drift on their own, which still looks fine. Keep the density moderate: every dot checks its distance to every other one, and a very full screen can slow down older laptops.

## Code

### HTML

```html
<div class="pt-constellation"><canvas></canvas></div>
```

### CSS

```css
.pt-constellation {
  --c1: #0071e3;
  --c2: #8b5cf6;
  --c3: #14b8a6;
  --k: 1;
  /* velocidad */
  --d: 1;
  /* densidad / escala */
  --o: 1;
  /* opacidad */
  --bg: #05060a;
  --fg: #ffffff;
  --blend: screen;
  min-height: 100vh;
}

.pt-constellation {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-constellation>* {
  opacity: var(--o);
}

.pt-constellation canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
```

### JavaScript

```js
(function (el) {
const cv=el.querySelector("canvas"),x=cv.getContext("2d");let W=0,H=0,raf=0;
const fit=()=>{const r=Math.min(window.devicePixelRatio||1,2);W=el.clientWidth;H=el.clientHeight;cv.width=W*r;cv.height=H*r;x.setTransform(r,0,0,r,0,0)};
const ro=new ResizeObserver(fit);ro.observe(el);fit();
const V=()=>{const s=getComputedStyle(el),g=(n)=>s.getPropertyValue(n).trim();return{c1:g("--c1"),c2:g("--c2"),c3:g("--c3"),bg:g("--bg"),k:+g("--k")||1,d:+g("--d")||1}};
// Movimiento reducido: se calculan de golpe unos fotogramas (con tiempo simulado) y la escena se queda quieta
const RM=matchMedia("(prefers-reduced-motion: reduce)").matches;let RF=0;
const requestAnimationFrame=(f)=>{if(!RM)return window.requestAnimationFrame(f);if(++RF<400)f(RF*60);return 0};
const P=[];for(let i=0;i<180;i++)P.push({x:Math.random(),y:Math.random(),vx:(Math.random()-.5)*.0008,vy:(Math.random()-.5)*.0008});
const m={x:-1e4,y:-1e4};const mv=(e)=>{const r=el.getBoundingClientRect();m.x=(e.clientX-r.left)*W/r.width;m.y=(e.clientY-r.top)*H/r.height};const lv=()=>{m.x=m.y=-1e4};
el.addEventListener("pointermove",mv);el.addEventListener("pointerleave",lv);
const loop=()=>{const v=V();x.clearRect(0,0,W,H);const n=Math.min(180,Math.floor(80*v.d)),R=120;const pts=[];
for(let i=0;i<n;i++){const p=P[i];p.x+=p.vx*v.k;p.y+=p.vy*v.k;if(p.x<0||p.x>1)p.vx*=-1;if(p.y<0||p.y>1)p.vy*=-1;
let px=p.x*W,py=p.y*H;const dx=px-m.x,dy=py-m.y,dd=Math.hypot(dx,dy);if(dd<140){const f=(140-dd)/140;p.x+=dx/dd*f*.004;p.y+=dy/dd*f*.004;px=p.x*W;py=p.y*H}pts.push([px,py])}
x.lineWidth=1;for(let i=0;i<n;i++)for(let j=i+1;j<n;j++){const d=Math.hypot(pts[i][0]-pts[j][0],pts[i][1]-pts[j][1]);if(d<R){x.globalAlpha=(1-d/R)*.7;x.strokeStyle=v.c2;x.beginPath();x.moveTo(pts[i][0],pts[i][1]);x.lineTo(pts[j][0],pts[j][1]);x.stroke()}}
for(let i=0;i<n;i++){const d=Math.hypot(pts[i][0]-m.x,pts[i][1]-m.y);if(d<180){x.globalAlpha=1-d/180;x.strokeStyle=v.c3;x.beginPath();x.moveTo(pts[i][0],pts[i][1]);x.lineTo(m.x,m.y);x.stroke()}}
x.globalAlpha=1;x.fillStyle=v.c1;x.shadowColor=v.c1;x.shadowBlur=10;for(const p of pts){x.beginPath();x.arc(p[0],p[1],2.2,0,7);x.fill()}x.shadowBlur=0;
raf=requestAnimationFrame(loop)};loop();
return()=>{cancelAnimationFrame(raf);ro.disconnect();el.removeEventListener("pointermove",mv);el.removeEventListener("pointerleave",lv)};
})(document.querySelector(".pt-constellation"));
```

### React

```tsx
// @ts-nocheck
import { useEffect, useRef } from "react";

const css = `
.pt-constellation {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-constellation>* {
  opacity: var(--o);
}

.pt-constellation canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

`;

export default function PatternConstellation() {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
const cv=el.querySelector("canvas"),x=cv.getContext("2d");let W=0,H=0,raf=0;
const fit=()=>{const r=Math.min(window.devicePixelRatio||1,2);W=el.clientWidth;H=el.clientHeight;cv.width=W*r;cv.height=H*r;x.setTransform(r,0,0,r,0,0)};
const ro=new ResizeObserver(fit);ro.observe(el);fit();
const V=()=>{const s=getComputedStyle(el),g=(n)=>s.getPropertyValue(n).trim();return{c1:g("--c1"),c2:g("--c2"),c3:g("--c3"),bg:g("--bg"),k:+g("--k")||1,d:+g("--d")||1}};
// Movimiento reducido: se calculan de golpe unos fotogramas (con tiempo simulado) y la escena se queda quieta
const RM=matchMedia("(prefers-reduced-motion: reduce)").matches;let RF=0;
const requestAnimationFrame=(f)=>{if(!RM)return window.requestAnimationFrame(f);if(++RF<400)f(RF*60);return 0};
const P=[];for(let i=0;i<180;i++)P.push({x:Math.random(),y:Math.random(),vx:(Math.random()-.5)*.0008,vy:(Math.random()-.5)*.0008});
const m={x:-1e4,y:-1e4};const mv=(e)=>{const r=el.getBoundingClientRect();m.x=(e.clientX-r.left)*W/r.width;m.y=(e.clientY-r.top)*H/r.height};const lv=()=>{m.x=m.y=-1e4};
el.addEventListener("pointermove",mv);el.addEventListener("pointerleave",lv);
const loop=()=>{const v=V();x.clearRect(0,0,W,H);const n=Math.min(180,Math.floor(80*v.d)),R=120;const pts=[];
for(let i=0;i<n;i++){const p=P[i];p.x+=p.vx*v.k;p.y+=p.vy*v.k;if(p.x<0||p.x>1)p.vx*=-1;if(p.y<0||p.y>1)p.vy*=-1;
let px=p.x*W,py=p.y*H;const dx=px-m.x,dy=py-m.y,dd=Math.hypot(dx,dy);if(dd<140){const f=(140-dd)/140;p.x+=dx/dd*f*.004;p.y+=dy/dd*f*.004;px=p.x*W;py=p.y*H}pts.push([px,py])}
x.lineWidth=1;for(let i=0;i<n;i++)for(let j=i+1;j<n;j++){const d=Math.hypot(pts[i][0]-pts[j][0],pts[i][1]-pts[j][1]);if(d<R){x.globalAlpha=(1-d/R)*.7;x.strokeStyle=v.c2;x.beginPath();x.moveTo(pts[i][0],pts[i][1]);x.lineTo(pts[j][0],pts[j][1]);x.stroke()}}
for(let i=0;i<n;i++){const d=Math.hypot(pts[i][0]-m.x,pts[i][1]-m.y);if(d<180){x.globalAlpha=1-d/180;x.strokeStyle=v.c3;x.beginPath();x.moveTo(pts[i][0],pts[i][1]);x.lineTo(m.x,m.y);x.stroke()}}
x.globalAlpha=1;x.fillStyle=v.c1;x.shadowColor=v.c1;x.shadowBlur=10;for(const p of pts){x.beginPath();x.arc(p[0],p[1],2.2,0,7);x.fill()}x.shadowBlur=0;
raf=requestAnimationFrame(loop)};loop();
return()=>{cancelAnimationFrame(raf);ro.disconnect();el.removeEventListener("pointermove",mv);el.removeEventListener("pointerleave",lv)};
  }, []);
  return (
    <>
      <style>{css}</style>
      <div
        ref={ref}
        className="pt-constellation"
        style={{
          "--c1": "#0071e3",
          "--c2": "#8b5cf6",
          "--c3": "#14b8a6",
          "--k": 1,
          "--d": 1,
          "--o": 1,
          "--bg": "#05060a",
          "--fg": "#ffffff",
          "--blend": "screen",
          minHeight: "100vh",
        }}
      >
        <canvas></canvas>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Constellation network” block (Backgrounds) from AIMRAN Library to my project.

## What it is
Floating dots joined by thin lines that drift apart when your mouse gets close.

## Chosen settings
- Color 1: #0071e3
- Color 2: #8b5cf6
- Color 3: #14b8a6
- Speed: 1x (from 0.2 to 3x)
- Density / scale: 1x (from 0.5 to 2x)
- Opacity: 1 (from 0.2 to 1)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck
import { useEffect, useRef } from "react";

const css = `
.pt-constellation {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-constellation>* {
  opacity: var(--o);
}

.pt-constellation canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

`;

export default function PatternConstellation() {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
const cv=el.querySelector("canvas"),x=cv.getContext("2d");let W=0,H=0,raf=0;
const fit=()=>{const r=Math.min(window.devicePixelRatio||1,2);W=el.clientWidth;H=el.clientHeight;cv.width=W*r;cv.height=H*r;x.setTransform(r,0,0,r,0,0)};
const ro=new ResizeObserver(fit);ro.observe(el);fit();
const V=()=>{const s=getComputedStyle(el),g=(n)=>s.getPropertyValue(n).trim();return{c1:g("--c1"),c2:g("--c2"),c3:g("--c3"),bg:g("--bg"),k:+g("--k")||1,d:+g("--d")||1}};
// Movimiento reducido: se calculan de golpe unos fotogramas (con tiempo simulado) y la escena se queda quieta
const RM=matchMedia("(prefers-reduced-motion: reduce)").matches;let RF=0;
const requestAnimationFrame=(f)=>{if(!RM)return window.requestAnimationFrame(f);if(++RF<400)f(RF*60);return 0};
const P=[];for(let i=0;i<180;i++)P.push({x:Math.random(),y:Math.random(),vx:(Math.random()-.5)*.0008,vy:(Math.random()-.5)*.0008});
const m={x:-1e4,y:-1e4};const mv=(e)=>{const r=el.getBoundingClientRect();m.x=(e.clientX-r.left)*W/r.width;m.y=(e.clientY-r.top)*H/r.height};const lv=()=>{m.x=m.y=-1e4};
el.addEventListener("pointermove",mv);el.addEventListener("pointerleave",lv);
const loop=()=>{const v=V();x.clearRect(0,0,W,H);const n=Math.min(180,Math.floor(80*v.d)),R=120;const pts=[];
for(let i=0;i<n;i++){const p=P[i];p.x+=p.vx*v.k;p.y+=p.vy*v.k;if(p.x<0||p.x>1)p.vx*=-1;if(p.y<0||p.y>1)p.vy*=-1;
let px=p.x*W,py=p.y*H;const dx=px-m.x,dy=py-m.y,dd=Math.hypot(dx,dy);if(dd<140){const f=(140-dd)/140;p.x+=dx/dd*f*.004;p.y+=dy/dd*f*.004;px=p.x*W;py=p.y*H}pts.push([px,py])}
x.lineWidth=1;for(let i=0;i<n;i++)for(let j=i+1;j<n;j++){const d=Math.hypot(pts[i][0]-pts[j][0],pts[i][1]-pts[j][1]);if(d<R){x.globalAlpha=(1-d/R)*.7;x.strokeStyle=v.c2;x.beginPath();x.moveTo(pts[i][0],pts[i][1]);x.lineTo(pts[j][0],pts[j][1]);x.stroke()}}
for(let i=0;i<n;i++){const d=Math.hypot(pts[i][0]-m.x,pts[i][1]-m.y);if(d<180){x.globalAlpha=1-d/180;x.strokeStyle=v.c3;x.beginPath();x.moveTo(pts[i][0],pts[i][1]);x.lineTo(m.x,m.y);x.stroke()}}
x.globalAlpha=1;x.fillStyle=v.c1;x.shadowColor=v.c1;x.shadowBlur=10;for(const p of pts){x.beginPath();x.arc(p[0],p[1],2.2,0,7);x.fill()}x.shadowBlur=0;
raf=requestAnimationFrame(loop)};loop();
return()=>{cancelAnimationFrame(raf);ro.disconnect();el.removeEventListener("pointermove",mv);el.removeEventListener("pointerleave",lv)};
  }, []);
  return (
    <>
      <style>{css}</style>
      <div
        ref={ref}
        className="pt-constellation"
        style={{
          "--c1": "#0071e3",
          "--c2": "#8b5cf6",
          "--c3": "#14b8a6",
          "--k": 1,
          "--d": 1,
          "--o": 1,
          "--bg": "#05060a",
          "--fg": "#ffffff",
          "--blend": "screen",
          minHeight: "100vh",
        }}
      >
        <canvas></canvas>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
