import type { IObjectOf } from "@thi.ng/api" ; import { reactive , Stream } from "@thi.ng/rstream/stream" ; import { assocObj } from "@thi.ng/transducers/assoc-obj" ; import { map } from "@thi.ng/transducers/map" ; import { pairs } from "@thi.ng/transducers/pairs" ; import { push } from "@thi.ng/transducers/push" ; import { transduce } from "@thi.ng/transducers/transduce" ; const slider = ( label , attribs , stream ) => ( ) => [ "div.mb2" , [ "span.dib.w4" , label ] , [ "input.w5" , { ... attribs , type : "range" , value : stream . deref ( ) , oninput : ( e ) => stream . next ( parseFloat ( ( < HTMLInputElement > e . target ) . value ) ) , } , ] , [ "span.ml3" , stream . deref ( ) ] , ] ; type ParamDef = [ string , any , number ] ; export const PARAM_DEFS = { radius : [ "radius" , { min : 2 , max : 64 , step : 1 } , 32 ] , bias : [ "bias" , { min : - 0.2 , max : 0.2 , step : 0.01 } , 0.09 ] , baseAttenuation : [ "base attenuation" , { min : 0.1 , max : 2 , step : 0.01 } , 1 ] , distAttenuation : [ "dist attenuation" , { min : 0.1 , max : 2 , step : 0.01 } , 1.2 ] , amp : [ "amplitude" , { min : 0 , max : 1 , step : 0.01 } , 1 ] , specular : [ "specular" , { min : 0 , max : 1 , step : 0.01 } , 0.25 ] , lightTheta : [ "light rotation" , { min : 0 , max : 3.14 , step : 0.01 } , 0.48 ] , eyeDist : [ "cam distance" , { min : 5 , max : 10 , step : 0.01 } , 5 ] } ; export const PARAMS = transduce ( map < [ string , ParamDef ] , [ string , Stream < number > ] > ( ( [ id , spec ] ) => [ id , reactive ( spec [ 2 ] ) , ] ) , assocObj ( ) , pairs ( PARAM_DEFS ) ) ; export const CONTROLS = transduce ( map ( ( [ id , [ label , attribs ] ] ) => slider ( label , attribs , PARAMS [ id ] ) ) , push ( ) , pairs ( PARAM_DEFS ) ) ;