Created
August 22, 2024 05:26
-
-
Save duangsuse/c2703fae87c92826a482ef2dd9f523c6 to your computer and use it in GitHub Desktop.
wtf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N2=(x,y=x)=>new _N2(new Float32Array(2),x,y) | |
data=(kv,T)=>{ | |
let s=(T+''), sub=(s,f)=>s.replace(/(\w+)/g,f), kvs=kv.split(','), cg='', | |
vec=(k,v)=>`${k.substr(1)}(v){let a=this._,i=${kvs.length-1};while(i-->0)a[i]${k[0]}=${v}; return this}` | |
if(kvs[0]=='_') { | |
'+p *pp -m /mm'.split(' ').forEach(k=> cg+=vec(k,'v')+'_'+vec(k,'v._[i]')) | |
kvs.slice(1).forEach((k,i)=> cg+=`get ${k}(){return this._[${i}]}set ${k}(v){this._[${i}]=v}`) | |
} | |
T=eval(sub(s,(m,k)=>kvs.includes(k)?`this.${k}`:k).replace('{\n',`{constructor(${kv}){${sub(kv, `this.$1=$1`)}}`+cg))(); this[T.name]=T | |
} | |
data('_,x,y', ({cos,sin,atan2,sqrt,PI}=Math,tr=2*PI)=> | |
class _N2 { | |
get a(){return atan2(y,x)/tr} | |
get v(){return sqrt(y**2+x**2)} | |
turn(a,v){x=v*cos(a*tr);y=v*sin(a*tr); return this} | |
set a(a){this.turn(a,this.v)} | |
set v(v){this.v1(); this.pp(v)} v1(){let v=this.v; if(v!=0)this.mm(v)} | |
get __(){return N2(x,y)} | |
}) | |
doc=document | |
el=(tag,...ee)=>{if(!tag.nodeType)tag=doc.createElement(tag) | |
let e,c,k,rw; while(ee[0]&&!ee[0].nodeType){e=ee.shift() | |
if(e.call){tag.append(c=new Text); e (v=>{c.textContent=v})} | |
else for(k in e){c=tag.getAttributeNode(k),rw=lit(e[k]); | |
rw(c? v=>{c.value=v} : v=>{tag[k]=v;tag.oninput=()=>e[k](tag.value)})}} | |
tag.append(...ee);return tag | |
} | |
lit=x=> x.onvar!=NO? x : f=>f(x) | |
pass=undefined | |
NO=null | |
holey=(v,o={},k='x' ,onvar=[],rw=NO,me=NO)=>(rw=x=>{ | |
let r,f, fu | |
//'i=0'赋值 | |
if(!x.call){if(x!==o[k]){o[k]=x; for(fu of onvar)fu(x)} return me} | |
//'i++'关系: B=A (x=>x+1) | |
if(x.length>1)return ev=>rw(x(o[k],ev)) | |
if(pass===(r=x(o[k]))) {f=v=>x(v)} | |
else {r=holey(r); f=v=>{r(x(v))} } | |
onvar.push(f); return r | |
}, o[k]=v, me=hide(rw,onvar,()=>o[k])) | |
hide=(ㅤ,A,B ,f)=>(f=x=>ㅤ(x),f.onvar=A,f.__defineGetter__('v',f.toJSON=B), f) | |
口=holey | |
let A=口(0), B=A(x=>+x+1) | |
el(doc.body, el("div",{onclick:A((x,to)=>+x+1)}, el("input",{value:A}), el("u",B))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment