How do I achive draw on line functionality in flutter? - flutter

So this is the kind of project I'm working on right now. What I want is to generate random lines and then want the user to draw on that line. I want to make the line fade initially and then make its area look solid (opacity: 1), the area that has been drawn by the user, the rest will still fade. The user needs to draw on top of that line. So the question is that how do I generate these random lines? And once generated how do I listen for their tracing like when the user swipes on it with their finger?

Related

How to let the user to build a polygon on the open street map?

UPD: Done. Look at this beautiful polygon.
UPD: In Flutter / openstreetmap, I want to let users draw a polygon by tapping a map and/or clicking a button. The polygon should be not filled. I need a very simple example just to get an idea of how it works.
The final task is:
I am making a flutter application that should give the user the ability to get information about markers located within a certain area on the map. I use osm. By pressing the button, the user initiates the construction of an arbitrary polygon, each corner of which is formed at the place of the next pressing of the button. When the construction of the polygon is completed, the objects inside the polygon are shown, the rest are hidden or not built. After that, the cycle ends by clearing the map.
I haven't found any solution for osm. I would appreciate any help. I don't have any code yet)
You can use the flutter_map library, I'm sure you can understand the documentation and how to set it up.
Then use PolygonLayerOptions(polygons: [Polygon(points: polygonList)]) as a layer on top of the OSM layer. Then set up the list polygonList and use the FlutterMap()'s onTap callback to get the position at which the user tapped and add the LatLng to the polygonList list. There are multiple other configuration options within the Polygon() constructor, and those can be found through IntelliSense or similar. To have no fill, just set the color to transparent.
I use this method (or a very similar one) for my app which lets users download areas of map. The user taps the top left and bottom right of a rectangular area they want to download, by code calculates the top right and bottom left, and a polygon is drawn to show the user exactly where they tapped. Make sure to use setState() or similar.

SpriteKit - Draw Bezier Curve Gradually

I'm working on an iOS educational where kids are drawing letters. The game mechanism is pretty simple and works OK. What I want to do is to show a drawing progress by turning the elapsed part into green thick line. See the image:
There are couple of solution I have in mind.
Mask over hidden path which transforms according to users touch position
Creating a new path on touchesMoved: by taking the original and adding a point to the user touch position, then stripping the rest
What would you choose or is there some better solution?
Note: I want to draw the green path precisely as the dashed one. By just drawing a path following the user movement would result in ugly line.
Thanks.
I would say your choice depends on whether the dashed line is also drawn (or drawable in all of its parts) with bezier curves.
If the dashed line is an image you show, probably solution 1 with an also drawn thick line and an adapted mask is easiest to do.
If the dashed line is already drawn as a bezier curve (or drawn by drawing several connected bezier curves), then solution 2 seems best to me. The tricky part would be to ensure you exactly follow the dashed line in this case (but I suppose you figured that already :-).

How do I approach smooth line drawing such as the example below in ios 5/6?

I have been developing line drawing apps that produce lines such as these:
I really want to draw lines such as these:
I dont know what technique is used to produce the lines that look like brushwork.
I would appreciate advice, or redirection to a post that looks at this question. I've looked for an hour. I dont know the terminology to ask the right question..
Thanks
You have two problems you need to solve:
How to determine the width of the line to be drawn
Drawing the appropriate width line
Ideally you would want pressure information from the user's finger to know how wide the line should be. The harder the user presses, the fatter the line. However, the capacitive touch devices that run iOS don't have the ability to get this information. So your next option is to use some algorithm based on how fast the user is moving their finger on the screen. Slow movement may mean fatter lines and fast movement may mean thinner lines. Or the reverse, depends on what you want to achieve.
Drawing the appropriate width line has many options depending on whether your app is using OpenGL. Mainly, I would look at using a small anti-aliased circle image that is used to paint into a pixel buffer. Scale the image appropriately to paint sections of the line at varying widths. This part of your question has a lot of options so you may want to ask it as a separate question while also including details of whether you're using OpenGL, Core Graphics or something else.

How to draw a line on MKMapView showing the route a user has taken?

I have had a look around online to try and find out the best way to draw a line showing the route a user has travelled. I think I need to use the MKOverlayView, and I guess I need to collect a selection of data points to plot (would these be GPS coordinates?). The question I have is based on how I would draw the line and keep adding to it as the users location updates?
I also want to be able to clear the line when a user presses a button. How would I implement this (not the button press, just the code to clear the line off the map view)?
Thanks in advance!
You can do this using MKPolyline. At First you need to get coordinates of route, then draw polylines over it. You will find an example here to draw polyline over some coordinates.

How to make a line draw between two points as you are trying to set the second / end point of the line (like drawing a line in MSPAINT!)

I was wondering if anyone would be able to tell me how you would go about this?
e.g.
- User pushes (+) Add Button
- Image appears to let user set start point of line
- After user sets the first point a second image appears and a line is drawn between them and animated between them as user moves the second image into place.
You could see this sort of action in just about any graphics drawing program where a user is required to draw a line; except to help the user know where he is drawing I am including a start/end point image to drag about.
I can draw a line no problems. I am perplexed a little by this as the two images I generate for the user to drag around and set as start/end point are both instances of a class I created (draw2d) that subclasses UIImageView (so I can drag it about).
So at present I am adding two UIImageViews to my UIViewController in order to drag them about - you can't draw a line between two UIImageViews as such as the only drawing I know how to do is IN the UIImageView.
Do I need to nest these two images in a parent-style UIImageView so I can draw between them?
Any assistance is always greatly appreciated.
If I understand correctly, you want to draw the line while the user drags their finger around to set the endpoint?
Can't you just track the dragging positions and re-draw the line each time it changes, using the last dragged position as the 'temporary end point'?
Do I need to nest these two images in
a parent-style UIImageView so I can
draw between them?
Yes.