;;;-*- indent-tabs-mode: nil -*- ;;; Copyright © 2005 Jeremy English ;;; ;;; Permission to use, copy, modify, distribute, and sell this software and its ;;; documentation for any purpose is hereby granted without fee, provided that ;;; the above copyright notice appear in all copies and that both that ;;; copyright notice and this permission notice appear in supporting ;;; documentation. No representations are made about the suitability of this ;;; software for any purpose. It is provided "as is" without express or ;;; implied warranty. ;;; ;;; Created: 14-December-2005 ;; The Basic Algorithm ;;------------------------------------------------------------------------- ;; decide on a sample size ;; loop: grab the color for the sample size on the black and white image ;; use the gray value to determine the brush size ;; if they want color pull the color from the original image ;; change the paint brush to the color if they want it ;; paint the dot in the middle of the range selection on the new blank image ;; move to the next postion on the black and white and goto loop (define (script-fu-image-fill-points image drawable sample-size use-colors? fadeout points-tail) (define (rand-range n) (fmod (rand) n)) ;; return a new list with the items from n to m of the old list (define (copy-from n m ls) (define (cp-i i j L) (cond ((or (< i 0) (> i j) (>= i (length ls))) L) (t (set! L (cons (nth i ls) L)) (cp-i (+ i 1) j L)))) (nreverse (cp-i n m (list)))) (define (my-make-new-image width height) (let* ((image (car (gimp-image-new width height RGB))) (layer (car (gimp-layer-new image width height RGB-IMAGE "foobar" 100 NORMAL-MODE)))) (gimp-drawable-fill layer BG-IMAGE-FILL) (gimp-image-add-layer image layer 0) (gimp-display-new image) (cons image layer))) (define (width-height image) (cons (car (gimp-image-width image)) (car (gimp-image-height image)))) ;works if the list is flat (define (list->array list) (define (push-item ar idx) (cond ((< idx 0) ar) (t (aset ar idx (nth idx list)) (push-item ar (- idx 1))))) (let* ((len (length list)) (ar (cons-array len 'double))) (push-item ar (- len 1)))) (define (get-brush color brush-list) (let* ((idx (/ (caar color) ;pull red (/ 255 (car brush-list))))) (cond ((>= idx (car brush-list)) (set! idx (- (car brush-list) 1)))) (nth idx (reverse (cadr brush-list))))) (define (same-points x y width height) (list x y)) (define (move-center x y width height) (list x y 0 0)) (define (move-left x y width height) (list x y 0 y)) (define (move-right x y width height) (list x y width y)) (define (move-up x y width height) (list x y x 0)) (define (move-down x y width height) (list x y x height)) (define (move-rand x y width height) (list x y (rand-range width) (rand-range height))) (define (move-center x y width height) (list x y (/ width 2) (/ height 2))) (define (put-dot original-image original-layer bw-image bw-layer working-layer top-left sample-size brush-list use-colors? fadeout adj_points) (let* ((points (adj_points (car top-left) (cadr top-left) (car (width-height original-image)) (cdr (width-height original-image))))) (cond ((= use-colors? TRUE) (gimp-palette-set-foreground (car (gimp-image-pick-color original-image original-layer (car points) (cadr points) 0 sample-size 1))))) (gimp-context-set-brush (get-brush (gimp-image-pick-color bw-image bw-layer (car points) (cadr points) 0 sample-size 1) brush-list)) (gimp-paintbrush working-layer fadeout (length points) (list->array points) 0 0))) (define (generate-points width height step func) ;start x and y at zero ;1 ;step x until we go over the width ;step y go back to 1 if y is less then height (define (step-y y ) (define (step-x x) (cond ((>= x width) t) (t (func x y) (step-x (+ x step))))) (cond ((>= y height) t) (t (step-x 0) (step-y (+ y step))))) (step-y 0)) (define (adjust-brush-list brush-list sample-size) (let* ((num-items (car brush-list)) (brushes (cadr brush-list))) (define (check-brush n) (cond ((or (> sample-size (car (gimp-brush-get-info (nth n brushes)))) (<= n 0)) n) (t (check-brush (- n 1))))) (let* ((new-length (check-brush (- num-items 1)))) (cond ((< new-length 0) t) (t (set-car! brush-list (+ new-length 1)) (set-cdr! brush-list (list (copy-from 0 new-length brushes))) brush-list))))) (let* ((old-fg (car (gimp-palette-get-foreground))) (width (car (width-height image))) (height (cdr (width-height image))) (bw-list (my-make-new-image width height)) (bw-image (car bw-list)) (bw-layer (cdr bw-list)) (blank-layer 0) (brush-list (gimp-brushes-get-list "fuzzy")) (tail-dir-list (list same-points move-left move-right move-up move-down move-rand move-center))) ;Copy the drawable and make it black and white (cond ;copy layer ((= (car (gimp-edit-copy drawable)) TRUE) (gimp-edit-paste bw-layer 0) ;make the new layer black and white (gimp-image-convert-grayscale bw-image) ;create a new layer fill with background color (set! blank-layer (car (gimp-layer-copy drawable 1))) (gimp-image-add-layer image blank-layer -1) (gimp-layer-set-name blank-layer "blank") (gimp-drawable-fill blank-layer BG-IMAGE-FILL) (adjust-brush-list brush-list sample-size) (generate-points width height sample-size (lambda (x y) (put-dot image drawable bw-image bw-layer blank-layer (list x y) sample-size brush-list use-colors? fadeout (nth points-tail tail-dir-list)))) ; Cleanup (gimp-palette-set-foreground old-fg) (gimp-image-merge-visible-layers bw-image 1) (gimp-image-merge-visible-layers image 1) (gimp-displays-flush)) (t (gimp-message "Could not copy drawable. See you later"))))) (script-fu-register "script-fu-image-fill-points" _"/Script-Fu/Render/Image Fill Points..." "Fill the image with random characters." "Jeremy English " "Jeremy English" "2005/12/12" "RGB GRAY" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-VALUE "Sample Size" "20" SF-TOGGLE "Use Color?" FALSE SF-VALUE "Fadeout" "10" SF-OPTION "Point's Tail" '("same" "left" "right" "up" "down" "random" "center"))