Created
April 14, 2022 13:09
-
-
Save haruo-wakakusa/d0001086f166acd209174124e94e3a83 to your computer and use it in GitHub Desktop.
グリッド模写用のグリッドを表示するSVGファイルを生成するRacketスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require racket/format) | |
(require racket/list) | |
; grid.rkt | |
(define x-split 4) | |
(define y-split 4) | |
(define margin 50) | |
(define extension 50) | |
(define x-grid-size 2000) | |
(define y-grid-size 2000) | |
(define line-width 2) | |
(define line-color "red") | |
; | |
; svg writer | |
; | |
(printf | |
"<svg xmlns=~s viewBox=~s>~n" | |
"http://www.w3.org/2000/svg" | |
(format "0 0 ~a ~a" | |
(+ x-grid-size (* 2 (+ margin extension))) | |
(+ y-grid-size (* 2 (+ margin extension))))) | |
(newline) | |
(define (near x) (~r x #:precision 3)) | |
(for ((i (range (add1 x-split)))) | |
(define x (near (+ margin extension (/ (* i x-grid-size) x-split)))) | |
(printf | |
" <line x1=~s y1=~s x2=~s y2=~s stroke=~s stroke-width=~s />~n" | |
x | |
(near margin) | |
x | |
(near (+ margin extension y-grid-size extension)) | |
line-color | |
(near line-width))) | |
(newline) | |
(for ((i (range (add1 y-split)))) | |
(define y (near (+ margin extension (/ (* i y-grid-size) y-split)))) | |
(printf | |
" <line x1=~s y1=~s x2=~s y2=~s stroke=~s stroke-width=~s />~n" | |
(near margin) | |
y | |
(near (+ margin extension x-grid-size extension)) | |
y | |
line-color | |
(near line-width))) | |
(newline) | |
(printf "</svg>~n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment