npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

maku.js

v1.0.8

Published

A bridge between HTML and WebGL(three.js).

Downloads

353

Readme

A bridge between HTML and WebGL(three.js).

Install

npm i maku.js

Usage

  1. Define some images in your HTML, and make them transparent
<canvas id="sketch"></canvas>
<div class="gallery-container">
  <ul class="gallery">
    <li class="gallery-item">
      <img
        src="https://s2.loli.net/2023/12/26/U9i6aQ7c1Wfd4th.jpg"
        class="gallery-item-img"
        alt=""
      />
      <div class="gallery-item-text">Image one</div>
    </li>
    <!-- ... -->
  </ul>
</div>
img {
  opacity: 0;
}
  1. Use Maku Class to sync HTML with WebGL
import * as THREE from "three";
import Lenis from "@studio-freight/lenis";
import { getScreenFov, Maku, MakuGroup } from "maku.js";

const width = window.innerWidth,
  height = window.innerHeight;

const z = 600;
const fov = getScreenFov(z, height);
const camera = new THREE.PerspectiveCamera(fov, width / height, 100, 2000);
camera.position.z = z;

// Create scene
const scene = new THREE.Scene();

// Create renderer
const canvas = document.querySelector("#sketch");
const renderer = new THREE.WebGLRenderer({
  canvas,
  antialias: true,
  alpha: true,
});
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(2, window.devicePixelRatio));
renderer.setAnimationLoop(animation);

// Create clock
const clock = new THREE.Clock();

// Create main objects
const textureLoader = new THREE.TextureLoader();

const material = new THREE.ShaderMaterial({
  vertexShader: /* glsl */ `
uniform float iTime;
uniform vec2 iResolution;

varying vec2 vUv;

void main(){
    vec3 p=position;
    gl_Position=projectionMatrix*modelViewMatrix*vec4(p,1.);
    
    vUv=uv;
}
  `,
  fragmentShader: /* glsl */ `
varying vec2 vUv;

uniform sampler2D iChannel0;

void main(){
    vec2 uv=vUv;
    vec4 tex=texture(iChannel0,uv);
    vec3 col=tex.xyz;
    gl_FragColor=vec4(col,1.);
}
  `,
  uniforms: {
    iChannel0: {
      value: null,
    },
    iTime: {
      value: clock.getElapsedTime(),
    },
    iResolution: {
      value: new THREE.Vector2(window.innerWidth, window.innerHeight),
    },
  },
});
const elList = [...document.querySelectorAll(".gallery-item-img")];
const makuGroup = new MakuGroup();
const makus = elList.map(
  (image) =>
    new Maku(image, material, scene, {
      meshSizeType: "scale",
      textureUniform: "iChannel0",
      textureLoader,
    })
);
makuGroup.addMultiple(makus);

makuGroup.syncPositions();

// Create scroller
const lenis = new Lenis({
  smoothTouch: true,
  syncTouch: true,
});

// Handle animation
function animation(time) {
  lenis.raf(time);

  makuGroup.makus.forEach((maku) => {
    const { mesh } = maku;
    mesh.material.uniforms.iTime.value = clock.getElapsedTime();
    mesh.material.uniforms.iResolution.value = new THREE.Vector2(
      window.innerWidth,
      window.innerHeight
    );
  });
  makuGroup.syncPositions();

  renderer.render(scene, camera);
}

// Handle resize
function resize() {
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.setPixelRatio(Math.min(2, window.devicePixelRatio));

  if (camera instanceof THREE.PerspectiveCamera) {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.fov = getScreenFov(camera.position.z, window.innerHeight);
    camera.updateProjectionMatrix();
  }

  makuGroup.syncPositions();
  makuGroup.syncScales();
}

window.addEventListener("resize", resize);

// And the basic setup is done!
// For more, you should visit demos below.
// https://codepen.io/collection/xKGjro

Link for this setup: Click Me

Demos

Click Me

Author

👤 alphardex

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator