#lang scribble/doc @(require scribble/manual (for-label scheme "picturing-programs.ss" ; "io-stuff.ss" ; "sb-universe.ss" ; "tiles.ss" 2htdp/image teachpack/2htdp/universe (only-in lang/htdp-beginner check-expect) )) @; teachpack["picturing-programs"]{Picturing Programs} @title{Picturing Programs Teachpack} @author{Stephen Bloch} @defmodule[(planet sbloch/picturing-programs/picturing-programs)] @section{About This Teachpack} Provides a variety of functions for combining and manipulating images and running interactive animations. It's intended to be used with the textbook @hyperlink["http://www.picturingprograms.com" "Picturing Programs"]. @section{Installation} If you're reading this, you've probably already installed the teachpack successfully, but if you need to install it on a different machine, ... @itemize[#:style 'ordered @item{start DrScheme} @item{switch languages to "Use the language declared in the source" (formerly known as "Module") and click "Run"} @item{in the Interactions pane, type @schemeblock[(require (planet sbloch/picturing-programs:2))]} @item{after a few seconds, you should see the message @schemeblock{Wrote file "picturing-programs.ss" to installed-teachpacks directory.}} @item{switch languages back to one of the HtDP languages, like Beginning Student} @item{either @itemize{ @item{in the Definitions pane, type @schemeblock[(require installed-teachpacks/picturing-programs)] or} @item{from the Language menu, choose "Add Teachpack..." and select "picturing-programs.ss"} } } @item{click "Run"} ] @section{Functions from image.ss and universe.ss} This package includes all of @schememodlink[2htdp/image]{the image teachpack} and and @schememodlink[2htdp/universe]{the universe teachpack}, so if you're using this teachpack, @emph{don't} also load either of those. See the above links for how to use those teachpacks. It also supersedes the older @scheme{tiles} and @scheme{sb-world} teachpacks, so if you have those, don't load them either; use this instead. This package also provides the following additional functions: @; @include-section{image.ss} @section{New image functions} @defproc[(rotate-cw (img image?)) image?]{ Rotates an image 90 degrees clockwise.} @defproc[(rotate-ccw (img image?)) image?]{ Rotates an image 90 degrees counterclockwise.} @defproc[(rotate-180 (img image?)) image?]{ Rotates an image 180 degrees around its center.} @defproc[(crop-top (img image?) (pixels natural-number/c)) image?]{ Chops off the specified number of pixels from the top of the image.} @defproc[(crop-bottom (img image?) (pixels natural-number/c)) image?]{ Chops off the specified number of pixels from the bottom of the image.} @defproc[(crop-left (img image?) (pixels natural-number/c)) image?]{ Chops off the specified number of pixels from the left side of the image.} @defproc[(crop-right (img image?) (pixels natural-number/c)) image?]{ Chops off the specified number of pixels from the right side of the image.} @defproc[(show-it (img image?)) image?]{ Returns the given image unaltered. Useful as a draw handler for animations whose model is an image.} @defproc[(reflect-vert (img image?)) image?]{ The same as @scheme{flip-vertical}; retained for compatibility.} @defproc[(reflect-horiz (img image?)) image?]{ The same as @scheme{flip-horizontal}; retained for compatibility.} @section{Input and Output} This teachpack also provides five functions to help in testing I/O functions (in Advanced Student language; ignore this section if you're in a Beginner or Intermediate language): @defproc[(with-input-from-string (input string?) (thunk (-> any/c))) any/c]{ Calls @tt{thunk}, which presumably uses @scheme[read], in such a way that @scheme[read] reads from @tt{input} rather than from the keyboard.} @defproc[(with-output-to-string (thunk (-> any/c))) string?]{ Calls @tt{thunk}, which presumably uses @scheme[display], @scheme[print], @scheme[write], and/or @scheme[printf], in such a way that its output is accumlated into a string, which is then returned.} @defproc[(with-input-from-file (filename string?) (thunk (-> any/c))) any/c]{ Calls @tt{thunk}, which presumably uses @scheme[read], in such a way that @scheme[read] reads from the specified file rather than from the keyboard.} @defproc[(with-output-to-file (filename string?) (thunk (-> any/c))) any/c]{ Calls @tt{thunk}, which presumably uses @scheme[display], @scheme[print], @scheme[write], and/or @scheme[printf], in such a way that its output is redirected into the specified file.} @defproc[(with-input-from-url (url string?) (thunk (-> any/c))) any/c] {Calls @tt{thunk}, which presumably uses @scheme[read], in such a way that @scheme[read] reads from the HTML source of the Web page at the specified URL rather than from the keyboard.} @defproc[(with-io-strings (input string?) (thunk (-> any/c))) string?]{ Combines @scheme[with-input-from-string] and @scheme[with-output-to-string]: calls @tt{thunk} with its input coming from @tt{input} and accumulates its output into a string, which is returned. Especially useful for testing: @schemeblock[ (define (ask question) (begin (display question) (read))) (define (greet) (local [(define name (ask "What is your name?"))] (printf "Hello, ~a!" name))) (check-expect (with-io-strings "Steve" greet) "What is your name?Hello, Steve!")] } @; @include-section{worlds.scrbl} @; @include-section{universes.scrbl}