about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2022-12-05 15:28:11 -0500
committerelioat <elioat@tilde.institute>2022-12-05 15:28:11 -0500
commit5f74b7bccea203e85a625dfa8487add596f1ae80 (patch)
tree4f1c58df4c9e6b70cc95db08e328e20dff61efe7 /src
parentbf8a3fd28083bd5b28fbd5479da2a9b5a48a9fe4 (diff)
downloaddecember-2022-5f74b7bccea203e85a625dfa8487add596f1ae80.tar.gz
images
Diffstat (limited to 'src')
-rw-r--r--src/pokedex.rkt33
-rw-r--r--src/tmp.rkt2
2 files changed, 18 insertions, 17 deletions
diff --git a/src/pokedex.rkt b/src/pokedex.rkt
index 67710f6..d8830c6 100644
--- a/src/pokedex.rkt
+++ b/src/pokedex.rkt
@@ -1,3 +1,4 @@
+
 #lang racket
 
 ;; let's try to make a pokedex in racket!
@@ -14,8 +15,9 @@
 ;; basic GET request
 (require net/url)
 (require json)
-; (require nested-hash) ;; this hasn't helped me with anything yet...
 
+; 🤔
+(require slideshow/pict racket/draw)
 
 ;; API URL
 (define *POKE-API* "https://pokeapi.co/api/v2/")
@@ -25,7 +27,7 @@
     "queries the api, returns a butt ton of info"
 	(call/input-url (string->url (~a *POKE-API* "pokemon/" id)) ; ~a, like string-append but appends *either* strings or numbers to a string
                 get-pure-port
-                (compose string->jsexpr port->string))) ;; QUESTION: could I use read-json here, instead?
+                (compose string->jsexpr port->string))) ; QUESTION: could I use read-json here, instead?
 
 (define (dex-entry id)
     "selects the info we need from the api, builds a hash table of the data that will build the entry"
@@ -38,21 +40,20 @@
         (hash-set! entry-data "types" (hash-ref poke-data 'types))
         entry-data))
 
-; (dex-entry 12) ;; QUESTION: would this all be easier to handle if it were a vector or list instead of a hash table?
-
-;; TOMORROW I'll start to figure out how to present this data
-
 (define (inspector h)
-    "display the contents of a hash table for human eyeballs and let the hash table fall back out"
-    (hash-map h
-        (lambda (k v)
-          (if (hash? v) (~a "value " v " was a hash table!\n") ;; test to see if a value is a hash table
-            (display (~a "key: " k ", value: " v "\n")))) ; QUESTION: is there a functional difference between hash-map and hash-for-each here?
-    h))
+  "display the contents of a hash table for human eyeballs and let the hash table fall back out"
+  (hash-map h
+            (lambda (k v)
+              (if (list? v) (map ; consider making this if a cond and testing for lists/hash tables to recursively dive into nested data
+                             (lambda (x) (inspector x)) v)
+                  (display (~a "  key: " k "\nvalue: " v "\n=====\n")))))
+  h)
 
-; (hash-ref (dex-entry 5) "types") ;; struggling to figure out how to access the nested hash tables stats and types...
+(inspector (dex-entry 11))
+(inspector (dex-entry "bulbasaur"))
 
-;; the other option not yet considered is to make individual API calls for each bit of data, rather than 1 call and plucking out the data I want.
-;; this may lead to an easier data shape, but means a lot more network traffic.
+(define img (hash-ref (dex-entry 11) "sprite"))
 
-(inspector (dex-entry 11))
+(define display-image (bitmap (make-object bitmap% img)))
+
+(frame (scale display-image 0.3))
diff --git a/src/tmp.rkt b/src/tmp.rkt
index 08cd3fd..ffb0edb 100644
--- a/src/tmp.rkt
+++ b/src/tmp.rkt
@@ -61,7 +61,7 @@
   (hash-map h
             (lambda (k v)
               (if (list? v) (map
-                             (lambda (x) (inspector2 x)) v)                
+                             (lambda (x) (inspector2 x)) v)               
                   (display (~a "  key: " k "\nvalue: " v "\n=====\n")))))
   h)