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

canvas-nice.js

v1.0.4

Published

A particle animation rendering tool optimized with rendering. Inspired by canvas-nest.js

Downloads

11

Readme

English translation

✨ Canvas-nice.js

canvas-nest.js 優化而來的網頁粒子動畫渲染器。

💨 更加快速

  • 使用 chunks 作為動態物件的空間分割資料結構,擺脫 canvas-nest 的爆搜算法。
  • 實作繪圖緩衝區,大幅提升渲染速度。

🎨 更多自訂參數

相較於 canvas-nest.js5 個參數;提供多達 14 個客製化參數,讓動畫更加多變!

如何使用

套件安裝

將下列連結或是放到 html 檔案的 body 中;或是直接將 canvas-nice.min.js 檔案複製到本機端使用。

<script defer type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/canvas-nice.min.js"></script>

程式碼已打包且壓縮過,目前大小為 7.09 KiB。

建立畫布

建立一個新的 .js 檔,並將自己設定的參數傳入 CanvasNice

new CanvasNice({
    point_dist: 77,
    point_count: 500,
    point_size: {
        min: 1,
        max: 2
    },
    point_slow_down_rate: 0.8,
    point_color: '120,120,120',
    line_color: '120,120,120',
    line_width_multiplier: 0.5,
    max_point_speed: 2,
    zIndex: 0,
    canvas_opacity: 1,
    render_rate: 45,
    chunk_capacity: 15,
    chunk_size_constant: 0.8,
    pointer_inter_type: 0
});

範例請見 index.htmlmain.js

參數說明

以下為參數資料型態與有效範圍一覽

point_dist: float (> 0)
point_count: int (>= 0)
point_size: {
    min: float (>= 0),
    max: float (>= 0)
}
max_point_speed: float (> 0)
point_slow_down_rate: float (> 0 && < 1)
point_color: 'r,g,b' (r, g, b >= 0 && <= 255)
line_color: 'r,g,b' (r, g, b >= 0 && <= 255)
line_width_multiplier: float (>= 0)
zIndex: int (any)
canvas_opacity: float (>= 0 && <= 1)
render_rate: int (> 0)
chunk_capacity: int (> 0)
chunk_size_constant: float (> 0.25)
pointer_inter_type: int (-1 / 0 / 1)
  • point_dist:粒子的互動半徑(單位為像素)

  • point_count:粒子數目,在普通配置下建議小於 1000

  • point_size:粒子的最小與最大半徑,可選(minmax 預設值皆為 1

  • max_point_speed:粒子在一座標軸方向的每一幀最快移動速度(單位為像素)

  • point_slow_down_rate:粒子超過最快移動速度後的速度衰減倍率

  • point_color:粒子的顏色

  • line_color:兩粒子間線的顏色

  • line_width_multiplier:兩粒子間線的寬度倍數,0 為不顯示線(推薦 0.5 ~ 1.5

  • zIndex:畫布的 z-index

  • render_rate:自訂渲染幀率,無填入則使用瀏覽器預設

  • canvas_opacity:畫布的透明度(1 為不透明;0 為完全透明)

  • chunk_capacity:每一個 chunk 所能容納的最高粒子數

  • chunk_size_constant:chunk 的寬或高與粒子互動半徑的比值(大於 1 為無損計算,推薦 0.8

  • pointer_inter_type:粒子與游標的互動模式,共三種:

    -1: 無互動
    0: 在游標周邊一定範圍內的粒子會完全靜止
    1: 模仿 canvas-nest.js 的互動模式,使粒子在一定範圍內來回震盪