codeworld-api-0.2.5: Graphics library for CodeWorld

Safe HaskellNone
LanguageHaskell98

CodeWorld

Contents

Synopsis

Entry points

drawingOf #

Arguments

:: Picture

The picture to show on the screen.

-> IO () 

Draws a Picture. This is the simplest CodeWorld entry point.

animationOf #

Arguments

:: (Double -> Picture)

A function that produces animation frames, given the time in seconds.

-> IO () 

Shows an animation, with a picture for each time given by the parameter.

activityOf #

Arguments

:: world

The initial state of the interaction.

-> (Event -> world -> world)

The event handling function, which updates the state given an event.

-> (world -> Picture)

The visualization function, which converts the state into a picture to display.

-> IO () 

Runs an interactive CodeWorld program that responds to events. Activities can interact with the user, change over time, and remember information about the past.

debugActivityOf #

Arguments

:: world

The initial state of the interaction.

-> (Event -> world -> world)

The event handling function, which updates the state given an event.

-> (world -> Picture)

The visualization function, which converts the state into a picture to display.

-> IO () 

Runs an interactive CodeWorld program in debugging mode. In this mode, the program gets controls to pause and manipulate time, and even go back in time to look at past states.

groupActivityOf #

Arguments

:: Int

The number of participants to expect. The participants will be ^ numbered starting at 0.

-> StaticPtr (StdGen -> world)

The initial state of the activity.

-> StaticPtr (Int -> Event -> world -> world)

The event handling function, which updates the state given a participant number and user interface event.

-> StaticPtr (Int -> world -> Picture)

The visualization function, which converts a participant number and the state into a picture to display.

-> IO () 

Runs an interactive multi-user CodeWorld program that is joined by several participants over the internet.

unsafeGroupActivityOf #

Arguments

:: Int

The number of participants to expect. The participants will be ^ numbered starting at 0.

-> (StdGen -> world)

The initial state of the activity.

-> (Int -> Event -> world -> world)

The event handling function, which updates the state given a participant number and user interface event.

-> (Int -> world -> Picture)

The visualization function, which converts a participant number and the state into a picture to display.

-> IO () 

A version of groupActivityOf that avoids static pointers, and does not check for consistency.

simulationOf #

Arguments

:: world

The initial state of the simulation.

-> (Double -> world -> world)

The time step function, which advances the state given the time difference.

-> (world -> Picture)

The visualization function, which converts the state into a picture to display.

-> IO () 

Shows a simulation, which is essentially a continuous-time dynamical system described by an initial value and step function.

debugSimulationOf #

Arguments

:: world

The initial state of the simulation.

-> (Double -> world -> world)

The time step function, which advances the state given the time difference.

-> (world -> Picture)

The visualization function, which converts the state into a picture to display.

-> IO () 

interactionOf #

Arguments

:: world

The initial state of the interaction.

-> (Double -> world -> world)

The time step function, which advances the state given the time difference.

-> (Event -> world -> world)

The event handling function, which updates the state given a user interface event.

-> (world -> Picture)

The visualization function, which converts the state into a picture to display.

-> IO () 

Runs an interactive event-driven CodeWorld program. This is a generalization of simulations that can respond to events like key presses and mouse movement.

debugInteractionOf #

Arguments

:: world

The initial state of the interaction.

-> (Double -> world -> world)

The time step function, which advances the state given the time difference.

-> (Event -> world -> world)

The event handling function, which updates the state given a user interface event.

-> (world -> Picture)

The visualization function, which converts the state into a picture to display.

-> IO () 

collaborationOf #

Arguments

:: Int

The number of participants to expect. The participants will be ^ numbered starting at 0.

-> StaticPtr (StdGen -> world)

The initial state of the collaboration.

-> StaticPtr (Double -> world -> world)

The time step function, which advances the state given the time difference.

-> StaticPtr (Int -> Event -> world -> world)

The event handling function, which updates the state given a participant number and user interface event.

-> StaticPtr (Int -> world -> Picture)

The visualization function, which converts a participant number and the state into a picture to display.

-> IO () 

Runs an interactive multi-user CodeWorld program, involving multiple participants over the internet.

unsafeCollaborationOf #

Arguments

:: Int

The number of participants to expect. The participants will be ^ numbered starting at 0.

-> (StdGen -> world)

The initial state of the collaboration.

-> (Double -> world -> world)

The time step function, which advances the state given the time difference.

-> (Int -> Event -> world -> world)

The event handling function, which updates the state given a participant number and user interface event.

-> (Int -> world -> Picture)

The visualization function, which converts a participant number and the state into a picture to display.

-> IO () 

A version of collaborationOf that avoids static pointers, and does not check for consistent parameters.

Pictures

data Picture #

Instances

data TextStyle #

Constructors

Plain 
Bold 
Italic 

Instances

Show TextStyle # 

Methods

showsPrec :: Int -> TextStyle -> ShowS

show :: TextStyle -> String

showList :: [TextStyle] -> ShowS

data Font #

Instances

Show Font # 

Methods

showsPrec :: Int -> Font -> ShowS

show :: Font -> String

showList :: [Font] -> ShowS

blank :: HasCallStack => Picture #

A blank picture

polyline :: HasCallStack => [Point] -> Picture #

A thin sequence of line segments, with these points as endpoints

path :: HasCallStack => [Point] -> Picture #

Warning: Please use polyline instead of path.path may be removed July 2019.

A thin sequence of line segments, with these points as endpoints

thickPolyline :: HasCallStack => Double -> [Point] -> Picture #

A thick sequence of line segments, with given line width and endpoints

thickPath :: HasCallStack => Double -> [Point] -> Picture #

Warning: Please used thickPolyline instead of thickPath.thickPath may be removed July 2019.

A thick sequence of line segments, with given line width and endpoints

polygon :: HasCallStack => [Point] -> Picture #

A thin polygon with these points as vertices

thickPolygon :: HasCallStack => Double -> [Point] -> Picture #

A thick polygon with this line width and these points as vertices

solidPolygon :: HasCallStack => [Point] -> Picture #

A solid polygon with these points as vertices

curve :: HasCallStack => [Point] -> Picture #

A smooth curve passing through these points.

thickCurve :: HasCallStack => Double -> [Point] -> Picture #

A thick smooth curve with this line width, passing through these points.

closedCurve :: HasCallStack => [Point] -> Picture #

A smooth closed curve passing through these points.

thickClosedCurve :: HasCallStack => Double -> [Point] -> Picture #

A thick smooth closed curve with this line width, passing through these points.

solidClosedCurve :: HasCallStack => [Point] -> Picture #

A solid smooth closed curve passing through these points.

rectangle :: HasCallStack => Double -> Double -> Picture #

A thin rectangle, with this width and height

solidRectangle :: HasCallStack => Double -> Double -> Picture #

A solid rectangle, with this width and height

thickRectangle :: HasCallStack => Double -> Double -> Double -> Picture #

A thick rectangle, with this line width, and width and height

circle :: HasCallStack => Double -> Picture #

A thin circle, with this radius

solidCircle :: HasCallStack => Double -> Picture #

A solid circle, with this radius

thickCircle :: HasCallStack => Double -> Double -> Picture #

A thick circle, with this line width and radius

arc :: HasCallStack => Double -> Double -> Double -> Picture #

A thin arc, starting and ending at these angles, with this radius

Angles are in radians.

sector :: HasCallStack => Double -> Double -> Double -> Picture #

A solid sector of a circle (i.e., a pie slice) starting and ending at these angles, with this radius

Angles are in radians.

thickArc :: HasCallStack => Double -> Double -> Double -> Double -> Picture #

A thick arc with this line width, starting and ending at these angles, with this radius.

Angles are in radians.

text :: HasCallStack => Text -> Picture #

Warning: Please used lettering instead of text.text may be removed July 2019.

A rendering of text characters.

lettering :: HasCallStack => Text -> Picture #

A rendering of text characters.

styledText :: HasCallStack => TextStyle -> Font -> Text -> Picture #

Warning: Please used styledLettering instead of styledText.styledText may be removed July 2019.

A rendering of text characters, with a specific choice of font and style.

styledLettering :: HasCallStack => TextStyle -> Font -> Text -> Picture #

A rendering of text characters onto a Picture, with a specific choice of font and style.

colored :: HasCallStack => Color -> Picture -> Picture #

A picture drawn entirely in this color.

coloured :: HasCallStack => Color -> Picture -> Picture #

A picture drawn entirely in this colour.

translated :: HasCallStack => Double -> Double -> Picture -> Picture #

A picture drawn translated in these directions.

scaled :: HasCallStack => Double -> Double -> Picture -> Picture #

A picture scaled by these factors.

dilated :: HasCallStack => Double -> Picture -> Picture #

A picture scaled by these factors.

rotated :: HasCallStack => Double -> Picture -> Picture #

A picture rotated by this angle.

Angles are in radians.

(<>) :: Monoid m => m -> m -> m #

(&) :: Picture -> Picture -> Picture infixr 0 #

Binary composition of pictures.

coordinatePlane :: HasCallStack => Picture #

A coordinate plane. Adding this to your pictures can help you measure distances more accurately.

Example:

main = drawingOf (myPicture <> coordinatePlane) myPicture = ...

:: HasCallStack => Picture #

The CodeWorld logo.

type Point = (Double, Double) #

translatedPoint :: Double -> Double -> Point -> Point #

rotatedPoint :: Double -> Point -> Point #

scaledPoint :: Double -> Double -> Point -> Point #

dilatedPoint :: Double -> Point -> Point #

type Vector = (Double, Double) #

vectorLength :: Vector -> Double #

vectorDirection :: Vector -> Double #

scaledVector :: Double -> Vector -> Vector #

rotatedVector :: Double -> Vector -> Vector #

Angle is in radians

dotProduct :: Vector -> Vector -> Double #

Colors

data Color #

Constructors

RGBA !Double !Double !Double !Double 

Instances

Eq Color # 

Methods

(==) :: Color -> Color -> Bool

(/=) :: Color -> Color -> Bool

Show Color # 

Methods

showsPrec :: Int -> Color -> ShowS

show :: Color -> String

showList :: [Color] -> ShowS

type Colour = Color #

pattern RGB :: Double -> Double -> Double -> Color #

pattern HSL :: Double -> Double -> Double -> Color #

gray :: Double -> Color #

grey :: Double -> Color #

lighter :: Double -> Color -> Color #

darker :: Double -> Color -> Color #

brighter :: Double -> Color -> Color #

duller :: Double -> Color -> Color #

assortedColors :: [Color] #

An infinite list of colors.

hue :: Color -> Double #

saturation :: Color -> Double #

luminosity :: Color -> Double #

alpha :: Color -> Double #

Events

data Event #

An event initiated by the user.

Values of this type represent events that the user triggers when using an interactive program.

Key events describe the key as Text. Most keys are represented by a single character text string, with the capital letter or other symbol from the key. Keys that don't correspond to a single character use longer names from the following list. Keep in mind that not all of these keys appear on all keyboards.

  • Up, Down, Left, and Right for the cursor keys.
  • F1, F2, etc. for function keys.
  • Backspace
  • Tab
  • Enter
  • Shift
  • Ctrl
  • Alt
  • Esc
  • PageUp
  • PageDown
  • End
  • Home
  • Insert
  • Delete
  • CapsLock
  • NumLock
  • ScrollLock
  • PrintScreen
  • Break
  • Separator
  • Cancel
  • Help

Constructors

KeyPress !Text 
KeyRelease !Text 
MousePress !MouseButton !Point

Warning: Please use PointerPress instead of MousePress.MousePress may be removed July 2019.

MouseRelease !MouseButton !Point

Warning: Please use PointerRelease instead of MouseRelease.MouseRelease may be removed July 2019.

MouseMovement !Point

Warning: Please use PointerMovement instead of MouseMovement.MouseMovement may be removed July 2019.

TimePassing !Double 

Instances

Eq Event # 

Methods

(==) :: Event -> Event -> Bool

(/=) :: Event -> Event -> Bool

Read Event # 

Methods

readsPrec :: Int -> ReadS Event

readList :: ReadS [Event]

readPrec :: ReadPrec Event

readListPrec :: ReadPrec [Event]

Show Event # 

Methods

showsPrec :: Int -> Event -> ShowS

show :: Event -> String

showList :: [Event] -> ShowS

data MouseButton #

Warning: Please use pointer events, which don't have buttons.MouseButton may be removed July 2019.

Instances

Eq MouseButton # 

Methods

(==) :: MouseButton -> MouseButton -> Bool

(/=) :: MouseButton -> MouseButton -> Bool

Read MouseButton # 

Methods

readsPrec :: Int -> ReadS MouseButton

readList :: ReadS [MouseButton]

readPrec :: ReadPrec MouseButton

readListPrec :: ReadPrec [MouseButton]

Show MouseButton # 

Methods

showsPrec :: Int -> MouseButton -> ShowS

show :: MouseButton -> String

showList :: [MouseButton] -> ShowS

pattern PointerPress :: Point -> Event #

pattern PointerRelease :: Point -> Event #

Debugging

trace :: Text -> a -> a #

Prints a debug message to the CodeWorld console when a value is forced. This is equivalent to the similarly named function in Trace, except that it uses the CodeWorld console instead of standard output.