Draw shape pointlist - homework

Greetings.

I'll first state that I'm a CS student so please don't provide a solution to my question.

I just want to know if I'm on the right path. Think I've been maybe 8 hours trying to do this...

My homework consists of a few images, a canvas and some buttons.

Everything is working, right now I'm on the last part of the homework. I have to use the canvas to touch in a spot, drag a diagonal line up or down and after ending the drag a rectangle must be drawn.

What I've done so far:

Create a global empty list.
When trying to draw the rectangle I add items to the list, 8 items to be converted to pairs of x,y coordinates.

When I try to set the x1,y1, x2,y2 etc it's not working. I think there must be something off with the values because if I remove items from the list I get an error. So I know the list is good. Testing with static values I can draw the rectangle.

What I'm not sure, didn't find information about it either...are the pointList values used clockwise?

I tried using math thinking it goes clockwise since my previous x,y and the current would be x1,y1 and x3,y3?

I'm using the drag handler of the canvas, tried to use touchup but didn't make sense.

The professor gave us a hint saying that one of the corners is x1,y1 and the other is x2,y2.

As an alternative I thought about of recording the drag x, y values and then creating the lines using math blocks...not sure if it can be done.

This are the blocks I'm trying to use, the x, y values may be misplaced... it's late.

Thanks for reading this and for your time.

1 Like

Hint: Review how Canvas coordinates are plotted Creating Animated Apps and perhaps https://undergroundmathematics.org/geometry-of-equations/r5967/solution or https://math.stackexchange.com/questions/2061270/geometry-creating-rectangle-given-2-diagonal-points

1 Like

Thank you very much SteveJG.

I'll give it a go.

The x1,y1 and x2,y2 co-ordinates of your line drag will provide you with all the co-ordinates you need to draw a rectangle, you just have to use the values in different pairs.

1 Like

Thank you so much both!

It's working!

Saved the coordinates x1,y1 from drag and used the touchup event of the canvas.

:grin: :+1:

excellent... this is the correct attitude...
Taifun

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.