dragon.cs 930 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. %!CairoScript
  2. /pot { % n -- n
  3. 1 sub
  4. dup -1 bitshift or
  5. dup -2 bitshift or
  6. dup -4 bitshift or
  7. dup -8 bitshift or
  8. dup -16 bitshift or
  9. 1 add
  10. } bind def
  11. /direction { % i -- bool
  12. dup 2 lt { pop true } {
  13. dup 1 add dup pot dup 3 -1 roll eq { pop pop true } {
  14. 2 div 1 sub 2 mul exch sub direction not
  15. } ifelse
  16. } ifelse
  17. } bind def
  18. /path { % cr dx dy -- cr
  19. 0 1 2048 {
  20. 4 1 roll 3 copy L pop 4 -1 roll direction {
  21. exch neg
  22. } {
  23. neg exch
  24. } ifelse
  25. } for
  26. pop pop
  27. } bind def
  28. dict
  29. /width 512 set
  30. /height 512 set
  31. surface context
  32. 1 g set-source paint
  33. //LINE_CAP_ROUND set-line-cap
  34. //LINE_JOIN_ROUND set-line-join
  35. 4 set-line-width
  36. 256 256 m 12 0 path 0 0 0 rgb set-source stroke
  37. 256 256 m -12 0 path 1 0 0 rgb set-source stroke
  38. 256 256 m 0 12 path 0 1 0 rgb set-source stroke
  39. 256 256 m 0 -12 path 0 0 1 rgb set-source stroke
  40. /target get (out.png) write-to-png pop
  41. pop