parsimonhi / animCJK

Draw animated Japanese characters (Kanji and Kana), Korean characters (Hanja) and Chinese characters (Hanzi) in correct stroke order using svg, free open-source code.
291 stars 71 forks source link

What to change to make it work? #8

Closed krmanik closed 4 years ago

krmanik commented 4 years ago

I have implemeted HanziWriter using json data from svgsKana but for the characters with more curve seems not working as expected. So what to be change in order to make it work?

demo (1)

magychan35 commented 4 years ago

I want to creat the same please for my videos. Can you tell me how can I let kanji letters appear on the viewer screen like this?

edberteliezer commented 4 years ago

@magychan35 It uses https://github.com/chanind/hanzi-writer for the writing features and uses AnimCJK data for the kanji order and image data. You should read the documentations to apply the code yourself. If not possible you should hire a web developer to do it for you. And lucky you, there someone already combined both hanzi writer and animCJK here: https://github.com/chanind/hanzi-writer-data-jp And here https://github.com/infinyte7/Write-Kanji

edberteliezer commented 4 years ago

@infinyte7 the problem is that the お kana is has two parts that is supposed to be played together. look here: https://github.com/parsimonhi/animCJK/blob/master/svgsKana/12362.svg?short_path=bf55bb6

<path style="--d:2s;" pathLength="3333" clip-path="url(#z12362c2a)" d="M 287,100 338,140 311,847 282,898 234,906 218,900 165,836 158,764 243,671 525,536 748,543 835,691 763,820 588,917"/>
<path style="--d:2s;" pathLength="3333" clip-path="url(#z12362c2b)" d="M 287,1712 338,1672 311,965 282,914 234,906 218,900 165,836 158,764 243,671 525,536 748,543 835,691 763,820 588,917"/>

Notice the delay is both 2s. There are 2 paths that is supposed to be played at the same time, Hence, your animation is cut off.

The solution (I think) to for you to:

  1. Code a JavaScript that can identify the duplicate delay and play it together as one. I am not familiar with Hanzi Writter so I am not sure the possibility of this.
  2. Edit it with an image editor and combine the separated path into one path.
krmanik commented 4 years ago

@magychan35

I want to creat the same please for my videos. Can you tell me how can I let kanji letters appear on the viewer screen like this?

You can check my implementation. https://github.com/infinyte7/Write-Kanji

https://github.com/infinyte7/Write-Kanji/blob/master/Versions/Version%201.1/back.html

I have used HanziWriter by chanind

@edberteliezer I will implement that.

parsimonhi commented 4 years ago

Hello,

This is a difficult problem because for characters with a stroke that overlaps on itself, it is necessary to split the stroke in 2 (otherwise there is a bad rendering around the point where the stroke overlaps).

May be you can try to modify the svg (the duration and delay of the animation and the coordinates of the medians of strokes that overlaps).

Below is a sample of a modified svg for the small あ (modified parts are in bold):

<svg id="z12353" class="acjk" version="1.1" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <style> <![CDATA[ @keyframes zk { to { stroke-dashoffset:0; } } svg.acjk path[clip-path] { --t:0.8s; animation:zk var(--t) linear forwards var(--d); stroke-dasharray:3337; stroke-dashoffset:3339; stroke-width:128; stroke-linecap:round; fill:none; stroke:#000; } svg.acjk path[id] {fill:#ccc;} ]]> </style> <path id="z12353d1" d="M631 359C613 359 597 367 581 375C560 386 537 392 515 398C475 409 435 418 394 423C359 425 322 424 288 412C273 405 260 393 243 388C237 388 234 395 237 400C248 424 271 440 295 450C331 464 372 465 411 462C474 455 534 435 596 422C615 417 636 414 653 403C660 398 668 393 671 385C673 377 668 369 661 366C652 362 642 359 631 359Z"/> <path id="z12353d2" d="M371 292C366 294 358 297 360 304C363 313 374 316 381 321C389 326 399 332 399 343C400 360 395 376 394 393C381 486 372 580 380 674C383 704 387 733 396 761C404 783 415 804 431 820C441 827 457 825 463 815C471 801 469 784 462 770C455 758 443 749 436 736C426 714 423 689 421 666C414 592 422 518 436 446C442 420 447 392 461 368C467 356 474 343 471 330C468 318 456 311 446 308C422 298 396 294 371 292Z"/> <path id="z12353d3a" d="M551 535C548 534 546 538 548 540C555 554 569 566 568 583C567 599 558 613 550 626C517 680 473 726 425 767C393 793 355 814 315 823C303 826 289 825 279 817C269 806 270 791 271 777C276 742 299 712 326 690C349 671 373 654 401 642C401 632 402 621 402 611C364 624 329 644 296 667C264 690 236 720 224 759C215 789 218 824 238 849C250 864 268 874 288 875C326 878 363 862 395 843C456 806 508 756 550 698C569 671 585 643 599 613C605 601 609 588 607 574C604 563 596 554 587 547C577 540 564 534 551 535Z"/> <path id="z12353d3b" d="M585 577C556 578 526 581 497 585C462 591 427 602 394 614C394 624 394 634 394 644C435 628 478 614 522 609C554 604 587 601 619 605C655 609 692 619 719 645C738 662 748 688 749 713C750 730 749 747 744 763C724 809 684 843 641 867C605 886 568 901 529 911C520 914 511 917 504 923C502 926 501 930 502 934C543 931 584 924 624 914C676 901 728 879 767 841C792 817 813 786 817 751C823 695 792 635 741 611C693 587 638 577 585 577Z"/> <defs> <clipPath id="z12353c1"><use xlink:href="#z12353d1"/></clipPath> <clipPath id="z12353c2"><use xlink:href="#z12353d2"/></clipPath> <clipPath id="z12353c3a"><use xlink:href="#z12353d3a"/></clipPath> <clipPath id="z12353c3b"><use xlink:href="#z12353d3b"/></clipPath> </defs> <path style="--d:1s;" pathLength="3333" clip-path="url(#z12353c1)" d="M 240,394 302,434 453,432 659,380"/> <path style="--d:2s;" pathLength="3333" clip-path="url(#z12353c2)" d="M 368,299 439,337 401,500 397,695 430,772 448,811"/>

<path style="--d:3s;--t:0.3s;" pathLength="3333" clip-path="url(#z12353c3a)" d="M 559,541 591,577 471,771 263,858 248,735 397,626"/> <path style="--d:3.3s;--t:0.5s;" pathLength="3333" clip-path="url(#z12353c3b)" d="M 397,626 476,601 616,589 706,605 773,674 779,800 665,885 509,927"/>

</svg>

Edit: this doesn't work well with safari because safari doesn't support the svg "pathLength" attribute. You can correct this bug by replacing in the css for each stroke the value of stroke-dasharray by the actual pathLength of the stroke + 4, and the value of stroke-dashoffset by the actual pathLength of the stroke + 6 (and of course by removing the svg pathLength attribute). This can be done automatically using for instance javascript and a css variable.

krmanik commented 4 years ago

Thanks for detailed explanation. I have understood this implementation. I will add this to my project.

parsimonhi commented 4 years ago

Note that the safari bug concerning svg "pathLength" attribute will be corrected soon (it is already corrected in beta versions of safari). So it is probably unnecessary to try to correct this bug.