Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

qr code example works with updated openvg lib

  • Loading branch information...
commit db2b67886bf9c67e5b81b134fec380184696adc2 1 parent f4b8cb5
Ben Swift benswift authored
Showing with 23 additions and 22 deletions.
  1. +23 −22 examples/external/qr-code.xtm
45 examples/external/qr-code.xtm
View
@@ -45,43 +45,44 @@
(bind-val height float height)
(define fullscreen #f) ;; #t for fullscreen
-;; re-evaluate this post function for new codes
;; notice how the version (complexity) parameter in qr_create is
-;; random, so you'll get a different complexity code each time you
+;; random, so you'll get a different complexity QR code each time you
;; re-evaluate
(bind-func post:XTMRENDERCB
- (let ((code (qr_create (Str "http://benswift.me") (random 20:i32)))
+ (let ((code (qr_create (Str "http://benswift.me") (random 10:i32)))
(size (QRcode_size code))
(dim (/ height (convert size)))
- (i 0)
- (j 0))
+ (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 ((fill (vgCreatePaint))
- (stroke (vgCreatePaint))
- (path (xtm_create_path)))
+ (let ((path (xtm_create_path))
+ (fill (vgCreatePaint)))
(xtm_vg_reset_matrices)
- (xtm_vg_clear 0. 0. 0. 1. (convert width) (convert height))
+ (xtm_vg_clear (convert width) (convert height) clear_color)
;; mess with the fill/stroke parameters to change colours
- (xtm_paint_setup_fill fill (random 0. .4) 1. 1. 1.)
- (xtm_paint_setup_stroke stroke
- (random .1)
- (random .3 .5)
- (random .6 .7)
- 1. 5.)
;; loop over the QR code data, adding a rects to the path
(dotimes (i size)
(dotimes (j size)
(if (QRcode_pixel code i j)
- (xtm_add_rect path
- (+ (/ (- width height) 2.)
- (* (convert i) dim))
- (* (convert j) dim)
- dim dim))))
+ (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_draw_path path)
+ (xtm_fill_path path)
;; clean up
(xtm_destroy_paint fill)
- (xtm_destroy_paint stroke)
(xtm_vg_print_error))
void)))
Please sign in to comment.
Something went wrong with that request. Please try again.