1+ import ImageLoader from "./imageLoader.js"
2+
13export default class Vignettes {
24
35 constructor ( ) {
46 this . _scenes = [ ] ;
7+ this . _image_loader = new ImageLoader ( ) ;
58 this . _current_scene = 0 ;
9+ this . _recording = false ;
610 }
711
812 add_scene ( scene ) {
@@ -13,6 +17,10 @@ export default class Vignettes{
1317 if ( this . _scenes . length > 0 ) {
1418 this . _scenes [ this . _current_scene ] . draw ( ) ;
1519 }
20+
21+ if ( this . _recording ) {
22+ this . capture_frame ( ) ;
23+ }
1624 }
1725
1826 click ( ) {
@@ -33,24 +41,68 @@ export default class Vignettes{
3341 }
3442 }
3543
36- key_pressed ( keyboard_event ) {
44+ key_pressed ( ) {
3745
38- console . log ( keyCode ) ;
39- if ( keyCode == 39 ) {
40- this . _current_scene = this . _current_scene - 1 ;
41- this . _current_scene = this . _current_scene < 0 ? this . _scenes . length - 1 : this . _current_scene ;
42- } else if ( keyCode == 37 ) {
43- this . current_scene = ( this . current_scene + 1 ) % this . _scenes . length ;
46+ console . log ( keyCode , key ) ;
47+
48+ if ( key == "ArrowRight" ) { // 'rightArrow'
49+ this . increment_current_scene ( ) ;
50+ } else if ( key == "ArrowLeft" ) { // 'leftArrow'
51+ this . decrement_current_scene ( ) ;
52+ } else if ( key == "r" && ! this . _recording ) { // 'r'
53+ this . begin_recording ( ) ;
54+ } else if ( key == "r" && this . _recording ) {
55+ this . end_recording ( ) ;
4456 } else if ( this . _scenes . length > 0 ) {
4557 this . _scenes [ this . _current_scene ] . key_pressed ( ) ;
4658 }
4759
48- console . log ( this . _current_scene ) ;
60+ }
4961
62+ increment_current_scene ( ) {
63+ this . _current_scene = ( this . _current_scene + 1 ) % this . _scenes . length ;
64+ }
65+
66+ decrement_current_scene ( ) {
67+ this . _current_scene = this . _current_scene - 1 ;
68+ this . _current_scene = this . _current_scene < 0 ? this . _scenes . length - 1 : this . _current_scene ;
5069 }
5170
5271 key_released ( keyboard_event ) {
5372 this . _scenes [ this . _current_scene ] . key_released ( ) ;
5473 }
5574
75+ begin_recording ( ) {
76+ console . log ( "started recording" ) ;
77+ ccapturer . start ( ) ;
78+ this . capture_frame ( ) ;
79+ this . _recording = true ;
80+ }
81+
82+ capture_frame ( ) {
83+ ccapturer . capture ( p5Canvas ) ;
84+ }
85+
86+ end_recording ( ) {
87+ console . log ( "finished recording" ) ;
88+ ccapturer . stop ( ) ;
89+ ccapturer . save ( ) ;
90+ this . _recording = false ;
91+ }
92+
93+ //-------------image loading and displaying------------------
94+ load_image ( name , file_type ) {
95+ this . _image_loader . load_image ( name , file_type ) ;
96+ }
97+ load_image_sequence ( name , file_type , sequence_length ) {
98+ this . _image_loader . load_image_sequence ( name , file_type , sequence_length ) ;
99+ }
100+ draw_image ( name , x , y ) {
101+ this . _image_loader . draw_image ( name , x , y ) ;
102+ }
103+ draw_image_from_sequence ( name , x , y , frame ) {
104+ this . _image_loader . draw_image_from_sequence ( name , frame , x , y ) ;
105+ }
106+ //-----------------------------------------------------------
107+
56108}
0 commit comments