Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
H
hashvatar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
spritely
hashvatar
Commits
3db8586c
Commit
3db8586c
authored
3 years ago
by
Jessica Tallon
Browse files
Options
Downloads
Patches
Plain Diff
Make hashvatar scalable and fix image path
parent
2538c520
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hashvatar/avatar.rkt
+12
-9
12 additions, 9 deletions
hashvatar/avatar.rkt
with
12 additions
and
9 deletions
hashvatar/avatar.rkt
+
12
−
9
View file @
3db8586c
#
lang
racket
(
require
racket/draw
racket/runtime-path
)
racket/runtime-path
(
prefix-in
htdp:
2
htdp/image
))
(
provide
make-
a
vatar
)
(
provide
make-
hash
vatar
)
;; 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-
a
vatar
token
salt
)
(
define
(
make-
hash
vatar
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment