Skip to content

Combinators and pict constructors I have found useful for writing slideshow presentations.

License

Notifications You must be signed in to change notification settings

deeglaze/slideshow-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Constructors and combinators for pict

This library provides some extra support for constructing and combining picts. It originated as a helper library for several of my presentations, and since I’ve had some reuse with them, so might others.

(list*of contract) -> contract?
  contract : contract?         

The "contract" constructor that is alluded to by the documentation for table. It is an improper list contract, where the last cons pair’s cdr may be '() or a value satisfying contract.

Examples:                                           
> (andmap (list*of number?) '(3 (0 1) (0 1 . 2) ()))
#t                                                  
> ((list*of number?) '(0 . nope))                   
#f                                                  
(colorize-if test pict color) -> pict?
  test : any/c                        
  pict : pict?                        
  color : color/c                     

A useful pattern: (if test (colorize pict color) pict)

(pin-over-center base x y pict) -> pict?
  base : pict?                          
  x : real?                             
  y : real?                             
  pict : pict?                          

Pin the center of pict to x and y over base.

(pin-over-hcenter base x y pict) -> pict?
  base : pict?                           
  x : real?                              
  y : real?                              
  pict : pict?                           

Like pin-over-center, only centers the x-axis.

(pin-over-vcenter base x y pict) -> pict?
  base : pict?                           
  x : real?                              
  y : real?                              
  pict : pict?                           

Like pin-over-hcenter, but for the y-axis.

(both fn) -> void?        
  fn : (-> boolean? void?)

To be used with slide-producing functions that have only two modes, signified by #t and #f.

(pin-under-all base tag pict) -> pict?
  base : pict?                        
  tag : symbol?                       
  pict : pict?                        

Center pict under all picts that are tagged (with tag-pict) with tag in base.

(pin-over-tag base finder tag wrap) -> pict?         
  base : pict?                                       
  finder : (-> pict? pict-path? (values real? real?))
  tag : symbol?                                      
  wrap : (-> pict? pict?)                            

Find a pict in base tagged tag, apply wrap to the found pict and pin over base at the coordinates given by finder.

(pin-under-tag base finder tag wrap) -> pict?        
  base : pict?                                       
  finder : (-> pict? pict-path? (values real? real?))
  tag : symbol?                                      
  wrap : (-> pict? pict?)                            

Like pin-over-tag, but uses pin-under.

(thick-ellipse  w                                 
                h                                 
                border-width                      
                color                             
               [#:fill-color fill-color]) -> pict?
  w : nonneg-real?                                
  h : nonneg-real?                                
  border-width : (real-in 0 255)                  
  color : color/c                                 
  fill-color : (or/c #f color/c) = #f             

Like ellipse/border, only uses the pen to draw a border rather than layer different colored ellipses. This produces more consistent borders.

(thick-filled-rounded-rectangle  w                            
                                 h                            
                                [corner-radius                
                                 #:color color                
                                 #:style style                
                                 #:angle angle                
                                 #:border-width border-width  
                                 #:border-color border-color] 
                                 #:border-style border-style) 
 -> pict?                                                     
  w : nonneg-real?                                            
  h : nonneg-real?                                            
  corner-radius : real? = -0.25                               
  color : color/c = "black"                                   
  style : brush-style/c = 'solid                              
  angle : real? = 0                                           
  border-width : (real-in 0 255) = 1                          
  border-color : (or/c #f color/c) = #f                       
  border-style : pen-style/c                                  

Like filled-rounded-rectangle, but adds a border with a pen. Can additionally rotate the rectangle by angle.

(filled-rounded-rectangle-frame  pict                          
                                [#:corner-radius corner-radius 
                                 #:scale scale                 
                                 #:x-scale x-scale             
                                 #:y-scale y-scale             
                                 #:color color                 
                                 #:angle angle                 
                                 #:border-width border-width   
                                 #:border-color border-color]  
                                 #:border-style border-style)  
 -> pict?                                                      
  pict : pict?                                                 
  corner-radius : real? = -0.25                                
  scale : nonneg-real? = 1                                     
  x-scale : nonneg-real? = 1                                   
  y-scale : nonneg-real? = 1                                   
  color : color/c = "white"                                    
  angle : real? = 0                                            
  border-width : (real-in 0 255) = 1                           
  border-color : (or/c #f color/c) = #f                        
  border-style : pen-style/c                                   

Uses thick-filled-rounded-rectangle to form a frame around a given pict, and gives the ability to scale uniformly and with each dimension. The x-axis and y-axis are scaled by (* scale x-axis) and (* scale y-axis) respectively.