-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Computer graphics for kids and artists with Processing implemented in Haskell. -- -- The library implements the Processing language (see -- https://processing.org/). It's an imperative EDSL for graphics -- and animation. It's very easy and fun to use. There are many books on -- processing and community is fairly active. We can find the quick start -- guide and lots of examples in the project repository on github -- https://github.com/anton-k/processing-for-haskell (see the -- directory examples). There is a tutorial at the project -- homepage at github: -- https://github.com/anton-k/processing-for-haskell. @package processing-for-haskell @version 0.1.0.1 -- | Imperative EDSL for graphics and animation. The libary implements a -- Processing in Haskell. -- -- An example: -- --
-- import Graphics.Proc
--
-- main = runProc $ def { procSetup = setup, procDraw = draw, procUpdate = update }
--
-- setup = do
-- size (300, 300)
-- return 0
--
-- draw x = do
-- background (grey 255)
-- fill (rgb 0 255 0)
-- circle 20 (150 + 50 * sin x, 150)
--
-- update x = return (x + 0.1)
--
--
-- We can find the quickstart guide and lots of examples in the project
-- repository on github
-- https://github.com/anton-k/processing-for-haskell (see the
-- directory examples).
module Graphics.Proc
-- | It holds all processing standard callbacks. With it we can set the
-- setup, draw, and update functions. Here we can specify how to react on
-- user-input.
--
-- All functions update the program state. They take it in as an argument
-- and produce as result. In Haskell we can not manipulate global
-- variables with such ease as Processing provides. So we have to find
-- out another way to update the state. The natural way for Haskell is to
-- keep the things as explicit as possible. That leads to the following
-- decisions:
--
-- -- text <- liftIO $ readFile filename --data Pio a -- | An alias for processing procedures. type Draw = Pio () -- | A alias for value update inside processing IO-monad. type Update s = s -> Pio s -- | Time duration in seconds. type TimeInterval = Float -- | Color datatype. It contains values for three components of the color -- and transparency. All values range in the interval from 0 to 1. data Col Col :: Float -> Float -> Float -> Float -> Col -- | 2D vector. type P2 = (Float, Float) -- | 3D vector. type P3 = (Float, Float, Float) -- | Return the pair of width and height as a 2D vector. winSize :: Pio P2 -- | System variable that stores the width of the display window. This -- value is set by the first parameter of the size() function. -- For example, the function call size(320, 240) sets the width -- variable to the value 320. The value of width defaults to 100 if -- size() is not used in a program. -- -- processing docs: https://processing.org/reference/width.html winWidth :: Pio Float -- | System variable that stores the height of the display window. This -- value is set by the second parameter of the winSize() -- function. For example, the function call winSize(320, 240) -- sets the height variable to the value 240. The value of height -- defaults to 100 if winSize() is not used in a program. -- -- processing docs: https://processing.org/reference/height.html winHeight :: Pio Float -- | Defines the dimension of the display window width and height in units -- of pixels. In a program that has the setup() function, the size() -- function must be the first line of code inside setup(). -- -- processing docs: https://processing.org/reference/size_.html size :: P2 -> Draw -- | Draws all geometry with smooth (anti-aliased) edges. This behavior is -- the default, so smooth() only needs to be used when a program -- needs to set the smoothing in a different way. The level parameter -- increases the level of smoothness. This is the level of over sampling -- applied to the graphics buffer. -- -- processing docs: https://processing.org/reference/smooth_.html smooth :: Draw -- | Draws all geometry and fonts with jagged (aliased) edges and images -- when hard edges between the pixels when enlarged rather than -- interpoloating pixels. Note that smooth() is active by default, so it -- is necessary to call noSmooth() to disable smoothing of geometry, -- fonts, and images. -- -- processing docs: -- https://processing.org/reference/noSmooth_.html noSmooth :: Pio () -- | The system variable frameCount contains the number of frames that have -- been displayed since the program started. Inside setup() the value is -- 0, after the first iteration of draw it is 1, etc. -- -- processing docs: -- https://processing.org/reference/frameCount.html frameCount :: Pio Int -- | Specifies the number of frames to be displayed every second. For -- example, the function call frameRate(30) will attempt to refresh 30 -- times a second. If the processor is not fast enough to maintain the -- specified rate, the frame rate will not be achieved. Setting the frame -- rate within setup() is recommended. The default rate is 60 frames per -- second. -- -- processing docs: -- https://processing.org/reference/frameRate_.html frameRate :: Float -> Pio () -- | By default, Processing loops through draw() continuously, executing -- the code within it. However, the draw() loop may be stopped by calling -- noLoop(). In that case, the draw() loop can be resumed with loop(). -- -- processing docs: https://processing.org/reference/loop_.html loop :: Draw -- | Stops Processing from continuously executing the code within draw(). -- If loop() is called, the code in draw() begins to run continuously -- again. If using noLoop() in setup(), it should be the last line inside -- the block. -- -- processing docs: https://processing.org/reference/noLoop_.html noLoop :: Draw -- | Executes the code within draw() one time. This functions allows the -- program to update the display window only when necessary, for example -- when an event registered by mousePressed() or keyPressed() occurs. -- -- In structuring a program, it only makes sense to call redraw() within -- events such as mousePressed(). This is because redraw() does not run -- draw() immediately (it only sets a flag that indicates an update is -- needed). -- -- processing docs: https://processing.org/reference/redraw_.html redraw :: Draw -- | Converts ints to floats. float :: Int -> Float -- | Converts floats to ints. int :: Float -> Int -- | A triangle is a plane created by connecting three points. -- -- processing docs: -- https://processing.org/reference/triangle_.html triangle :: P2 -> P2 -> P2 -> Draw -- | Draws a rectangle to the screen. A rectangle is a four-sided shape -- with every angle at ninety degrees. By default, the first two -- parameters set the location of the upper-left corner, the third sets -- the width, and the fourth sets the height. The way these parameters -- are interpreted, however, may be changed with the rectMode() function. -- -- processing docs: https://processing.org/reference/rect_.html rect :: P2 -> P2 -> Draw -- | A quad is a quadrilateral, a four sided polygon. It is similar to a -- rectangle, but the angles between its edges are not constrained to -- ninety degrees. The first pair of parameters (x1,y1) sets the first -- vertex and the subsequent pairs should proceed clockwise or -- counter-clockwise around the defined shape. -- -- processing docs: https://processing.org/reference/quad_.html quad :: P2 -> P2 -> P2 -> P2 -> Draw -- | Draws an ellipse (oval) to the screen. An ellipse with equal width and -- height is a circle. By default, the first two parameters set the -- location, and the third and fourth parameters set the shape's width -- and height. The origin may be changed with the ellipseMode() -- function. -- -- processing docs: https://processing.org/reference/ellipse_.html ellipse :: P2 -> P2 -> Draw -- | Draws a circle with a given radius and center. -- --
-- circle radius center --circle :: Float -> P2 -> Draw -- | Draws a line (a direct path between two points) to the screen. -- -- processing docs: https://processing.org/reference/line_.html line :: P2 -> P2 -> Draw -- | Draws a line-path (sequence of line segments). linePath :: [P2] -> Draw -- | Draws a point, a coordinate in space at the dimension of one pixel. -- -- processing docs: https://processing.org/reference/point_.html point :: P2 -> Draw -- | Draws a sequence of points. pointPath :: [P2] -> Draw -- | Draws a polygon. polygon :: [P2] -> Draw -- | Draws a Bezier curve on the screen. These curves are defined by a -- series of anchor and control points. The first two parameters specify -- the first anchor point and the last two parameters specify the other -- anchor point. The middle parameters specify the control points which -- define the shape of the curve. Bezier curves were developed by French -- engineer Pierre Bezier. -- -- processing docs: https://processing.org/reference/bezier_.html bezier :: P2 -> P2 -> P2 -> P2 -> Draw -- | Modes for drawing of ellipse. See ellipseMode. type EllipseMode = DrawMode -- | Modes for drawing of rectangle. See rectMode. type RectMode = DrawMode -- | Modes for drawing of rectangle or ellipse. data DrawMode Radius :: DrawMode Center :: DrawMode Corner :: DrawMode Corners :: DrawMode -- | Modifies the location from which ellipses are drawn by changing the -- way in which parameters given to ellipse() are intepreted. -- -- The default mode is ellipseMode Center, which interprets the -- first two parameters of ellipse() as the shape's center point, while -- the third and fourth parameters are its width and height. -- -- ellipseMode Radius also uses the first two parameters of -- ellipse() as the shape's center point, but uses the third and fourth -- parameters to specify half of the shapes's width and height. -- -- ellipseMode Corner interprets the first two parameters of -- ellipse() as the upper-left corner of the shape, while the third and -- fourth parameters are its width and height. -- -- ellipseMode Corners interprets the first two parameters of -- ellipse() as the location of one corner of the ellipse's bounding box, -- and the third and fourth parameters as the location of the opposite -- corner. ellipseMode :: EllipseMode -> Draw -- | Modifies the location from which rectangles are drawn by changing the -- way in which parameters given to rect() are intepreted. -- -- The default mode is rectMode Corner, which interprets the -- first two parameters of rect() as the upper-left corner of the shape, -- while the third and fourth parameters are its width and height. -- -- rectMode Corners interprets the first two parameters of -- rect() as the location of one corner, and the third and fourth -- parameters as the location of the opposite corner. -- -- rectMode Center interprets the first two parameters of rect() -- as the shape's center point, while the third and fourth parameters are -- its width and height. -- -- rectMode Radius also uses the first two parameters of rect() -- as the shape's center point, but uses the third and fourth parameters -- to specify half of the shapes's width and height. -- -- processing docs: -- https://processing.org/reference/rectMode_.html rectMode :: RectMode -> Draw -- | Sets the width of the stroke used for lines, points, and the border -- around shapes. All widths are set in units of pixels. -- -- processing docs: -- https://processing.org/reference/strokeWelight_.html strokeWeight :: Float -> Draw -- | Contains coordinates of the mouse as a vector. mouse :: Pio P2 -- | The system variable mouseX always contains the current horizontal -- coordinate of the mouse. -- -- processing docs: https://processing.org/reference/mouseX.html mouseX :: Pio Float -- | The system variable mouseX always contains the current vertical -- coordinate of the mouse. -- -- processing docs: https://processing.org/reference/mouseY.html mouseY :: Pio Float -- | Contains relative coordinates of the mouse as a vector. relMouse :: Pio P2 -- | Contains relative mouseX coordinates of the mouse (scaled to -- the interval [0, 1]). relMouseX :: Pio Float -- | Contains relative mouseY coordinates of the mouse (scaled to -- the interval [0, 1]). relMouseY :: Pio Float -- | Mouse buttons, including a wheel data MouseButton :: * LeftButton :: MouseButton MiddleButton :: MouseButton RightButton :: MouseButton WheelUp :: MouseButton WheelDown :: MouseButton AdditionalButton :: Int -> MouseButton mouseButton :: Pio (Maybe MouseButton) -- | A generalized view of keys data Key :: * Char :: Char -> Key SpecialKey :: SpecialKey -> Key MouseButton :: MouseButton -> Key -- | Special keys data SpecialKey :: * KeyF1 :: SpecialKey KeyF2 :: SpecialKey KeyF3 :: SpecialKey KeyF4 :: SpecialKey KeyF5 :: SpecialKey KeyF6 :: SpecialKey KeyF7 :: SpecialKey KeyF8 :: SpecialKey KeyF9 :: SpecialKey KeyF10 :: SpecialKey KeyF11 :: SpecialKey KeyF12 :: SpecialKey KeyLeft :: SpecialKey KeyUp :: SpecialKey KeyRight :: SpecialKey KeyDown :: SpecialKey KeyPageUp :: SpecialKey KeyPageDown :: SpecialKey KeyHome :: SpecialKey KeyEnd :: SpecialKey KeyInsert :: SpecialKey KeyNumLock :: SpecialKey KeyBegin :: SpecialKey KeyDelete :: SpecialKey KeyShiftL :: SpecialKey KeyShiftR :: SpecialKey KeyCtrlL :: SpecialKey KeyCtrlR :: SpecialKey KeyAltL :: SpecialKey KeyAltR :: SpecialKey -- | You should actually never encounter this value, it is just here as a -- safeguard against future changes in the native GLUT library. KeyUnknown :: Int -> SpecialKey -- | Returns last pressed key. -- -- processing docs: https://processing.org/reference/key.html key :: Pio Key -- | The state of the keyboard modifiers data Modifiers :: * Modifiers :: KeyState -> KeyState -> KeyState -> Modifiers [shift] :: Modifiers -> KeyState [ctrl] :: Modifiers -> KeyState [alt] :: Modifiers -> KeyState -- | Returns last pressed key modifier. modifiers :: Pio Modifiers -- | The year() function returns the current year as an integer (2003, -- 2004, 2005, etc). -- -- processing docs: https://processing.org/reference/year_.html year :: Pio Int -- | The month() function returns the current month as a value from 1 - 12. -- -- processing docs: https://processing.org/reference/month_.html month :: Pio Int -- | The day() function returns the current day as a value from 1 - 31. -- -- processing docs: https://processing.org/reference/day_.html day :: Pio Int -- | The hour() function returns the current hour as a value from 0 - 23. -- -- processing docs: https://processing.org/reference/hour_.html hour :: Pio Int -- | The minute() function returns the current minute as a value from 0 - -- 59. -- -- processing docs: https://processing.org/reference/minute_.html minute :: Pio Int -- | The second() function returns the current second as a value from 0 - -- 59. -- -- processing docs: https://processing.org/reference/second_.html second :: Pio Int -- | Returns the number of milliseconds (thousandths of a second) since -- starting the program. This information is often used for timing events -- and animation sequences. -- -- processing docs: https://processing.org/reference/millis_.html millis :: Pio Int -- | Returens univeral hour. utcHour :: Pio Int -- | Prints values on the console. println :: Show a => a -> Pio () -- | Specifies an amount to displace objects within the display window. The -- x parameter specifies leftright translation, the y parameter -- specifies updown translation -- -- processing docs: -- https://processing.org/reference/translate_.html translate :: P2 -> Draw -- | Rotates the amount specified by the angle parameter. Angles must be -- specified in taus (values from 0 to 1) -- -- processing docs: https://processing.org/reference/rotate_.html rotate :: Float -> Draw -- | Rotates around X-axis. rotateX :: Float -> Draw -- | Rotates around Y-axis. rotateY :: Float -> Draw -- | Rotates around Z-axis. rotateZ :: Float -> Draw -- | Increases or decreases the size of a shape by expanding and -- contracting vertices. Objects always scale from their relative origin -- to the coordinate system. Scale values are specified as decimal -- percentages. For example, the function call scale(2.0) increases the -- dimension of a shape by 200%. -- -- processing docs: https://processing.org/reference/scale_.html scale :: P2 -> Draw -- | Replaces the current matrix with the identity matrix. The equivalent -- function in OpenGL is glLoadIdentity(). -- -- processing docs: -- https://processing.org/reference/resetMatrix_.html resetMatrix :: Draw -- | Applies local transformation. Substitutes the pair of pushMatrix and -- popMatrix. It can be used like this: -- --
-- local $ do -- rotate angle -- translate p1 -- drawShape params ---- -- see https://processing.org/reference/pushMatrix_.html and -- https://processing.org/reference/popMatrix_.html local :: Draw -> Draw -- | Multiplies the current matrix by the one specified through the -- parameters. This is very slow because it will try to calculate the -- inverse of the transform, so avoid it whenever possible. The -- equivalent function in OpenGL is glMultMatrix(). -- -- processing docs: -- https://processing.org/reference/applyMatrix_.html applyMatrix :: [Float] -> Draw -- | Shears a shape around the x-axis the amount specified by the angle -- parameter. A -- -- processing docs: https://processing.org/reference/shearX_.html shearX :: Float -> Draw -- | Shears a shape around the y-axis the amount specified by the angle -- parameter. A -- -- processing docs: https://processing.org/reference/shearY_.html shearY :: Float -> Draw -- | Sets the color used to fill shapes. For example, if you run fill -- (rgb 204 102 0), all subsequent shapes will be filled with -- orange. -- -- processing docs: https://processing.org/reference/fill_.html fill :: Col -> Draw -- | Disables filling geometry. If both noStroke() and noFill() are called, -- nothing will be drawn to the screen. -- -- processing docs: https://processing.org/reference/noFill_.html noFill :: Draw -- | Sets the color used to draw lines and borders around shapes. -- -- processing docs: https://processing.org/reference/stroke_.html stroke :: Col -> Draw -- | Disables drawing the stroke (outline). If both noStroke() and noFill() -- are called, nothing will be drawn to the screen -- -- processing docs: -- https://processing.org/reference/noStroke_.html noStroke :: Draw -- | Sets stroke and fill to the same color. strokeFill :: Col -> Draw -- | Creates an RGB-color from three values. The values are from 0 to 255. rgb :: Float -> Float -> Float -> Col -- | Creates an RGB-color with transparency. rgba :: Float -> Float -> Float -> Float -> Col -- | Creates a grey value out of single float value. The value is from 0 to -- 255. grey :: Float -> Col -- | Creates an grey-color with transparency. greya :: Float -> Float -> Col setAlpha :: Float -> Col -> Col -- | The background() function sets the color used for the background of -- the Processing window. The default background is light gray. This -- function is typically used within draw() to clear the display window -- at the beginning of each frame, but it can be used inside setup() to -- set the background on the first frame of animation or if the backgound -- need only be set once. -- -- processing docs: -- https://processing.org/reference/background_.html background :: Col -> Draw -- | Clears the pixels within a buffer. -- -- processing docs: https://processing.org/reference/clear_.html clear :: Draw -- | White color. white :: Col -- | Black color. black :: Col -- | Nave color. navy :: Col -- | Blue color. blue :: Col -- | Aqua color. aqua :: Col -- | Teal color. teal :: Col -- | Olive color. olive :: Col -- | Green color. green :: Col -- | Lime color. lime :: Col -- | Yellow color. yellow :: Col -- | Orange color orange :: Col -- | Red color red :: Col -- | Maroon color. maroon :: Col -- | Fuchsia color. fushsia :: Col -- | Purple color purple :: Col -- | Gray color. gray :: Col -- | Silver color. silver :: Col -- | Re-maps a number from one range to another. Originally called map in -- the Processing, but in Haskell this name is already taken. -- -- processing docs: https://processing.org/reference/map_.html remap :: FloatInterval -> FloatInterval -> Float -> Float -- | Interval for float value (minValue, maxValue). type FloatInterval = (Float, Float) -- | Constrains a value to not exceed a maximum and minimum value. -- -- processing docs: -- https://processing.org/reference/constrain_.html constrain :: (Float, Float) -> Float -> Float -- | The constrian that is defined on vectors. constrain2 :: (P2, P2) -> P2 -> P2 -- | Converts degrees to radians. radians :: Float -> Float -- | Converts rdians to degrees. degrees :: Float -> Float -- | Converts angle in taus to unit vector rotated by given angle. e :: Float -> P2 -- | The function e in radians. erad :: Float -> P2 -- | Sets the seed value for random(). By default, random() produces -- different results each time the program is run. Set the seed parameter -- to a constant to return the same pseudo-random numbers each time the -- software is run. -- -- processing docs: -- https://processing.org/reference/randomSeed_.html randomSeed :: Int -> Pio () -- | Generates random numbers. Each time the random() function is called, -- it returns an unexpected value within the specified range. If only one -- parameter is passed to the function, it will return a float between -- zero and the value of the high parameter. For example, random(5) -- returns values between 0 and 5 (starting at zero, and up to, but not -- including, 5). -- -- processing docs: https://processing.org/reference/random_.html random :: Float -> Pio Float -- | Genrates random numbers within the given range. random2 :: (Float, Float) -> Pio Float -- | Creates random point within the ranges of the size of the screen. randomP2 :: Pio P2 -- | Creates random color. randomCol :: Pio Col -- | Creates random color with transparency. randomCola :: Pio Col -- | Returns a float from a random series of numbers having a mean of 0 and -- standard deviation of 1. Each time the randomGaussian() function is -- called, it returns a number fitting a Gaussian, or normal, -- distribution. There is theoretically no minimum or maximum value that -- randomGaussian() might return. Rather, there is just a very low -- probability that values far from the mean will be returned; and a -- higher probability that numbers near the mean will be returned. -- -- processing docs: -- https://processing.org/reference/randomGaussian_.html randomGaussian :: Pio Float -- | Parameters for perlin noise. See docs for function -- noiseDetail. data NoiseDetail NoiseDetail :: Int -> Float -> NoiseDetail [noiseDetailsOctaves] :: NoiseDetail -> Int [noiseDetailsFalloff] :: NoiseDetail -> Float -- | Adjusts the character and level of detail produced by the Perlin noise -- function. Similar to harmonics in physics, noise is computed over -- several octaves. Lower octaves contribute more to the output signal -- and as such define the overal intensity of the noise, whereas higher -- octaves create finer-grained details in the noise sequence. -- -- By default, noise is computed over 4 octaves with each octave -- contributing exactly half than its predecessor, starting at 50% -- strength for the first octave. This falloff amount can be changed by -- adding an additional function parameter. For example, a falloff factor -- of 0.75 means each octave will now have 75% impact (25% less) of the -- previous lower octave. While any number between 0.0 and 1.0 is valid, -- note that values greater than 0.5 may result in noise() returning -- values greater than 1.0. -- -- By changing these parameters, the signal created by the noise() -- function can be adapted to fit very specific needs and -- characteristics. -- -- processing docs: -- https://processing.org/reference/noiseDetail_.html noiseDetail :: Int -> Float -> Pio () -- | Sets the number of octaves for perlin noise. noiseOctaves :: Int -> Pio () -- | Sets the seed value for noise(). By default, noise() produces -- different results each time the program is run. Set the seed parameter -- to a constant to return the same pseudo-random numbers each time the -- software is run. -- -- processing docs: -- https://processing.org/reference/noiseSeed_.html noiseSeed :: Int -> Pio () -- | Returns 1D Perlin noise. noise1 :: Float -> Pio Float -- | Returns 2D Perlin noise. noise2 :: P2 -> Pio Float -- | Returns 3D Perlin noise. noise3 :: P3 -> Pio Float -- | Maps values from interval (0, 1) to the points on the circle. -- --
-- onCircle radius center value --onCircle :: Float -> P2 -> Float -> P2 -- | Maps values from interval (0, 1) to the points on the line segment. -- --
-- onLine point1 point2 value --onLine :: P2 -> P2 -> Float -> P2 -- | Rescales the unipolar scale (0, 1) to the given range. uon :: (Float, Float) -> Float -> Float -- | Datatyp for mutable variables. We can create a reference and then -- manipulate the value with functions readPioRef and -- writePioRef. The API is the same as in the case of -- IORefs. It's standard way to work with mutables in haskell. data PioRef a -- | Creates a reference for a mutable value. The argument is an initial -- value assigned to the variable. newPioRef :: a -> Pio (PioRef a) -- | Reads the value from the reference. readPioRef :: PioRef a -> Pio a -- | Writes the value to reference. writePioRef :: PioRef a -> a -> Pio () -- | Modifies a value iside the reference with a function. modifyPioRef :: PioRef a -> (a -> a) -> Pio ()