#lang racket/base

; A flag generator

(require
  "flag/division.rkt"
  "flag/palette.rkt"
  "../graphics/vectorial.rkt"
  "../graphics/color.rkt"
  "../base-generation/random.rkt")

(provide
  flag-generate)

; Colors used in flags

; Metals / Light colors
(define metal-colors
  (list
    (hsl-color 0 0 95) ;; Argent <=> White
    (hsl-color 50 95 55) ;; Or <=> Yellow
    (hsl-color 200 95 80) ;; Celeste <=> Light blue
    (hsl-color 10 95 80) ;; Carnation <=> Light red / skin
    (hsl-color 275 95 80) ;; Lavender <=> Light purple
    (hsl-color 130 95 80) ;; Mint <=> Light green
    (hsl-color 50 75 75) ;; Buff <=> Light brown / beige
    (hsl-color 330 95 80) ;; Pink <=> Pink
  ))

; Tinctures / Dark colors
(define tincture-colors
  (list
    (hsl-color 225 85 40) ;; Azure <=> Blue
    (hsl-color 0 85 50) ;; Gules <=> Red
    (hsl-color 350 75 30) ;; Sanguine <=> Dark red
    (hsl-color 310 45 40) ;; Purpure <=> Purple
    (hsl-color 210 15 40) ;; Cendrée <=> Grey
    (hsl-color 0 0 0) ;; Sable <=> Black
    (hsl-color 110 75 30) ;; Vert <=> Green
    (hsl-color 30 90 50) ;; Orangé <=> Orange
    (hsl-color 20 75 30) ;; Tenné <=> Brown
  ))

; The only thing needed is the width
(define (flag-generate width)
  ; 4 pairs of colors are needed
  (define palette (palette-generate 4 tincture-colors metal-colors))
  ; Decide on the dimensions - ratio width:height can be 3:2 or 2:1
  (define height (* width (random:from-vector (vector 1/2 2/3))))
  ; Return a vector image
  (vector-image
    #:width width
    #:height height
    (field-division width height palette)))
