j4 gif
(22.88 KB, 300x200)
j8 gif
(46.96 KB, 300x200)
Making gifs with Racket
#lang racket
(require 2htdp/image)
(require lang/posn)
;; Convert degrees to radians
(define (radians degree)
(* degree (/ pi 180)))
;; https://www.mathsisfun.com/polar-cartesian-coordinates.html
(define (coord length degree)
(list (* length (cos (radians degree)))
(* length (sin (radians degree)))))
;; algorithmically generate
(define (rays [count 4] [length 100])
(let* ([width (/ 360 (* 2 count))]
[initial (- 0 (/ width 2))])
(for/fold ([posns '()])
([i (range count)])
(append posns (list (list 0 0)
(coord length (- (* (* 2 i) width) (/ width 2)))
(coord length (+ (* (* 2 i) width) (/ width 2))))))))
;; https://www.crwflags.com/fotw/flags/jp%5E.html
(define (japan-naval #:width [width 300]
#:turn [turn 0]
#:fg [fg (make-color 188 0 45)]
#:bg [bg "white"])
(let* ([height (/ width 3/2)]
[radius (/ height 4)]
[offset (- radius (/ radius 3))]
[uncropped (overlay/offset
(overlay
(circle radius "solid" fg)
(rotate turn
(polygon
(map (lambda (xy) (apply make-posn xy))
(rays 16 width)) "solid" fg)))
;; move rectangle $offset pixels to the right
offset 0
(rectangle width height "solid" bg))]
[x (- (/ (image-width uncropped) 2) (/ width 2) (- offset))]
[y (- (/ (image-height uncropped) 2) (/ height 2))]
[cropped (crop x y width height uncropped)])
cropped))
To generate frames:
(require racket/format)
(for ([i (range 8)]) (save-image (japan-naval #:turn (* 45/16 i)) (string-join (list "j" (~a i #:align 'right #:width 2 #:pad-string "0") ".png") "")))
I then used gimp to load each image into a layer and export an animated gif.