The PayPal Logo Challenge
Recently, I came across an interesting blog post in PayPal Engineering blog site. It was an article about how the author curated a solution to generate PayPal’s logo using just CSS3. One thing that kept me thinking was that the author at the end of the post, challenges and wishes to see other CSS based implementations of the PayPal logo. I, being a JavaScript enthusiast, decided to take up the challenge and implement the same using JavaScript!
How was it done?
The evolution of HTML5 gave us the super powerful HTML element Canvas and a set of JavaScript APIs to draw and manipulate graphic contexts. This proved the web could do many powerful things than just displaying a bunch of text and images. I am going to use the 2D Context Rendering APIs to draw the PayPal logo onto a Canvas.
Step 1: Define the Canvas element into which the logo will be drawn.
|
|
Step 2: In JavaScript, start grabbing a 2D render context reference to the same canvas element.
|
|
Step 3: Define some values to characterize the appearance of ‘P’. I break down the letter ‘P’ into two parts and call the top part as ‘Head’ and the bottom part as ‘Leg’.
|
|
Step 4: Now, I will start to draw the letter ‘P’ on the canvas context.
|
|
sketch explaining the drawing
Step 5: Color the drawn surface.
|
|
colored sketch
Step 6: Next, repeat the same code above and draw another ‘P’ with a little offset so that it overlays on the existing drawing and fill it with a darker shade of blue.
Step7: Finally, skew the canvas horizontally so that the logo appears a bit tilted.
|
|
The finished canvas drawing looks like the below image
Conclusion
I accomplished the challenge that I started within myself and published it as a reusable library here: https://github.com/samsel/paypal-logo-canvas. A working example of the library can be found here: http://jsfiddle.net/samsel/unqrods8/3/.
While executing this challenge, I was really overwhelmed by the power of the canvas element plus its associated JavaScript API. I wish we embrace the web more and push it to its limits!
Comments