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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started