Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (require 2htdp/image)
- (require 2htdp/universe)
- ((lambda (x)
- (local ((define (I-th s i)
- (local ((define (for_I-th s i k)
- (cond
- ((= k i) (car s))
- (else (for_I-th (cdr s) i (add1 k))))))
- (cond
- ((and (positive? i) (integer? i) (<= i (length s))) (for_I-th s i 1))
- (else '()))))
- (define (eqc? a b)
- (if (and (= (color-red a) (color-red b)) (= (color-green a) (color-green b)) (= (color-blue a) (color-blue b)) (= (color-alpha a) (color-alpha b)))
- #t
- #f))
- (define-struct coord (x y))
- (define (Exists? f)
- (if (file-exists? f)
- (if (or (> (image-width (bitmap/file f)) 1300) (> (image-height (bitmap/file f)) 650))
- (empty-scene 1300 650)
- (bitmap/file f))
- (empty-scene 1300 675)))
- (define (-> x)
- (overlay/align "left" "top"
- (beside
- (overlay
- (text "Открыть" 16 "black")
- (rectangle 100 25 "outline" "black"))
- (overlay
- (text "Сохранить" 16 "black")
- (rectangle 100 25 "outline" "black"))
- (overlay
- (beside (overlay
- (text "-" 16 "black")
- (square 25 "outline" "black"))
- (overlay
- (text (number->string (car (cdr (cdr (cdr x))))) 16 "black")
- (rectangle 50 25 "outline" "black"))
- (overlay
- (text "+" 16 "black")
- (square 25 "outline" "black")))
- (rectangle 100 25 "outline" "black"))
- (overlay
- (text "Сменить стиль" 12 "black")
- (rectangle 100 25 "outline" "black"))
- (overlay
- (beside (rectangle 10 25 "solid" "red")
- (rectangle 10 25 "solid" "orange")
- (rectangle 10 25 "solid" "yellow")
- (rectangle 10 25 "solid" "darkseagreen")
- (rectangle 10 25 "solid" "lightblue")
- (rectangle 10 25 "solid" "blue")
- (rectangle 10 25 "solid" "purple")
- (rectangle 10 25 "solid" "white")
- (rectangle 10 25 "solid" "pink")
- (rectangle 10 25 "solid" "black"))
- (rectangle 100 25 "outline" "black"))
- (overlay
- (square 25 "outline" "black")
- (bitmap/file "curve.jpg"))
- (overlay
- (square 25 "outline" "black")
- (bitmap/file "line.jpg"))
- (overlay
- (square 25 "outline" "black")
- (bitmap/file "rec.png"))
- (overlay
- (square 25 "outline" "black")
- (bitmap/file "fill.png"))
- (rectangle 699 25 "outline" "black"))
- (car x)))
- (define (D x f)
- (cond
- ((= (length x) 4) (cons (f (car x)) (cdr x)))
- (else (cons (car x) (D (cdr x) f)))))
- (define (Figure x)
- (if (zero? (car (cdr (reverse x))))
- (circle (* (car (cdr (cdr (cdr x)))) 0.5) "solid" (car (cdr (cdr (cdr (cdr x))))))
- (square (car (cdr (cdr (cdr x)))) "solid" (car (cdr (cdr (cdr (cdr x))))))))
- (define (->Figure x)
- (if (zero? x)
- 1
- 0))
- (define (Colour n)
- (cond
- ((= n 0) "red")
- ((= n 1) "orange")
- ((= n 2) "yellow")
- ((= n 3) "darkseagreen")
- ((= n 4) "lightblue")
- ((= n 5) "blue")
- ((= n 6) "purple")
- ((= n 7) "white")
- ((= n 8) "pink")
- (else "black")))
- (define (->Colour x n)
- (cond
- ((string? (car x)) (cons (Colour n) (cdr x)))
- (else (cons (car x) (->Colour (cdr x) n)))))
- (define (?Form x)
- (if (zero? x)
- "round"
- "projecting"))
- (define (??Form x)
- (if (zero? x)
- "round"
- "bevel"))
- (define ($Dr x)
- (if (zero? (car (reverse x)))
- (overlay
- (text "Заставка" 16 "black")
- (empty-scene 1300 675))
- (-> x)))
- (define (c->st c)
- (car (image->color-list (square 1 "solid" c))))
- (define (OldCCoord x old_c s n)
- (cond
- ((empty? x) s)
- ((eqc? (car x) old_c) (OldCCoord (cdr x) old_c (cons n s) (add1 n)))
- (else (OldCCoord (cdr x) old_c s (add1 n)))))
- (define (FoundR s n)
- (cond
- ((<= (* n 1300) s (* (add1 n) 1300)) (make-coord (- s (* n 1300)) (add1 n)))
- (else (FoundR s (add1 n)))))
- (define (ReallyOCC s)
- (cond
- ((empty? s) '())
- (else (cons (FoundR (car s) 0) (ReallyOCC (cdr s))))))
- (define (h?* s for_h)
- (cond
- ((empty? for_h) #f)
- ((h? s (car for_h)) #t)
- (else (h?* s (cdr for_h)))))
- (define (h? s c)
- (cond
- ((empty? s) #f)
- ((and (<= 0 (abs (- (coord-x (car s)) (coord-x c))) 1) (<= 0 (abs (- (coord-y (car s)) (coord-y c))) 1)) #t)
- (else (h? (cdr s) c))))
- (define (d* s for_h)
- (cond
- ((empty? s) '())
- ((and (<= 0 (abs (- (coord-x (car s)) (coord-x for_h))) 1) (<= 0 (abs (- (coord-y (car s)) (coord-y for_h))) 1)) (d* (cdr s) for_h))
- (else (cons (car s) (d* (cdr s) for_h)))))
- (define (g new_s s for_h)
- (cond
- ((empty? s) new_s)
- ((and (<= 0 (abs (- (coord-x (car s)) (coord-x for_h))) 1) (<= 0 (abs (- (coord-y (car s)) (coord-y for_h))) 1)) (g (cons (car s) new_s) (cdr s) for_h))
- (else (g new_s (cdr s) for_h))))
- (define (Select** s for_h for_h* new_s)
- (cond
- ((empty? for_h) (Select* s for_h* new_s))
- (else (Select** (d* s (car for_h)) (cdr for_h) (g for_h* s (car for_h)) (g new_s s (car for_h))))))
- (define (Select* s for_h new_s)
- (cond
- ((h?* s for_h) (Select** s for_h '() new_s))
- (else new_s)))
- (define (eqcc? s1 s2)
- (if (and (= (coord-x s1) (coord-x s2)) (= (coord-y s1) (coord-y s2)))
- #t
- #f))
- (define (d s el)
- (cond
- ((empty? s) '())
- ((eqcc? (car s) el) (d (cdr s) el))
- (else (cons (car s) (d (cdr s) el)))))
- (define (Del s)
- (cond
- ((empty? s) '())
- (else (cons (car s) (Del (d (cdr s) (car s)))))))
- (define (~>* s)
- (cond
- ((empty? s) '())
- (else (cons (+ (* (sub1 (coord-y (car s))) 1300) (coord-x (car s))) (~>* (cdr s))))))
- (define (Sorted? s)
- (cond
- ((empty? s) #t)
- ((empty? (cdr s)) #t)
- ((<= (car s) (car (cdr s))) (Sorted? (cdr s)))
- (else #f)))
- (define (Cut s i)
- (local ((define (SubCut s i k)
- (cond
- ((= k i) '())
- (else (cons (car s) (SubCut (cdr s) i (add1 k)))))))
- (SubCut s i 0)))
- (define (UnCut s i)
- (local ((define (SubUnCut s i k)
- (cond
- ((= k i) s)
- (else (SubUnCut (cdr s) i (add1 k))))))
- (SubUnCut s i 0)))
- (define (Sort_6 s)
- (local ((define (ForOdd s)
- (add1 (* (sub1 (length s)) 0.5)))
- (define (ForEven s)
- (* (length s) 0.5))
- (define (\ s)
- (if (odd? (length s))
- (ForOdd s)
- (ForEven s)))
- (define (<<< s1 x)
- (cond
- ((empty? s1) '())
- ((>= (car s1) x) (<<< (cdr s1) x))
- (else (cons (car s1) (<<< (cdr s1) x)))))
- (define (>>>= s2 x)
- (cond
- ((empty? s2) '())
- ((< (car s2) x) (>>>= (cdr s2) x))
- (else (cons (car s2) (>>>= (cdr s2) x)))))
- (define (<< s1 x s2)
- (append (<<< s1 x) (<<< s2 x)))
- (define (>>= s1 x s2)
- (append (>>>= s2 x) (>>>= s1 x)))
- (define (** s1 x s2)
- (append (Sort_6 (<< s1 x s2)) (list x) (Sort_6 (>>= s1 x s2)))))
- (cond
- ((or (empty? s) (= (length s) 1)) s)
- (else (** (Cut s (sub1 (\ s))) (I-th s (\ s)) (reverse (UnCut s (\ s))))))))
- (define (~> x i c s)
- (cond
- ((empty? x) '())
- ((empty? s) x)
- ((= i (car s)) (cons c (~> (cdr x) (add1 i) c (cdr s))))
- (else (cons (car x) (~> (cdr x) (add1 i) c s)))))
- (define (f x c Mx My old_c)
- (color-list->bitmap (~> x 1 c (Sort_6 (~>* (Del (Select* (ReallyOCC (OldCCoord x old_c '() 1)) `(,(make-coord Mx My)) `(,(make-coord Mx My))))))) 1300 675))
- (define (** i)
- (local ((define (*** i n x)
- (cond
- ((= n x) (color-list->bitmap i 1300 650))
- (else (*** (cdr i) (add1 n) x)))))
- (*** i 0 (* 1300 25))))
- (define ($M x Mx My B)
- (cond
- ((and (zero? (car (reverse x))) (mouse=? B "button-down")) (reverse (cons 1 (cdr (reverse x)))))
- ((zero? (car (reverse x))) x)
- ((and (<= 0 Mx 100) (<= 0 My 25) (mouse=? B "button-down")) (cons (above (rectangle 1300 25 "solid" "white") (Exists? "img.bmp")) (cons '() (cdr (cdr x)))))
- ((and (<= 100 Mx 200) (<= 0 My 25) (mouse=? B "button-down")) ((lambda (x y) x) x (save-image (** (image->color-list (car x))) "img.bmp")))
- ((and (> (car (cdr (cdr (cdr x)))) 1) (<= 200 Mx 225) (<= 0 My 25) (mouse=? B "button-down")) (D x sub1))
- ((and (< (car (cdr (cdr (cdr x)))) 30) (<= 275 Mx 300) (<= 0 My 25) (mouse=? B "button-down")) (D x add1))
- ((and (<= 300 Mx 400) (<= 0 My 25) (mouse=? B "button-down")) (reverse (cons (car (reverse x)) (cons (->Figure (car (cdr (reverse x)))) (cdr (cdr (reverse x)))))))
- ((and (<= 400 Mx 500) (<= 0 My 25) (mouse=? B "button-down")) (->Colour x (string->number (substring (number->string Mx) 1 2))))
- ((and (<= 500 Mx 525) (<= 0 My 25) (mouse=? B "button-down")) (cons (car x) (cons (car (cdr x)) (cons 0 (cdr (cdr (cdr x)))))))
- ((and (<= 525 Mx 550) (<= 0 My 25) (mouse=? B "button-down")) (cons (car x) (cons (car (cdr x)) (cons 1 (cdr (cdr (cdr x)))))))
- ((and (<= 550 Mx 575) (<= 0 My 25) (mouse=? B "button-down")) (cons (car x) (cons (car (cdr x)) (cons 2 (cdr (cdr (cdr x)))))))
- ((and (<= 575 Mx 600) (<= 0 My 25) (mouse=? B "button-down")) (cons (car x) (cons (car (cdr x)) (cons 3 (cdr (cdr (cdr x)))))))
- ((and (zero? (car (cdr (cdr x)))) (>= My (+ 25 (* (car (cdr (cdr (cdr x)))) 0.5))) (mouse=? B "drag")) (cons (place-image (Figure x) Mx My (car x)) (cons (cons (make-coord Mx My) (car (cdr x))) (cdr (cdr x)))))
- ((and (= (car (cdr (cdr x))) 1) (>= My (+ 25 (* (car (cdr (cdr (cdr x)))) 0.5))) (mouse=? B "button-down") (false? (empty? (car (cdr x)))) (list? (car (car (cdr x)))) (= (length (car (car (cdr x)))) 1))
- (cons (scene+line (car x)
- (coord-x (car (car (car (cdr x))))) (coord-y (car (car (car (cdr x))))) Mx My
- (make-pen (car (cdr (cdr (reverse x)))) (car (cdr (cdr (cdr x)))) "solid" (?Form (car (cdr (reverse x)))) (??Form (car (cdr (reverse x))))))
- (cons (cons (cons (make-coord Mx My) (car (car (cdr x)))) (cdr (car (cdr x)))) (cdr (cdr x)))))
- ((and (= (car (cdr (cdr x))) 1) (>= My (+ 25 (* (car (cdr (cdr (cdr x)))) 0.5))) (mouse=? B "button-down")) (cons (car x) (cons (cons `(,(make-coord Mx My)) (car (cdr x))) (cdr (cdr x)))))
- ((and (= (car (cdr (cdr x))) 2) (>= My (+ 25 (* (car (cdr (cdr (cdr x)))) 0.5))) (mouse=? B "button-down") (false? (empty? (car (cdr x)))) (list? (car (car (cdr x)))) (= (length (car (car (cdr x)))) 1))
- (cons (scene+line (scene+line (scene+line (scene+line (car x)
- (coord-x (car (car (car (cdr x))))) My Mx My
- (make-pen (car (cdr (cdr (reverse x)))) (car (cdr (cdr (cdr x)))) "solid" (?Form (car (cdr (reverse x)))) (??Form (car (cdr (reverse x))))))
- Mx (coord-y (car (car (car (cdr x))))) Mx My
- (make-pen (car (cdr (cdr (reverse x)))) (car (cdr (cdr (cdr x)))) "solid" (?Form (car (cdr (reverse x)))) (??Form (car (cdr (reverse x))))))
- (coord-x (car (car (car (cdr x))))) (coord-y (car (car (car (cdr x))))) Mx (coord-y (car (car (car (cdr x)))))
- (make-pen (car (cdr (cdr (reverse x)))) (car (cdr (cdr (cdr x)))) "solid" (?Form (car (cdr (reverse x)))) (??Form (car (cdr (reverse x))))))
- (coord-x (car (car (car (cdr x))))) (coord-y (car (car (car (cdr x))))) (coord-x (car (car (car (cdr x))))) My
- (make-pen (car (cdr (cdr (reverse x)))) (car (cdr (cdr (cdr x)))) "solid" (?Form (car (cdr (reverse x)))) (??Form (car (cdr (reverse x))))))
- (cons (cons (cons (make-coord Mx My) (car (car (cdr x)))) (cdr (car (cdr x)))) (cdr (cdr x)))))
- ((and (= (car (cdr (cdr x))) 2) (>= My (+ 25 (* (car (cdr (cdr (cdr x)))) 0.5))) (mouse=? B "button-down")) (cons (car x) (cons (cons `(,(make-coord Mx My)) (car (cdr x))) (cdr (cdr x)))))
- ((and (= (car (cdr (cdr x))) 3) (>= My 25) (mouse=? B "button-down"))
- (cons (f (image->color-list (car x)) (c->st (car (cdr (cdr (reverse x))))) Mx My (I-th (image->color-list (car x)) (+ (* (sub1 My) 1300) Mx))) (cdr x)))
- (else x))))
- (big-bang x
- (to-draw $Dr)
- (on-mouse $M)))) `(,(empty-scene 1300 675) () 0 15 "black" 0 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement