about summary refs log tree commit diff stats
path: root/src/pokedex
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2022-12-21 21:21:19 -0500
committerelioat <elioat@tilde.institute>2022-12-21 21:21:19 -0500
commit7a62b573087cde23285195d154c8bb73a760b048 (patch)
treec992d33cdda558136307562c372aba96eb2d2146 /src/pokedex
parent580ca9123411324abdc6e3fc260688172fec671f (diff)
downloaddecember-2022-7a62b573087cde23285195d154c8bb73a760b048.tar.gz
*
Diffstat (limited to 'src/pokedex')
-rw-r--r--src/pokedex/imgs/blank.txt1
-rw-r--r--src/pokedex/pokedex.rkt42
2 files changed, 33 insertions, 10 deletions
diff --git a/src/pokedex/imgs/blank.txt b/src/pokedex/imgs/blank.txt
new file mode 100644
index 0000000..87058af
--- /dev/null
+++ b/src/pokedex/imgs/blank.txt
@@ -0,0 +1 @@
+file to force this directory to show up in git
diff --git a/src/pokedex/pokedex.rkt b/src/pokedex/pokedex.rkt
index 3aebea1..5af1710 100644
--- a/src/pokedex/pokedex.rkt
+++ b/src/pokedex/pokedex.rkt
@@ -1,4 +1,3 @@
-
 #lang racket
 
 ;; let's try to make a pokedex in racket!
@@ -13,11 +12,12 @@
 
 
 ;; basic GET request
-(require net/url)
-(require json)
+(require net/url
+         net/url-connect
+         json
+         slideshow/pict
+         racket/draw)
 
-; 🤔
-(require slideshow/pict racket/draw)
 
 ;; API URL
 (define *POKE-API* "https://pokeapi.co/api/v2/")
@@ -52,8 +52,30 @@
 (inspector (dex-entry 11))
 (inspector (dex-entry "bulbasaur"))
 
-(define img (hash-ref (dex-entry 11) "sprite"))
-
-(define display-image (bitmap (make-object bitmap% img)))
-
-(frame (scale display-image 0.3)) ; this doesn't actually seem to work with URLs/PNGs
+(define (get-image id sprite-file-name)
+  (define img (hash-ref (dex-entry id) "sprite"))
+  (define img-url
+    (string->url img))
+  (define the-data
+    (parameterize ([current-https-protocol 'secure])
+      (port->bytes (get-pure-port img-url))))
+  (define out (open-output-file sprite-file-name))
+  (write-bytes the-data out)
+  (close-output-port out)
+  (display-image sprite-file-name))
+
+(define (display-image image)
+  (define display-image (bitmap (make-object bitmap% image)))
+  (frame (scale display-image 1)))
+
+(define (see-pokemon id)
+  (define sprite-file-name
+    (~a "imgs/" id ".png"))
+  (if (file-exists? sprite-file-name)
+      (display-image sprite-file-name)
+      (get-image id sprite-file-name)))
+
+(see-pokemon "bulbasaur")
+(see-pokemon "butterfree")
+(see-pokemon "pikachu")
+(see-pokemon 124)
\ No newline at end of file