Monday, July 1, 2013

When my Racket skills come in handy...

Note: fixed the code.

Today I made a converter (in Racket) that takes an image and returns a string to type into SourceCoder or something. (This uses the HtDP Advanced Student language, by the way.)

(require racket)
(require picturing-programs)

; (current-command-line-arguments) gets all the command-line arguments as a vector

; convert-to-format: image char char list(string) number number number number -> string
; Given an image, a char for walls, and a char
; for blanks, returns a string containing the
; data in Elv4 map format. The fourth argument
; is a list of metadata, and the last four
; define the spawnpoint.

(define (convert-to-format i w b m rx ry x y)
  (letrec ([wir (/ (image-width i) 16)]
           [hir (/ (image-height i) 8)]
           [rl (build-list (* wir hir) (lambda (x) (quotient x wir)))]
           [cl (build-list (* wir hir) (lambda (x) (remainder x wir)))])
    (if (not (and (integer? wir)
                  (integer? hir))) (error 'convert-to-format "Image width must be divisible by 16 and height must be divisible by 8")
                                   (format "{~a,~a\n{~a,~a,~a,~a\n~a" wir hir rx ry x y
                                           (foldr (lambda (x y) (string-append x "\n" y)) ""
                                                  (map (lambda (x r c) (string-append (read-sector i r c w b) x))
                                                       m rl cl))))))

(define (read-sector i r c w b)
  (foldr (lambda (x y) (string-append x y))
         ""
         (foldr (lambda (x y) (append x y)) empty (build-list 8 (lambda (y)
                                                                  (build-list 16 (lambda (x) (if (color=? 'black (get-pixel-color (+ x (* 16 c)) (+ y (* 8 r)) i)) (string w) (string b)))))))))



(display (convert-to-format . #\X #\space (make-list 36 "0000102DEFAULT  ") 0 0 5 8))

If you want to have a program name containing a theta in the source code, then use "[", the character after "Z". My mapmaking times have become way easier.

Friday, June 28, 2013

My hard labor has been nullified...

So I wrote the hex drawer X and its 16-bit counterpart Y, but my work on assembly has been to no use. A user gave me a smaller Basic version that works reasonably fast, and I can write a program that does about the same thing as X or Y.
Hello! this is blue_bear_94, and I am announcing another 84+ RPG!
Of course, Elvyna 4 will be so big that it won't fit in the RAM, so the game won't be entirely in TI-Basic. I plan to use a utility that allows copying from the archive, as well as routines for drawing hexadecimal numbers.