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    /digego/extempore/tree/v0.8.9/examples/contrib/slideshow.xtm
  • post:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/kinect_vg.xtm
  • post:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo_multi.xtm
  • postrender:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender5.xtm
  • prerender:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender3.xtm
  • prerender:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender2.xtm
  • prerender:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender5.xtm
  • prerender:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender4.xtm
  • prerender:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender6.xtm
  • render:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender3.xtm
  • render:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender2.xtm
  • render:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender1.xtm
  • render:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender5.xtm
  • render:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender4.xtm
  • render:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender6.xtm
  • trans:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/fluids_2d.xtm
  • trans:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender4.xtm
  • vector_gfx:XTMRENDERCB    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender5.xtm