post:XTMRENDERCB   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/contrib/qr-code.xtm

Implementation

;; notice how the version (complexity) parameter in qr_create is
;; random, so you'll get a different complexity QR code each time you
;; re-evaluate
(bind-func post:XTMRENDERCB
  (let ((code (qr_create (String "http://benswift.me") (random 10:i32)))
        (size (QRcode_size code))
        (dim (/ height (convert size)))
        (i 0) (j 0)
        ;; path & color setup
        (fill_color:xtm_color* (alloc))
        (clear_color:xtm_color* (alloc)))
    (afill! clear_color 0. 0. 0. 1.)
    (lambda (frame shader m v p data)
      (let ((path (xtm_create_path))
            (fill (vgCreatePaint)))
        (xtm_vg_reset_matrices)
        (xtm_vg_clear (convert width) (convert height) clear_color)
        ;; mess with the fill/stroke parameters to change colours
        ;; loop over the QR code data, adding a rects to the path
        (dotimes (i size)
          (dotimes (j size)
            (if (QRcode_pixel code i j)
                (let ((v (+ .5 (* .5 (cos (* STWOPI 0.1 (/ (convert frame) 10.)))))))
                  (afill! fill_color
                          (% (+ v 0.1) 1.)
                          (% (+ v 0.7) 1.)
                          (% (+ v 0.2) 1.)
                          1.)
                  (xtm_paint_set_fill fill fill_color)
                  (xtm_add_rect path
                                (+ (/ (- width height) 2.)
                                   (* (convert i) dim))
                                (* (convert j) dim)
                                dim dim)))))
        ;; draw the path
        (xtm_fill_path path)
        ;; clean up
        (xtm_destroy_paint fill)
        (xtm_vg_print_error))
      void)))


Back to Index

Similar Entries

  • post:XTMRENDERCB    xtlang
  • post:XTMRENDERCB    xtlang
  • post:XTMRENDERCB    xtlang
  • postrender:XTMRENDERCB    xtlang
  • prerender:XTMRENDERCB    xtlang
  • prerender:XTMRENDERCB    xtlang
  • prerender:XTMRENDERCB    xtlang
  • prerender:XTMRENDERCB    xtlang
  • prerender:XTMRENDERCB    xtlang
  • render:XTMRENDERCB    xtlang
  • render:XTMRENDERCB    xtlang
  • render:XTMRENDERCB    xtlang
  • render:XTMRENDERCB    xtlang
  • render:XTMRENDERCB    xtlang
  • render:XTMRENDERCB    xtlang
  • trans:XTMRENDERCB    xtlang
  • trans:XTMRENDERCB    xtlang
  • vector_gfx:XTMRENDERCB    xtlang