How to convert x,y coordinates to an angle?

前端 未结 6 840
暗喜
暗喜 2020-12-13 06:49

Microsoft provide an excellent SVG gradient maker so IE9 can also have \"CSS3\" gradients (click Custom).

I currently utilise their logic for my Fireworks and Dreamw

6条回答
  •  长情又很酷
    2020-12-13 07:24

    var x,x1,x2,y,y1,y2;
    var cells = 'cell0';
    		var h,w;
    		var cx,cy;
    		var dx,dy;
    		var derajat;
    		var deg;
    		var ang;
    		var light;
    		var control;
    			function mouse_watch(event){
    				x = event.clientX;
    				y = event.clientY;
    				cell_data(cells);
    				koordinat(x2,y2);
    				busur(derajat);
    			}
    			function koordinat(x2,y2){
    				x2 = x-cx;
    				y2 = y-cy;
    				yk = y2;
    				xk = x2;
    			}
    			function busur(derajat){
    
    				y1 = Math.sqrt((Math.abs(yk)*Math.abs(yk))+(Math.abs(xk)*(Math.abs(xk))));
    				x1 = 0;
    				dy = yk-y1;
    				dx = xk-x1;
    				rad = Math.atan2(dy, dx);
    				derajat = rad * (360 / Math.PI);
    				cell = document.getElementById(cells);
    				ang = cell.getElementsByClassName('angle0')[0];
    				ang.style.transform = 'rotate('+derajat+'deg)';
    				light = ang.getElementsByClassName('points')[0];
    				light.style.height = y1+'px';
    			}
    			function cell_data(cells){
    				cell = document.getElementById(cells);
    				h = Number(cell.style.height.replace('px',''));
    				w = Number(cell.style.width.replace('px',''));
    				cy = Number(cell.style.top.replace('px',''))+h/2;
    				cx = Number(cell.style.left.replace('px',''))+w/2;
    			}
    			.preview_engine{
    				position: absolute;
    				top: 0;
    				left: 0;
    				padding: 10px;
    				background-color: #2E8AE6;
    				color: white;
    			}
    			body{
    				cursor: default;
    				width: 100%;
    				height: 100%;
    				font-family: Arial;
    				font-size: 12px;
    			}
    			.fieldwork{
    				width: 100%;
    				height: 100%;
    				position: absolute;
    				top: 0px;
    				left: 0px;
    			}
    			.cell{
    				position: relative;
    				transition : width 2s, height 2s, top 2s, left 2s;
    				background-color: red;
    			}
    			.angle0{
    				width: 200px;
    				height: 200px;
    				position: absolute;
    				top: -75px;
    				left: -75px;
    				background-color: green;
    				border-radius: 50%;
    				opacity: 0.5;
    				transition : width 2s, height 2s, top 2s, left 2s;
    			}
    			.points{
    				width: 10px;
    				height: 10px;
    				position: absolute;
    				left: 95px;
    				top: 95px;
    				background-color: red;
    				border-radius: 1em;
    				opacity: none;
    			}

提交回复
热议问题