Rythm.js
v2.2.5 - A lot of new dances !
데모 AT : https://okazari.github.io/rythm.js/
페이지 댄스를하는 JavaScript 라이브러리.
NPM으로 설치 :
npm install rythm.js또는 CDN에서 얻는다 :
https://unpkg.com/rythm.js/
https://cdnjs.cloudflare.com/ajax/libs/rythm.js/2.2.6/rythm.min.js
페이지로 리듬 가져 오기 :
< script type =" text/javascript " src =" /path/to/rythm.min.js " > </ script >Rythm CSS 클래스 중 하나를 추가하여 어떤 요소가 춤을 추는지를 나타냅니다.
< div class =" rythm-bass " > </ div >리듬 객체를 만들고 오디오 URL을 제공 한 다음 시작 함수를 사용하십시오.
var rythm = new Rythm ( )
rythm . setMusic ( 'path/to/sample.mp3' )
rythm . start ( ) import Rythm from 'rythm.js'
const rythm = new Rythm ( )
rythm . setMusic ( 'path/to/sample.mp3' )
rythm . start ( ) const rythm = new Rythm ( )
/* The starting scale is the minimum scale your element will take (Scale ratio is startingScale + (pulseRatio * currentPulse)).
* Value in percentage between 0 and 1
* Default: 0.75
*/
rythm . startingScale = value
/* The pulse ratio is be the maximum additional scale your element will take (Scale ratio is startingScale + (pulseRatio * currentPulse)).
* Value in percentage between 0 and 1
* Default: 0.30
*/
rythm . pulseRatio = value
/* The max value history represent the number of passed value that will be stored to evaluate the current pulse.
* Int value, minimum 1
* Default: 100
*/
rythm . maxValueHistory = value
/* Set the music the page will dance to
* @audioUrl: '../example/mysong.mp3'
*/
rythm . setMusic ( audioUrl )
/* Used to collaborate with other players library.
* You can connect Rythm to an audioElement, and then control the audio with your other player
*/
rythm . connectExternalAudioElement ( audioElement )
/* Adjust audio gain
* @value: Number
*/
rythm . setGain ( value )
/* Add your own rythm-class
* @elementClass: Class that you want to link your rythm to
* @danceType: Use any of the built-in effect or give your own function
* @startValue: The starting frequency of your rythm
* @nbValue: The number of frequency of your rythm
* 1024 Frequencies, your rythm will react to the average of your selected frequencies.
* Examples: bass 0-10 ; medium 150-40 ; high 500-100
*/
rythm . addRythm ( elementClass , danceType , startValue , nbValue )
/* Plug your computer microphone to rythm.js.
* This function returns a Promise object that is resolved when the microphone is up.
* Require your website to be run in HTTPS
*/
rythm . plugMicrophone ( ) . then ( function ( ) { ... } )
// Let's dance
rythm . start ( )
/* Stop the party
* @freeze: Set this to true if you want to prevent the elements to reset to their initial position
*/
rythm . stop ( freeze ) addRythm 함수를 사용하여 자신의 클래스가 특정 주파수를 듣게 할 수 있습니다. 기본 클래스가 만드는 방법은 다음과 같습니다.
addRythm('rythm-bass', 'pulse', 0, 10)addRythm('rythm-medium', 'pulse', 150, 40)addRythm('rythm-high', 'pulse', 500, 100) 이 댄스 유형을 더 많이 제어하려면 addRythm 에 대한 마지막 인수로 구성 객체를 제공 할 수 있습니다.
addRythm ( 'rythm-high' , 'shake' , 500 , 100 , { direction : 'left' , min : 20 , max : 300 } )내장 춤과 그 옵션은 다음과 같습니다.
transform: scale() . 기본값 : 0.75transform: scale() . 기본값 : 1.25transform: translateY() . 기본값 : 0transform: translateY() . 기본값 : 30transform: translateX() . 기본값 : -15transform: translateX() . 기본값 : 15left 에서 오른쪽으로 이동하기 위해 right 오른쪽으로 이동할 수 있습니다. 기본값 : righttransform: rotate() . 기본값 : -20transform: rotate() . 기본값 : 20left 에서 오른쪽으로 이동하기 위해 right 오른쪽으로 이동할 수 있습니다. 기본값 : rightopacity 에 대한 최소값 (0과 1). 기본값 : 0opacity 에 대한 최대 값 (0과 1). 기본값 : 1false (펄스가 높을수록 더 눈에 띄게됩니다)[0,0,0][255,255,255][0,0,0][255,255,255]border-radius 에 제공되는 최소값. 기본값 : 0border-radius 에 제공되는 최대 값. 기본값 : 25falsefilter: blur() . 기본값 : 0filter: blur() . 기본값 : 8falseup 또는 down 구부러져야하는지 여부. 기본값 : downright 또는 left 스윙 해야하는지 여부. 기본값 : right20letter-spacing 에 제공되는 최소값. 기본값 : 0letter-spacing 에 제공되는 최대 값. 기본값 : 25false[0,0,0][255,255,255]border-width 에 주어진 최소값. 기본값 : 0border-width 에 주어진 최대 값. 기본값 : 5font-width 에 제공되는 최소값. 기본값 : 0.8font-width 에 제공되는 최대 값. 기본값 : 1.2tilt 에 주어진 최소값. 기본값 : 20tilt 에 주어진 최대 값. 기본값 : 25false[0,0,0][255,255,255]각 시각적 효과를 보려면 데모로 이동할 수 있습니다.
자신의 댄스 유형을 사용하려면 내장 댄스 키 대신 addRythm 의 두 번째 인수로 객체를 제공해야합니다.
이 객체에는 두 가지 속성이 있어야합니다.
/* The custom function signature is
* @elem: The HTML element target you want to apply your effect to
* @value: The current pulse ratio (percentage between 0 and 1)
* @options: The option object user can give as last argument of addRythm function
*/
const pulse = ( elem , value , options = { } ) => {
const max = options . max || 1.25
const min = options . min || 0.75
const scale = ( max - min ) * value
elem . style . transform = `scale( ${ min + scale } )`
}
/* The reset function signature is
* @elem: The element to reset
*/
const resetPulse = elem => {
elem . style . transform = ''
}
addRythm ( 'my-css-class' , { dance : pulse , reset : resetPulse } , 150 , 40 )모든 풀 요청에 감사드립니다. 다음 단계에 따라이 프로젝트에서 코딩을 시작할 수 있습니다.
npm install 실행하십시오npm start .v2.2.x에서 새로운 댄스 유형을 추가하는 것은 매우 쉽습니다.
srcdances 에서 새 파일을 만듭니다 예를 들어, jump.js 파일의 내용은 다음과 같습니다.
/* The function signature is
* @elem: The HTML element target you want to apply your effect to
* @value: The current pulse ratio (percentage between 0 and 1)
* @options: The option object user can give as last argument of addRythm function
*/
export default ( elem , value , options = { } ) => {
const max = options . max || 30
const min = options . min || 0
const jump = ( max - min ) * value
elem . style . transform = `translateY( ${ - jump } px)`
}
/* The reset function signature is
* @elem: The element to reset
*/
export const reset = elem => {
elem . style . transform = ''
}Dancer.js 파일의 생성자에 등록하십시오. import jump , { reset as resetJump } from './dances/jump.js'
class Dancer {
constructor ( ) {
this . registerDance ( 'jump' , jump , resetJump )
}
}라이센스 : Gnu Gpl
저자 : @okazaribzh