Skip to content
Snippets Groups Projects
Commit 3db8586c authored by Jessica Tallon's avatar Jessica Tallon
Browse files

Make hashvatar scalable and fix image path

parent 2538c520
No related branches found
No related tags found
No related merge requests found
#lang racket
(require racket/draw
racket/runtime-path)
racket/runtime-path
(prefix-in htdp: 2htdp/image))
(provide make-avatar)
(provide make-hashvatar)
;; For the "amount", it is the amount of images we have for that body part, this
;; goes from 0 -> n so the total amount is actually n+1. The "byte-ref" is which
......@@ -15,11 +16,7 @@
(define hat (body-part 10 3 "hat"))
(define mouth (body-part 15 4 "mouth"))
(define image-path
(build-path
(find-system-path 'orig-dir)
".."
"images/sketchy/"))
(define-runtime-path image-path "../images/sketchy/")
(define (hash-token token salt)
(sha1-bytes (string->bytes/utf-8 (string-append token salt))))
......@@ -41,7 +38,7 @@
(define item-bitmap (read-bitmap bitmap-path))
(send canvas draw-bitmap item-bitmap 0 0))
(define (make-avatar token salt)
(define (make-hashvatar token salt width-height)
(define hashed-token (hash-token token salt))
;; Pick the items for this hash
......@@ -51,9 +48,15 @@
(define avatar-hat (pick hat hashed-token))
(define avatar-mouth (pick mouth hashed-token))
;; Calculate scale factor relative to 500x500
(when (> width-height 500)
(error "Width or height can't be more than 500x500"))
(define scale-factor (/ width-height 500))
;; Now we need to build the avatar
(define avatar (make-bitmap 500 500))
(define avatar (make-bitmap width-height width-height))
(define avatar-dc (new bitmap-dc% [bitmap avatar]))
(send avatar-dc set-scale scale-factor scale-factor)
(draw-bitmap body avatar-body avatar-dc)
(draw-bitmap bottom avatar-bottom avatar-dc)
(draw-bitmap eye avatar-eye avatar-dc)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment