Here are the links: Codepen , Mdn .
Let me know if I did it correctly.
Thank you for your help !
Looks very good to me. I did mine with 1 more line than yours;
function drawRect() {
ctx.fillStyle = color;
ctx.rect(x,y,width,height);
ctx.fill();
}
drawRect();
Now I have learnt something new with the function fillRect which is a combination of the functions rect and fill. Good to always refactor code. Keep up the great work.
I’m glad I actually helped learned something.
Did you learn the canvas API or did you do it learn just the necessary to get past the exercise like me?
I feel like it would be easier to just use a program that generate canvas code. Canvas seems to be something mathematically too simple for a program with a user interface to not be able to generate it at lightning speed.
Canvas looks interesting to me. The whole idea of the browser and what you can do with it is amazing. I started learning about front end 6 months ago and it has made me want to learn even more. WebGL: 2D and 3D graphics for the web is on my radar of things to learn but I think it makes more sense to complete HTML, CSS and Javascript and the frameworks first.
I like maths and the ability to see maths on the browser is exciting to me. I like learning fundamentals as it allows you to break apart other applications and rebuild new code.
But, isn’t it easier to just do 2d graphics with a svg software?
I think canvas is interesting but canvas language is very fastidious. I just don’t understand what is the advantage of writing canvas code when it could be easily automatically generated by the computer without too much hassle using software like Inkscape.
It seems like 2d Canvas is only for simple graphics. Webgl is something else. Are there anything you can do with canvas 2d that isn’t possible using 2d software?
Can you show me some real life example of the power of 2d canvas?
PS: I mean computer software were meant to make life easier if a software is as powerful as a language and takes way less time to get the job done, I’d choose the software.
I dont know. I am just learning whats here on MDN. Maybe someone else more knowledgeable will be able to advise you on that.