path-2d

How to position Path2D SVG element in canvas?

自古美人都是妖i 提交于 2021-01-01 18:41:23
问题 I'm drawing a path2D SVG shape on canvas. The problem is that the moveTo function does not seem to work when using SVG data. The problem is illustrated in this codepen. https://codepen.io/grasmachien/pen/rNaJeBN const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); let p = new Path2D('M10 10 h 80 v 80 h -80 Z'); p.moveTo(100,100) ctx.fill(p); Is there a way to move the path without moving the canvas? 回答1: Use the transform to move the path Using

How to position Path2D SVG element in canvas?

99封情书 提交于 2021-01-01 18:36:30
问题 I'm drawing a path2D SVG shape on canvas. The problem is that the moveTo function does not seem to work when using SVG data. The problem is illustrated in this codepen. https://codepen.io/grasmachien/pen/rNaJeBN const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); let p = new Path2D('M10 10 h 80 v 80 h -80 Z'); p.moveTo(100,100) ctx.fill(p); Is there a way to move the path without moving the canvas? 回答1: Use the transform to move the path Using

Java Class Cast Exception java.awt.geom.Path2D.Double

扶醉桌前 提交于 2020-01-05 02:46:32
问题 I've been getting this class cast exception when trying to to implement an AffineTransform. Call to AffineTransform: public Shape moveToAndRotate(double x, double y, double theta) { double cx = getBounds2D().getCenterX(); double cy = getBounds2D().getCenterY(); at.translate(cx, cy); at.translate(x, y); at.rotate(Math.toRadians(theta)); at.translate(-cx, -cy); return at.createTransformedShape(yingYang); } This is resides in a custom shape class (YingYang). public class YingYang implements

Mouse pointer detection over a Path2D

北慕城南 提交于 2020-01-01 09:44:14
问题 I have constructed a Path2D that represents an unclosed shape consisting of straight lines: I want to be able to detect when the mouse is clicked and the mouse pointer is near to (within a few pixels of) the path. Using the contains method does not work because the algorithm treats the unclosed shape as implicitly closed (i.e. by drawing a straight line between the start and end points). Does anyone know of another mechanism for achieving this? 回答1: Create a BasicStroke (the width controls

How can I draw a polygon using path2d and see if a point is within it's area?

谁说我不能喝 提交于 2019-12-22 10:28:48
问题 I,m trying to draw a polygon shape of any kind using multiple vertices with path2d and I want to later on see if a determinate point is within its area using java.awt.geom.Area public static boolean is insideRegion(Region region, Coordinate coord){ Geopoint lastGeopoint = null; GeoPoint firstGeopoint = null; final Path2D boundary = new Path2D.Double(); for(GeoPoint geoponto : region.getGeoPoints()){ if(firstGeopoint == null) firstGeopoint = geoponto; if(lastGeopoint != null){ boundary.moveTo

Path2D.addPath got removed?

心已入冬 提交于 2019-12-11 04:27:28
问题 I have been working with Path2D for a while, but now it seems like it's function Path2D.addPath(path, matrix?) got removed (at least in chrome). Is there actually any replacement? Is it permanent, or just a mistake on browser part? 回答1: This is the information on addPath from MDN (and shameless plug): "addPath" (NOTE: EXPERIMENTAL, on standard track) DESKTOP: Chrome | Firefox | Edge | IE | Opera | Safari --------+---------+---------+---------+---------+---------- Yes | 34 | - | - | Yes | Yes

Let an Enemy follow a path with the same speed

£可爱£侵袭症+ 提交于 2019-12-11 01:29:38
问题 I started programming a game in java. I have Enemys and a Player, a basic 2D game, thats to get experience for the first time. Now i wanted the Enemys to follow a path, which i can draw in to a "level editor". I have a JPanel, a mouseMoveListener, and on click the Path2D starts saving the mouseMove Points to a Path2D.Double Object. After that, i implemented the following method to make the enemys following this path: public void forward(){ if(!pathIterator.isDone()){ pathIterator

Using Path2D in a TypeScript project is not resolved

余生颓废 提交于 2019-12-10 18:36:41
问题 I want to use the new Path2D api in a TypeScript project but I don't see it in lib.es6.d.ts What is my best course of action to use this? Does anyone have a d.ts file for Path2D? 回答1: I took me some time, and I made the Declaration for you: I've done this following the same standard TypeScript defines its interfaces internally in lib.d.ts . Note that you can extend this code easily for future features, and if you do I would love to see it updated here. Path2D.d.ts (View in TypeScript

How can I draw a polygon using path2d and see if a point is within it's area?

[亡魂溺海] 提交于 2019-12-05 18:46:05
I,m trying to draw a polygon shape of any kind using multiple vertices with path2d and I want to later on see if a determinate point is within its area using java.awt.geom.Area public static boolean is insideRegion(Region region, Coordinate coord){ Geopoint lastGeopoint = null; GeoPoint firstGeopoint = null; final Path2D boundary = new Path2D.Double(); for(GeoPoint geoponto : region.getGeoPoints()){ if(firstGeopoint == null) firstGeopoint = geoponto; if(lastGeopoint != null){ boundary.moveTo(lastGeopoint.getLatitude(),lastGeopoint.getLongitude()); boundary.lineTo(geoponto.getLatitude()