Last active
October 23, 2019 10:37
-
-
Save dapi/53384fe200773da5d848327e756f8347 to your computer and use it in GitHub Desktop.
Проверять тут - http://sketch.paperjs.org/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var title = new PointText(new Point(200, 10)); | |
| title.content="click - установка стрелки, drug - перемещени, shift-drug - вращение" | |
| var debug = new PointText(new Point(200, 50)); | |
| var currentArrow; | |
| var raster = new Raster({ | |
| source: "https://paraquest.ru/uploads/slide/image/20/2018-11-12_21_10_04-Улет_с_Аламнера3.png", | |
| position: view.center | |
| }); | |
| var arrow_options = { | |
| segments: [[0,0], [35,0], [35, 7], [50,0], [35,-7], [35, 0]], | |
| strokeColor: 'red', | |
| fillColor: 'red', | |
| strokeWidth: 2, | |
| strokeCap: 'round', | |
| }; | |
| var arrowPath = new Path(arrow_options); | |
| // Бокс предназначен для большей зона охвата мышкой | |
| var boxPath = new Path.Rectangle([-5,-15], [55,30]); | |
| boxPath.strokeColor='black'; | |
| boxPath.fillColor='black'; | |
| boxPath.opacity=0; | |
| var path = new Group([arrowPath, boxPath]); | |
| var definition = new SymbolDefinition(path); | |
| var originalRotation = 45; | |
| var lastRotation = originalRotation; | |
| var items = 0 | |
| var firstPoint; | |
| var placeArrow = function(point) { | |
| var i = definition.place(); | |
| var savedRotation; | |
| i.onMouseDown = function(event) { | |
| savedRotation = i.rotation; | |
| firstPoint = event.point; | |
| i.selected = true; | |
| } | |
| i.onMouseUp = function(event) { | |
| i.selected = false; | |
| } | |
| i.onDoubleClick = function(event) { i.remove(); } | |
| i.onMouseDrag = function(event) { | |
| if (event.modifiers.shift) { | |
| var x = event.point.x - firstPoint.x; | |
| var y = event.point.y - firstPoint.y; | |
| var ab = 0 + y*100; | |
| var a = Math.sqrt(Math.pow(0,2) + Math.pow(100,2)); | |
| var b = Math.sqrt(Math.pow(x,2) + Math.pow(y,2)); | |
| var angle = Math.acos(ab/(a*b)); | |
| i.rotation = 180 / Math.PI * Math.atan2(y, x); | |
| lastRotation = i.rotation; | |
| } else { | |
| i.position = event.point; | |
| } | |
| } | |
| i.name = 'arrow'; | |
| i.position = point; | |
| i.rotate(lastRotation); | |
| items +=1; | |
| } | |
| tool.onMouseDown = function(event) { | |
| if (!(event.item && event.item.name == 'arrow')) { | |
| placeArrow(event.point); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment