1- // events.js
2-
3- import { config , mandelbrotCanvas , juliaCanvas , pixelRatio , scalePerZoom , rangeInput , colorCompressionRange , colorCompressionDisplay , themeSelector } from './config.js' ;
1+ import { config , mandelbrotCanvas , pixelRatio , scalePerZoom , rangeInput , colorCompressionRange , colorCompressionDisplay , themeSelector } from './config.js' ;
42import { renderJulia } from './rendering.js' ;
5- import { canvasToMandelbrot , getCanvasCoordinates , preventDefaultBehavior } from './utils.js' ;
3+ import { cursorCoordinates , getCanvasCoordinates , preventDefaultBehavior } from './utils.js' ;
64
75// Update max iterations
86const updateMaxIterations = ( ) => {
@@ -29,7 +27,6 @@ const updateColorCompression = () => {
2927// Track Ctrl key press
3028const handleCtrlKey = ( event , pressed ) => {
3129 if ( event . key === 'Control' ) {
32- console . log ( `Ctrl ${ pressed ? 'pressed' : 'unpressed' } .` ) ;
3330 config . isCtrlPressed = pressed ;
3431 }
3532} ;
@@ -39,7 +36,7 @@ const handleCtrlClick = (event) => {
3936 if ( config . isCtrlPressed && event . button === 0 ) {
4037 preventDefaultBehavior ( event ) ;
4138 const { x, y } = getCanvasCoordinates ( event ) ;
42- const { x : mouseX , y : mouseY } = canvasToMandelbrot ( x , y ) ;
39+ const { x : mouseX , y : mouseY } = cursorCoordinates ( x , y ) ;
4340 config . targetCenter = [ mouseX , mouseY ] ;
4441 }
4542} ;
@@ -51,8 +48,8 @@ const handleWheelZoom = (event) => {
5148 const delta = Math . min ( Math . max ( - event . deltaY * 5 , - 100 ) , 100 ) / 100 ;
5249 config . targetZoom += delta ;
5350
54- const { x : mouseXBefore , y : mouseYBefore } = canvasToMandelbrot ( x , y ) ;
55- const { x : mouseXAfter , y : mouseYAfter } = canvasToMandelbrot ( x , y ) ;
51+ const { x : mouseXBefore , y : mouseYBefore } = cursorCoordinates ( x , y ) ;
52+ const { x : mouseXAfter , y : mouseYAfter } = cursorCoordinates ( x , y ) ;
5653 config . center [ 0 ] += ( mouseXBefore - mouseXAfter ) ;
5754 config . center [ 1 ] += ( mouseYBefore - mouseYAfter ) ;
5855} ;
@@ -67,7 +64,7 @@ const handleMouseMove = (event) => {
6764 }
6865
6966 const { x, y } = getCanvasCoordinates ( event ) ;
70- const { x : mandelbrotX , y : mandelbrotY } = canvasToMandelbrot ( x , y ) ;
67+ const { x : mandelbrotX , y : mandelbrotY } = cursorCoordinates ( x , y ) ;
7168 config . juliaConstant = [ mandelbrotX , mandelbrotY ] ;
7269 renderJulia ( ) ;
7370 document . querySelector ( "#Re" ) . value = mandelbrotX . toFixed ( 8 ) ;
0 commit comments