Geting coordinates canvas

Hi, everyone,
I'm trying to draw a line on the canvas and then after I draw and press a button it will draw black dots on the line. So the way I did it I saved the coordinates of the points I drag in a list and then from the list I get the coordinates and draw points. It worked partially and I got stuck in the problem that it drew some of the points on the line but some of the points it just drew not on the line and in a random place on the canvas. I would appreciate it if someone could help me and explain to me why this is happening. Thanks


You used the For Each Item In List block where you should have used the For Each Number From 1 to Length Of List by 2 block.

That would eliminate the search for where you are in traversing the point list

Did you know you could make new lists [x,y] and add those lists to another list?

That's called a table.

Hello Yosi

That isn't a line, it's a random, non-uniform curve, so establishing points on it is tricky.

  1. How is the curve drawn in the first instance? Is that the User dragging a finger on the Canvas?

  2. Where does the Points List come from?

The first thing is that the user draws a regular line on the canvas. After he draws the line then when he presses a button black dots should appear along the entire line he drew. Some of the black dots appear on and some that I don't understand why don't appear on the line as you can see in the picture. Can you explain to me why some of the dots don't appear on the line?

You were close, but try this:

wow, Thank you it works great.
But do you know what was the problem with the first code i did?

Use Do It when in companion to show the points generated by your blocks, and compare with your original data list....

You kept losing your place in the list when you went to put together an x,y pair for plotting the next point from the unravelled list you built.

The index in list block would look for just the first item in the list with that value, regardless of how many other points had that same x or y value you used in your search.

So the random points that you plotted were hybrid children of parts of other points, with mismatched x and y.

Here's an experiment to try with your original code, if you still have it.

Draw a really straight diagonal line, with no wiggles in any direction.
If it is really straight and diagonal, there should be no ambiguity as to which y goes with which x. There should be no random points when you redraw, or they should be very close to the line if youwavered when you drew the line.

Now clear everything, and draw a spiral in the center third of the canvas, wrapping around a few times to hit lots of x and y values repeatedly. The random dots you find should appear only in that center third, because you never left that zone.

This is why shoe stores package their shoes in boxes, so the left and right shoes don't get mixed up with other pairs of shoes.

3 Likes

OK ,
thank you