Académique Documents
Professionnel Documents
Culture Documents
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
The following steps are for testing how the canvas would behave when it is in mobile.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
● This would get the website to a mobile screen view, like this:
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
3. Refresh. We noticed that the canvas resized itself as per the screen size.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
4. When we moved the mouse inside the website, the mouse cursor changed to the
below image (See the highlighted part):
● This icon would act as if your finger is moving on the screen. So when we
coded and tested, we used this as our finger on screen.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
5. We clicked inside the canvas and left it there. We saw a message on the console
screen - my_touchstart. That meant the touch functionality was working.
6. We clicked and moved the mouse inside the canvas and it started painting. This
mouse click and moving the mouse meant - touching on the mobile screen and
moving the finger.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
7. We saw a message on the console screen - my_touchmove and the last and current
x and y and coordinates,
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
9. We refreshed the page, and saw that the canvas resized itself again as per the
screen size.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
So we followed the above steps when we wrote and tested the code.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
We saw in the main.js file that we had the old code which was done in the previous class
which was for the web paint application for desktop.
Now we converted this code and made it fully-functional, so that we can use it on mobiles.
2. The variables which we used to store the last x and y coordinates remained the
same.
3. The reference for the canvas, the variable holding the color, and the variable holding
the width would be the same as well.
4. We fetched the width of the screen and stored it inside the variable. We did this
because we wanted to know which screen size (mobile or pc) the user is using.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
As we learned in bootstrap that the screen width was divided into basic 5 sections:
● Screen width 1200px and more: The big screens: These are for laptops and desktops.
● Screen width between 1200px and 992px: These are for laptops.
● Screen width between 992px and 768px: These are for tablets.
● Screen width less than 768px: These are for mobiles.
We have built this paint application so that users can use this in tablets and mobiles. For
that, we needed to reduce the width and height of the canvas as per the screen of the user
and we wanted this to be applied only to the tablet and mobile screens.
● We wrote an if condition:
○ If the screen size is less than 992 (means 992px), then we changed the width
and height of the canvas with the new width and new height which we had
defined in the above points.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
● The new width and new height of the canvas was 730px and 400px
respectively, so as a result, automatically, our canvas fitted inside the
screen.
● Whenever you reduce or increase the width of the screen (provided it's
less than 992px), the canvas will be resized according to the width of
the screen.
7. Then, we updated the style of the body with a CSS property which was
overflow:hidden. This style disabled the scrolling of the page. It was done so that the
painting on the canvas was done very smoothly.
● Syntax:
○ document: the HTML document
○ body: body tag
○ style: We are adding style to the body tag.
○ overflow: This is the CSS property.
○ hidden: This is the value for the property.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
○ Old code:
○ Old code:
○ Updated code:
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
➔ We removed the following code, because we didn’t want to track the mouse
events.
As a result:
○ e.touches[0].clientX: Gave the x coordinate where we
touch on the canvas.
As the canvas can be placed anywhere on the screen
and by just using e.touches[0].clientX, it won’t give the
actual x coordinate on the canvas.
○ So to get the actual x coordinate on canvas with respect
to the screen, we do: e.touches[0].clientX -
canvas.offsetLeft.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
last_position_of_x_touch.
02. touchmove event: The touchmove event is the same as a mousemove event.
When we move our finger on the screen, this event should be executed.
○ Old code:
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
○ Old code:
○ Updated code:
➔ We removed the below code because we wanted to store the current x and y
coordinates of the touch and not of the mouse.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
○ The code which was inside the if condition almost remained the same.
○ We only needed to change:
○ all the current_position_of_mouse_x to
current_position_of_touch_x
○ all the current_position_of_mouse_y to
current_position_of_touch_y
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
The remaining code remained the same because the logic of drawing
remained the same. Refer to the code below:
○ beginPath(): This begins a path, or resets the current path for drawing
anything. It tells the canvas to start drawing the shape/object.
○ strokeStyle: This sets the color of the drawing.
■ We had to set the value to variable color and variable color has
black color, so the drawing will be of the black color.
○ lineWidth: This sets the width for the drawing.
■ We had set the value of the variable width_of_line to 2, so the
width of the drawing will be 2.
● We passed the current x and y coordinate to lineTo, this meant that the
creation of the line should end on these coordinates.
What’s NEXT?
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
Here are some Best References we’ve compiled together to enhance your knowledge and
understanding of the concepts we learned today in the class. This will help you become a
pro at coding and creating industry-grade tech products!
Short Videos: Watch these Short Videos to understand the application of the concepts
learned in class in real-world applications.
1. https://www.youtube.com/watch?v=JoQEBOXdfNc
2. https://www.youtube.com/watch?v=voopDNDhrIE
3. https://www.youtube.com/watch?v=ga_SLzsUdTY
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
Coding Playground: Try out these code examples to get more practice in making Websites
and Playstore ready apps.
1. https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_sha
pes
2. https://www.w3schools.com/tags/canvas_createlineargradient.asp
3. https://www.w3schools.com/tags/canvas_drawimage.asp
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
ADV-C83
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.