Question: I am writing a program that will allow the user to move the crosshairs with the mouse I am having trouble getting the crosshairs to

I am writing a program that will allow the user to move the crosshairs with the mouse I am having trouble getting the crosshairs to move using function moveCrosshairs(e). Can you help and explain how to do this? Thank you. Here is my code:

/*This program will allow the user to use the mouse to draw crosshairs that follow the mouse*/

let hLine; let vLine; function main(){

drawCrosshairs(); mouseMoveMethod(moveCrosshairs); } /*initializes crosshairs through center of the canvas before the user moves mouse*/ function drawCrosshairs(){

//draw horizontal line

hlLine = new Line(0,getHeight()/2,getWidth(),getHeight()/2); hLine.setColor("black"); hLine.setLineWidth(2); add(hLine);

//draw vertical line vLine = new Line(getWidth()/2,0, getWidth()/2,getHeight()); vLine.setColor("black"); vLine.setLineWidth(2); add(vLine); } function moveCrosshairs(e){ hlLine.setPosition(0,e.getY()); hLine.setEndpoint(getWidth(),e.getY(); vLine.setPosition(e.getX(),0); vLine.setPostion(e.getX(),get(Height());

}

main();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!