The effect

Implementation approach

Design each character to be 1 unit

Loop a region x ∈ [-30, 30) y ∈ [-15, 10)

It’s x squared plus y squared minus 1 to the third minus x cubed y cubed

If the input (x² + y² -1) ³ -x ³y³ < 0 indicates that it is in the heart function, the output should be in this case

If (x² + y² -1) ³ -x ³y³ >= 0, output space

Caveat

  1. Js implements the sleep function
const sleep = (ms) = > new Promise((resolve) = > {setTimeout((a)= > {resolve()}, ms)});
Copy the code
  1. Asynchronous code cannot be executed in the JS for loop, i.e
for (let y = - 15; y < 10; y++) {
  for (let x = - 30; x < 30; x++) {
    sleep(1000); }}Copy the code

This code cannot be implemented; sleep will execute after the for execution is complete

To solve this problem, I used recursive functions to implement the loop, thus achieving the effect of typewriting characters one by one

For details please see

Project address: github.com/bilibiliou/…

If you think it’s ok, I hope the bosses star

Thanks

Use Python to draw heart code to explain