After learning the core.async library in Clojure, I was craving for a real-world example. Now I found one from purelyfunctional.tv.
The original code can be found here.
The Toy Car Factory Let’s describe how a worker builds a toy car.
Take a car body from the part box. Take a wheel from the part box. Take another wheel from the part box. Attach the first wheel to the body. Attach the second wheel to the body.
In this post, we will be focusing on the Paint.
Color The color in Paint has 3 parts: basic color, color filter and xfermode.
Basic color There are 2 ways to set color in Paint: use setColor() and use Shader.
Set color directly Two methods can be used:
paint.setColor(Color.parseColor("#B90E83"); paint.setARGB(100, 255, 0, 0); There is no difference, pick whichever you like.
Set color using Shader There are different types of Shader, let’s look them one by one.
If 101 is like a crash course, then this 102 will provide much more detail.
In this 1st part, we focus on only one thing: how to draw things.
Draw Color Draw the entire view with one color.
public class DrawColorView extends View { … @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.YELLOW); } } Draw Circle Draw a circle on the view.
Pay attention that all drawXXX() functions use pixel as unit.
There are 4 ways to specify line height in CSS:
/* The number way*/ line-height: 1.5; /* The em way*/ line-height: 1.5em; /* The percentage way*/ line-height: 150%; /* The pixel way*/ line-height: 24px; In simple settings, they are pretty much interchangable. For example:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"/> <title>Document</title> <style> p { font-size: 16px; line-height: 1.5; } </style> </head> <body> <p>I'm a paragraph.</p> </body> </html> Here p can use all 4 ways and there would be no difference.
For JavaScript beginners (I envy all of you because your brains are not damaged by this yet), () can be a huge confusion.
Example 1 const createPerson = name => {firstname: name}; console.log(createPerson("Guowei")); Of course it logs undefined. Let’s ask JavaScript what was it thinking when it executed the code.
Me: Hi, JavaScript.
JavaScript: Hi!
Me: What the heck has happened? Where is my returned object?
JavaScript: Wait. What return? What object?