@@ -121,8 +121,8 @@ <h2>📝 Editor</h2>
121121const min = Math . min , max = Math . max , random = Math . random ;
122122const step = ( edge , x ) => x >= edge ? 1.0 : 0.0 ;
123123const clamp = ( v , mn , mx ) => Math . max ( mn , Math . min ( mx , v ) ) ;
124- const relumin = ( x ) => Math . min ( x , 0 ) ;
125- const relumax = ( x ) => Math . max ( x , 0 ) ;
124+ const relumin = ( x ) => x >= 0 ? undefined : x ;
125+ const relumax = ( x ) => x <= 0 ? undefined : x ;
126126function gcd ( a , b ) {
127127 while ( b ) {
128128 [ a , b ] = [ b , a % b ] ;
@@ -145,11 +145,33 @@ <h2>📝 Editor</h2>
145145 if ( n <= 0 ) return [ ] ;
146146 const seq = [ 1 ] ;
147147 for ( let i = 2 ; i <= n ; i ++ ) {
148- seq . push ( seq [ seq . length - 1 ] * i ) ;
148+ seq . push ( seq [ seq . length - 1 ] * i ) ;
149149 }
150150 return seq ;
151151}
152152
153+ function isprime ( x ) {
154+ if ( x < 2 ) { return false ; }
155+ if ( x <= 3 ) { return true ; }
156+ if ( x % 2 === 0 || x % 3 === 0 ) { return false ; }
157+ for ( let i = 5 ; i * i <= x ; i += 6 ) {
158+ if ( x % i === 0 || x % ( i + 2 ) === 0 ) {
159+ return false ;
160+ }
161+ }
162+ return true ;
163+ }
164+
165+ // According to this logic, almost all functions can be turned into prime versions. like fib-prime or mersenne-prime with add condition
166+ function primorial ( n ) {
167+ if ( n <= 0 ) return [ ] ;
168+ const seq = [ 1 ] ;
169+ for ( let i = 2 ; i <= n ; i ++ ) {
170+ if ( isprime ( i ) ) { seq . push ( seq [ seq . length - 1 ] * i ) ; }
171+ }
172+ return seq ;
173+ }
174+
153175function fib ( n ) {
154176 if ( n <= 0 ) return [ ] ;
155177 if ( n === 1 ) return [ 0 ] ;
@@ -473,7 +495,31 @@ <h2>📝 Editor</h2>
473495 return cmul ( x , cexp ( cadd ( cmul ( clog ( t ) , complex ( 0.5 + w . x , w . y ) ) , t . scale ( - 1.0 ) ) ) ) . scale ( 2.50662827463 ) ;
474496}
475497function cgamma_left ( z ) { return ( cmul ( csin ( z . scale ( Math . PI ) ) , cgamma_right ( complex ( 1.0 - z . x , - z . y ) ) ) ) . inv ( ) . scale ( Math . PI ) ; }
476- function cgamma ( x , y ) { const z = toComplex ( x , y ) ; return z . x < 0.5 ? cgamma_left ( z ) : cgamma_right ( z ) ; }
498+ function cgamma ( x , y ) { let z = toComplex ( x , y ) ; z = complex ( z . x + 1.0 , z . y ) ; return z . x < 0.5 ? cgamma_left ( z ) : cgamma_right ( z ) ; }
499+
500+ const EULER_GAMMA = 0.5772156649015329 ;
501+ function cgammaw ( x , y ) {
502+ let z = toComplex ( x , y ) ; z = complex ( z . x + 1.0 , z . y ) ;
503+ const one = complex ( 1.0 , 0.0 ) ;
504+ let result = cmul ( z , cexp ( z . scale ( EULER_GAMMA ) ) ) ;
505+ for ( let n = 1 ; n <= 256 ; n ++ ) {
506+ const invn = 1.0 / n ;
507+ result = cmul ( result , cmul ( z . scale ( invn ) . add ( one ) , cexp ( z . scale ( - invn ) ) ) ) ;
508+ }
509+ return result . inv ( ) ;
510+ }
511+
512+ function cgammap ( x , y ) {
513+ let z = toComplex ( x , y ) ; z = complex ( z . x + 1.0 , z . y ) ;
514+ const one = complex ( 1.0 , 0.0 ) ;
515+ let result = cmul ( z , cexp ( z . scale ( EULER_GAMMA ) ) ) ;
516+ const primesv = primes ( 256 ) ;
517+ for ( let n = 0 ; n < primesv . length ; n ++ ) {
518+ const invn = 1.0 / primesv [ n ] ;
519+ result = cmul ( result , cmul ( z . scale ( invn ) . add ( one ) , cexp ( z . scale ( - invn ) ) ) ) ;
520+ }
521+ return result . inv ( ) ;
522+ }
477523
478524function randomColor ( ) { const h = Math . floor ( Math . random ( ) * 360 ) ; return `hsl(${ h } ,70%,55%)` ; }
479525
@@ -502,7 +548,6 @@ <h2>📝 Editor</h2>
502548 render ( ) ;
503549}
504550window . addEventListener ( 'resize' , resize ) ;
505-
506551canvas . addEventListener ( 'mousedown' , e => { dragging = true ; lx = e . clientX ; ly = e . clientY ; } ) ;
507552canvas . addEventListener ( 'mousemove' , e => {
508553 if ( ! dragging ) return ;
@@ -517,14 +562,8 @@ <h2>📝 Editor</h2>
517562
518563function zoom ( f ) { scale *= f ; render ( ) ; }
519564function resetView ( ) { scale = 50 ; cx = 0 ; cy = 0 ; render ( ) ; }
520-
521- function toScreen ( x , y ) {
522- return [ ( x - cx ) * scale + canvas . width / 2 , canvas . height / 2 - ( y - cy ) * scale ] ;
523- }
524-
525- function toMath ( px , py ) {
526- return [ ( px - canvas . width / 2 ) / scale + cx , - ( py - canvas . height / 2 ) / scale + cy ] ;
527- }
565+ function toScreen ( x , y ) { return [ ( x - cx ) * scale + canvas . width / 2 , canvas . height / 2 - ( y - cy ) * scale ] ; }
566+ function toMath ( px , py ) { return [ ( px - canvas . width / 2 ) / scale + cx , - ( py - canvas . height / 2 ) / scale + cy ] ; }
528567
529568function render ( ) {
530569 const W = canvas . width , H = canvas . height ;
0 commit comments