@@ -9,20 +9,21 @@ const ctx = canvas.getContext('2d');
99
1010const max_width = window . innerWidth * PIXEL_RATIO ;
1111const max_height = window . innerHeight * PIXEL_RATIO ;
12+ const max_size = Math . min ( max_width , max_height ) ;
1213
13- ctx . canvas . style . width = `${ window . innerWidth } px` ;
14- ctx . canvas . style . height = `${ window . innerHeight } px` ;
15- ctx . canvas . width = max_width ;
16- ctx . canvas . height = max_height ;
14+ ctx . canvas . style . width = `${ max_size / PIXEL_RATIO } px` ;
15+ ctx . canvas . style . height = `${ max_size / PIXEL_RATIO } px` ;
16+ ctx . canvas . width = max_size ;
17+ ctx . canvas . height = max_size ;
1718
1819ctx . fillStyle = 'white' ;
1920ctx . fillRect ( 0 , 0 , canvas . width , canvas . height ) ;
2021
2122const img_canvas = document . createElement ( 'canvas' ) ;
2223const img_ctx = img_canvas . getContext ( '2d' ) ;
2324
24- img_ctx . canvas . width = max_width ;
25- img_ctx . canvas . height = max_height ;
25+ img_ctx . canvas . width = max_size ;
26+ img_ctx . canvas . height = max_size ;
2627img_ctx . fillStyle = 'white' ;
2728img_ctx . fillRect ( 0 , 0 , canvas . width , canvas . height ) ;
2829
@@ -119,6 +120,7 @@ const ishihara_input = {
119120} ;
120121
121122function renderText ( ) {
123+ if ( generating ) return ;
122124 img_ctx . fillStyle = 'white' ;
123125 img_ctx . fillRect ( 0 , 0 , img_canvas . width , img_canvas . height ) ;
124126 ctx . fillStyle = 'white' ;
@@ -185,7 +187,24 @@ gui.add(ishihara_input, 'load_image').name('Load image');
185187gui . add ( ishihara_input , 'color_scheme' , [ 'General 1' , 'General 2' , 'General 3' , 'Protanopia' , 'Protanomaly' , 'Viewable by all' , 'Colorblind only' ] ) . name ( 'Color scheme' ) ;
186188
187189gui . add ( ishihara_input , 'text' ) . name ( 'Text' ) . onChange ( ( ) => renderText ( ) ) ;
188- gui . add ( ishihara_input , 'circular' ) . name ( 'Circular' ) ;
190+ gui . add ( ishihara_input , 'circular' ) . name ( 'Circular' ) . onChange ( value => {
191+ const w = value ? max_size : max_width ;
192+ const h = value ? max_size : max_height ;
193+ canvas . width = w ;
194+ canvas . height = h ;
195+ canvas . style . width = `${ w / PIXEL_RATIO } px` ;
196+ canvas . style . height = `${ h / PIXEL_RATIO } px` ;
197+ img_canvas . width = w ;
198+ img_canvas . height = h ;
199+ ctx . fillStyle = 'white' ;
200+ ctx . fillRect ( 0 , 0 , w , h ) ;
201+ img_ctx . fillStyle = 'white' ;
202+ img_ctx . fillRect ( 0 , 0 , w , h ) ;
203+ ishihara_input . min_radius = ( w + h ) / 800 ;
204+ ishihara_input . max_radius = ( w + h ) / 100 ;
205+ update_gui ( gui ) ;
206+ renderText ( ) ;
207+ } ) ;
189208gui . add ( ishihara_input , 'resize' ) . name ( 'Resize' ) ;
190209gui . add ( ishihara_input , 'shape_factory' , [ 'Circle' , 'Regular polygon' , 'Cross' , 'Star' , 'Heart' ] ) . onChange ( value => {
191210 hide_gui_element ( gui , 'sides' , value !== 'Regular polygon' && value !== 'Star' ) ;
0 commit comments