Join Joe Marini for an in-depth discussion in this video Using scaling, part of Learning HTML Canvas.
- [Instructor] The next transform we're going…to learn about is The Scale Transform which causes…drawing operations to be multiplied…by a scale factor in the x and y directions.…So the way that the scale transform works is pretty simple.…So suppose I use the fillRect function…to create a rectangle that is 20 pixels wide…and 10 pixels high.…If I call the canvas's scale function,…with a factor of two for each axis,…and then call the same fillRect function again…with the same values.…The result would be a rectangle that's 40 pixels wide…and 20 pixels high.…
So let's try this out and make sure…that the theory is correct.…So once again here in the editor, I've got scale_start open.…And you can see I've already got some code…that draws a rectangle that's 100 by 50 pixels.…So I'm going to add the code to scale the next rectangle…and then draw the same size rect again.…So I'll use the scale function to do that,…so I'll save off the current drawing state.…And we learned about this earlier in the course.…And I'll call ctx.scale.…
- Canvas examples
- Drawing shapes, arcs, paths, and curves
- Drawing text
- Drawing shadows, patterns, and gradients
- Using clipping paths
- Displaying images and video
- Transforming objects with scaling and rotation
- Manipulating raw pixels
- Applying transitions
- Creating animations
Skill Level Intermediate
1. Overview of Canvas
2. Basic Canvas Drawing Techniques
3. Complex Canvas Drawing
4. Advanced Drawing APIs
5. Practical Examples
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.