porting sketch code to js