@@ -184,6 +184,15 @@ class RaylibJs {
184
184
this . ctx . fillRect ( posX , posY , width , height ) ;
185
185
}
186
186
187
+ DrawRectangleV ( position_ptr , size_ptr , color_ptr ) {
188
+ const buffer = this . wasm . instance . exports . memory . buffer ;
189
+ const color = getColorFromMemory ( buffer , color_ptr ) ;
190
+ const position = new Float32Array ( buffer , position_ptr , 2 ) ;
191
+ const size = new Float32Array ( buffer , size_ptr , 2 ) ;
192
+ this . ctx . fillStyle = color ;
193
+ this . ctx . fillRect ( position [ 0 ] , position [ 1 ] , size [ 0 ] , size [ 1 ] ) ;
194
+ }
195
+
187
196
IsKeyPressed ( key ) {
188
197
return ! this . prevPressedKeyState . has ( key ) && this . currentPressedKeyState . has ( key ) ;
189
198
}
@@ -344,6 +353,41 @@ class RaylibJs {
344
353
this . ctx . fillText ( text , posX , posY + fontSize ) ;
345
354
}
346
355
356
+ GetRandomValue ( min , max ) {
357
+ return min + Math . floor ( Math . random ( ) * ( max - min + 1 ) ) ;
358
+ }
359
+
360
+ ColorFromHSV ( result_ptr , hue , saturation , value ) {
361
+ const buffer = this . wasm . instance . exports . memory . buffer ;
362
+ const result = new Uint8Array ( buffer , result_ptr , 4 ) ;
363
+
364
+ // Red channel
365
+ let k = ( 5.0 + hue / 60.0 ) % 6 ;
366
+ let t = 4.0 - k ;
367
+ k = ( t < k ) ? t : k ;
368
+ k = ( k < 1 ) ? k : 1 ;
369
+ k = ( k > 0 ) ? k : 0 ;
370
+ result [ 0 ] = Math . floor ( ( value - value * saturation * k ) * 255.0 ) ;
371
+
372
+ // Green channel
373
+ k = ( 3.0 + hue / 60.0 ) % 6 ;
374
+ t = 4.0 - k ;
375
+ k = ( t < k ) ? t : k ;
376
+ k = ( k < 1 ) ? k : 1 ;
377
+ k = ( k > 0 ) ? k : 0 ;
378
+ result [ 1 ] = Math . floor ( ( value - value * saturation * k ) * 255.0 ) ;
379
+
380
+ // Blue channel
381
+ k = ( 1.0 + hue / 60.0 ) % 6 ;
382
+ t = 4.0 - k ;
383
+ k = ( t < k ) ? t : k ;
384
+ k = ( k < 1 ) ? k : 1 ;
385
+ k = ( k > 0 ) ? k : 0 ;
386
+ result [ 2 ] = Math . floor ( ( value - value * saturation * k ) * 255.0 ) ;
387
+
388
+ result [ 3 ] = 255 ;
389
+ }
390
+
347
391
raylib_js_set_entry ( entry ) {
348
392
this . entryFunction = this . wasm . instance . exports . __indirect_function_table . get ( entry ) ;
349
393
}
0 commit comments