|
Hello guys, I practiced drawing and I have a question: Why the right line of the arrow goes edge-to-edge? Also why without .stroke() I can't see anything? Thank you.
|
|
@andrea wants us to be the compiler!
This is a great chance for you to practice being the compiler! Grab a piece of paper and a pencil, the FOLLOW YOUR DIRECTIONS exactly as you have them.
Solving your arrow problemI didn't see the problem immediately. These were the steps I followed to solve your problem. But, I don't think I should just give you the answer. BE THE COMPILER. Follow your own directions. Keep coding!Also, I encourage you to put LOTS OF COMMENTS INTO YOUR CODE. |
|
@andrea asks a language design question:
Others might say "this is a feature, not a bug." Probably way before iOS, iPhones, and iPads back when programs were only written for the MacOS, someone looked how to best optimize the way shapes and images were drawn to the screen. Processors weren't the fastest. So languages took optimization seriously. These decisions were made long ago. As you can see, you first must layout all the edges of your path describing when to put the "pen" down on the paper, and when to "draw" a line from one point to the next. Then, when the entire path is defined, you can select how those lines are drawn. There are many, many options that you've not even encountered yet. Think of these options as the path's "ink". Do you want dashed lines? Once you have your shape defined, you can also define the path's look and feel. When you have all this decided, you make the shape appear by finally adding "ink" to your path. |
|
@Obelix I changed the coordinates and it works. Please can you tell me your previous solution on the math question? I have difficulties on math :( My code:
|
|
Break your big problem into smaller, solvable problems.
All the drawing takes place inside of a rectangle, which you defined as
As an example, let's say your rectangle is 500 pixels wide and 500 pixels tall. You start the right side of your arrow head at this point.
This point is halfway between the left and right edges of the rectangle, ( Now you want to draw a line to the rightSideOfArrowPoint. This is how you defined the xCoordinate. ( Consequently, you draw a line from the coordinate (250, 0) all the way to (2000, 2000). This point is waaaaaaaaaaaay outside of the rectangle. This is why your first arrow wasn't drawn correctly. |
SPONSORED From March 20th to 26th, you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.