CS 330 Lecture 36 – GIMP example, macros
May 2, 2012 by Chris Johnson. Filed under
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
cs330, lectures, spring 2012.
Agenda
- program this
- GIMP Script-Fu floodfilling example
Program this
Sketch out the pseudocode for implementing a paintbucket operation in an image editor.
Script-Fu template
(script-fu-register
"floodfill"
"Hackbucket"
"Performs the hackbucket operation very slowly"
"Chris Johnson"
"You wrote this code, not me."
"May 2, 2012"
""
ARGS
...
)
(script-fu-menu-register "floodfill" "<Image>/CS330")
Code
hackbucket.scm
(define floodfill
(lambda (image color x y)
(let
((layer (car (gimp-image-get-active-layer image)))
(fill-color (cons-array 3 'byte)))
; check for fill != init
(floodfill-helper layer (car (cdr (gimp-drawable-get-pixel layer x y))) fill-color x y))))
(define floodfill-helper
(lambda (layer init-color fill-color x y)
(cond
; check for canvas drop off
((< x 0) '())
((< y 0) '())
; TODO
((not (equal? (car (cdr (gimp-drawable-get-pixel layer x y))) init-color)) '())
; general case
(else
(begin
(color-pixel-at layer fill-color x y)
(floodfill-helper layer init-color fill-color (+ x 1) y)
(floodfill-helper layer init-color fill-color (- x 1) y)
(floodfill-helper layer init-color fill-color x (+ y 1))
(floodfill-helper layer init-color fill-color x (- y 1)))))))
(define color-pixel-at
(lambda (layer color x y)
(gimp-drawable-set-pixel layer x y 3 color)
(gimp-displays-flush)
(gimp-drawable-update layer x y 1 1)))
(script-fu-register
"floodfill"
"Hackbucket"
"Performs the hackbucket operation very slowly"
"Chris Johnson"
"You wrote this code, not me."
"May 2, 2012"
""
SF-IMAGE "Image" 0
SF-COLOR "Color" '(0 0 0)
SF-VALUE "X" "0"
SF-VALUE "Y" "0"
)
(script-fu-menu-register "floodfill" "<Image>/CS330")
Haiku
Plugins tweak software.
But what about appliances?
Blenders need Whip-Fu.