================================================================================ PEBLObjects - Graphics and Objects ================================================================================ This module contains functions for creating and manipulating graphical objects, windows, and visual elements. .. contents:: Function Index :local: :depth: 0 .. index:: AddObject AddObject() ----------- *Adds an object to a parent object (window)* **Description:** Adds a widget to a parent window, at the top of the object stack. Once added, the object will be drawn onto the parent last, meaning it will be on top of anything previously added. In general, objects can be added to other objects as well as windows. For example, you can add drawing objects (circles, etc.) to an image to annotate the image and maintain its proper x,y coordinates. Also, if you 're-add' an object that is already on a widget, it will get automatically removed from the window first. This is an easy way to reorder elements on a screen. .. code-block:: text AddObject(, ) AddObject(, ) AddObject(, ) **Example:** .. code-block:: pebl define Start(p) { win <- MakeWindow() img <- MakeImage("pebl.png") circ <- Circle(20,20,10,MakeColor("red"),1) AddObject(circ,img) AddObject(img,win) Move(img,100,100) Draw() WaitForAnyKeyPress() } **See Also:** :func:`RemoveObject()` .. index:: Bezier Bezier() -------- *Creates bezier curve centered at x,y with relative points* **Description:** Creates a smoothed line through the points specified by ````, ````. The lists ```` and ```` are adjusted by ```` and ````, so they should be relative to 0, not the location you want the points to be at. Like other drawn objects, the bezier must then be added to the window to appear. denotes how smooth the approximation will be. **Usage:** .. code-block:: pebl Bezier(,,,, ,) **Example:** .. code-block:: pebl win <- MakeWindow() #This makes a T xpoints <- [-10,10,10,20,20,-20,-20,-10] ypoints <- [-20,-20,40,40,50,50,40,40] p1 <- Bezier(100,100,xpoints, ypoints, 5, MakeColor("black")) AddObject(p1,win) Draw() **See Also:** :func:`BlockE()`, :func:`Polygon()`, :func:`MakeStarPoints()`, :func:`MakeNGonPoints()` .. index:: Circle Circle() -------- *Creates circle with radius r centered at position x,y* **Description:** Creates a circle for graphing at x,y with radius r. Circles must be added to a parent widget before it can be drawn; it may be added to widgets other than a base window. The properties of circles may be changed by accessing their properties directly, including the FILLED property which makes the object an outline versus a filled shape. **Usage:** .. code-block:: pebl Circle(, , ,) **Example:** .. code-block:: pebl c <- Circle(30,30,20, MakeColor(green)) AddObject(c, win) Draw() **See Also:** :func:`Square()`, :func:`Ellipse()`, :func:`Rectangle()`, :func:`Line()` .. index:: Draw Draw() ------ *Redraws a widget and its children* **Description:** Redraws the screen or a specific widget. **Usage:** .. code-block:: pebl Draw() Draw() **See Also:** :func:`DrawFor()`, :func:`Show()`, :func:`Hide()` .. index:: DrawFor DrawFor() --------- **Description:** Draws a screen or widget, returning after ```` refreshes. This function currently does not work as intended in the SDL implementation, because of a lack of control over the refresh blank. It may work in the future. **Usage:** .. code-block:: pebl DrawFor( , ) **See Also:** :func:`Draw()`, :func:`Show()`, :func:`Hide()` .. index:: Ellipse Ellipse() --------- *Creates ellipse with radii rx and ry centered at position x,y* **Description:** Creates a ellipse for graphing at x,y with radii rx and ry. Ellipses are only currently definable oriented in horizontal/vertical directions. Ellipses must be added to a parent widget before it can be drawn; it may be added to widgets other than a base window. The properties of ellipses may be changed by accessing their properties directly, including the FILLED property which makes the object an outline versus a filled shape. **Usage:** .. code-block:: pebl Ellipse(, , , ,) **Example:** .. code-block:: pebl e <- Ellipse(30,30,20,10, MakeColor(green)) AddObject(e, win) Draw() **See Also:** :func:`Square()`, :func:`Circle()`, :func:`Rectangle()`, :func:`Line()` .. index:: GetCursorPosition GetCursorPosition() ------------------- **Description:** Returns an integer specifying where in a textbox the edit cursor is. The value indicates which character it is on. **Usage:** .. code-block:: pebl GetCursorPosition() **See Also:** :func:`SetCursorPosition()`, :func:`MakeTextBox()`, :func:`SetText()` .. index:: GetLineBreaks GetLineBreaks() --------------- **Description:** This gets linebreaks for a textbox. It is mainly used internally for text rendering/layout, but could be useful in other contexts. **Example:** .. code-block:: pebl gWin <- MakeWindow() obj <- EasyTextbox("test a b c d e f g h i j k l m n o p q r s t u v",30,30,gWin,22, 40,200) breaks <- GetLineBreaks(obj) Print("Number of lines:" + Length(breaks)) .. index:: GetParent GetParent() ----------- **Description:** This gets parent of a widget. **Example:** .. code-block:: pebl gWin <- MakeWindow() obj <- EasyLabel("test",30,30,gWin,22) ## later win <- GetParent(obj) ##should be gWin .. index:: GetPixelColor GetPixelColor() --------------- *Gets the color of a specified pixel on a widget* **Description:** Gets a color object specifying the color of a particular pixel on a widget. **Usage:** .. code-block:: pebl color <- GetPixelColor(widget,x,y) **Example:** .. code-block:: pebl ##Judge brightness of a pixel img <- MakeImage("test.png") col <- GetPixelColor(img,20,20) hsv <- RGBtoHSV(col) Print(Third(hsv)) **See Also:** :func:`SetPixel()` .. index:: GetProperty GetProperty() ------------- *Returns value of property* **Description:** Gets a particular named property of an object. This works for custom or built-in objects. If the property does not exist, a fatal error will be signaled, and so you should check using PropertyExists() if there is any chance the property does not exist. **Example:** .. code-block:: pebl obj <- MakeCustomObject("myobject") obj.taste <- "buttery" obj.texture <- "creamy" SetProperty(obj,"flavor","tasty") list <- GetPropertyList(obj) loop(i,list) { if(PropertyExists(obj,i) { Print(i + ": " + GetProperty(obj,i)) } } **See Also:** :func:`GetPropertyList()`, :func:`PropertyExists()`, :func:`SetProperty()`, :func:`MakeCustomObject()`, :func:`PrintProperties()` .. index:: GetPropertyList GetPropertyList() ----------------- *Gets a list of all the property names of an object* **Description:** Gets a list of all of the properties an object has. This works for custom or built-in objects. **Example:** .. code-block:: pebl obj <- MakeCustomObject("myobject") obj.taste <- "buttery" obj.texture <- "creamy" SetProperty(obj,"flavor","tasty") list <- GetPropertyList(obj) loop(i,list) { if(PropertyExists(obj,i) { Print(i + ": " + GetProperty(obj,i)) } } **See Also:** :func:`GetProperty`, :func:`PropertyExists`, :func:`SetProperty` :func:`MakeCustomObject`, :func:`PrintProperties` .. index:: GetSize GetSize() --------- **Description:** Returns a list of ``[height, width]``, specifying the size of the widget. The .width and .height properties can also be used instead of this function **Usage:** .. code-block:: pebl GetSize() **Example:** .. code-block:: pebl image <- MakeImage("stim1.bmp") xy <- GetSize(image) x <- Nth(xy, 1) y <- Nth(xy, 2) .. index:: GetText GetText() --------- *Returns the text in a textbox or label* **Description:** Returns the text stored in a text object (either a textbox or a label). The .text properties can also be used instead of this function. **Usage:** .. code-block:: pebl GetText() **See Also:** :func:`SetCursorPosition()`, :func:`GetCursorPosition()`, :func:`SetEditable()`, :func:`MakeTextBox()` .. index:: GetVocalResponseTime GetVocalResponseTime() ---------------------- *A simple voice key* **Description:** This is a simple audio amplitude voice key controlled by two parameters *ONLY AVAILABLE ON WINDOWS AND LINUX*. **Usage:** .. code-block:: pebl GetVocalResponseTime(buffer, timethreshold, energythreshold) **Example:** .. code-block:: pebl buffer <- MakeAudioInputBuffer(5000) resp0 <- GetVocalResponseTime(buffer,.35, 200) SaveAudioToWaveFile("output.wav",buffer) **See Also:** :func:`MakeAudioInputBuffer()`, :func:`SaveAudioToWaveFile()`, .. index:: Hide Hide() ------ *Hides an object* **Description:** Makes an object invisible, so it will not be drawn. **Usage:** .. code-block:: pebl Hide() **Example:** .. code-block:: pebl window <- MakeWindow() image1 <- MakeImage("pebl.bmp") image2 <- MakeImage("pebl.bmp") AddObject(image1, window) AddObject(image2, window) Hide(image1) Hide(image2) Draw() # empty screen will be drawn. Wait(3000) Show(image2) Draw() # image2 will appear. Hide(image2) Draw() # image2 will disappear. Wait(1000) Show(image1) Draw() # image1 will appear. **See Also:** :func:`Show()` .. index:: Line Line() ------ *Creates line starting at x,y and ending at x+dx, y+dy* **Description:** Creates a line for graphing at x,y ending at x+dx, y+dy. dx and dy describe the size of the line. Lines must be added to a parent widget before it can be drawn; it may be added to widgets other than a base window. Properties of lines may be accessed and set later. **Usage:** .. code-block:: pebl Line(, , , , ) **Example:** .. code-block:: pebl l <- Line(30,30,20,20, MakeColor("green") AddObject(l, win) Draw() **See Also:** :func:`Square()`, :func:`Ellipse()`, :func:`Rectangle()`, :func:`Circle()` .. index:: LoadAudioFile LoadAudioFile() --------------- *Load an audio file* **Description:** Loads an audio file supported by the ffmpeg library. It is nearly identical to LoadMovie(), but only works for audio files (.ogg, .mp3, .wav, .aiff, .wma, et.). It creates a movie object, which can then be played using PlayMovie() or StartPlayback() functions. Currently, only supported on Windows and Linux. The ffmpeg (``http://ffmpeg.org``) library supports a wide range of audio formats, including most .wav, .mp3, .ogg, .flac, .aiff, .wma, and others. Currently, there appears to sometimes be playback problems if the audio stream is not stereo, so be sure to convert your audio to stereo. Also, there appears to be some problems with .flac data formats. If you have problems with playback, you should verify that your media file loads with another ffmpeg media player. **Usage:** .. code-block:: pebl LoadAudioFile(audiofile) **Example:** .. code-block:: pebl movie <- LoadAudioFile("instuctions.mp3") PrintProperties(inst) PlayMovie(inst) PausePlayback(insnt) **See Also:** :func:`LoadMovie()`, :func:`PlayMovie()`, :func:`StartPlayback()`, :func:`PausePlayback()` .. index:: LoadMovie LoadMovie() ----------- *Load a movie file* **Description:** DOES NOT WORK IN PEBL 2.0+ Loads a movie file using the ffmpeg library. It creates a movie object, which can then be played using PlayMovie() or StartPlayback() functions. Currently, only supported on Windows and Linux. The ffmpeg (``http://ffmpeg.org``) library supports a wide range of video and audio formats, including most .mpg, .avi, .ogg and .mp3 type formats. Audio-only formats should load and play with LoadMovie, but another function, LoadAudioFile(), has been created for these, as they do not need to be added to a window to work. If you have problems with playback, you should verify that your media file loads with another ffmpeg media player. For technical reasons, a movie MUST be loaded directly onto a window, and not another widget. **Usage:** .. code-block:: pebl LoadMovie(movie,window, width, height) **Example:** .. code-block:: pebl movie <- LoadMovie("movie.avi",gWin,640,480) PrintProperties(movie) Move(movie,20,20) Draw() StartPlayback(movie) Wait(500) #Play 500 ms of the movie. PausePlayback(movie) **See Also:** :func:`LoadAudioFile()`, :func:`LoadMovie()`, :func:`PlayMovie()`, :func:`StartPlayback()`, :func:`PausePlayback()` .. index:: LoadSound LoadSound() ----------- *Loads a soundfile from the filename, returning a variable that can be played* **Description:** Loads a soundfile from ````, returning a variable that can be played using the PlayForeground or PlayBackground functions. ``LoadSound`` As of PEBL version 2.1, LoadSound will load raw and compressed audio files of various sorts. This includes uncompressed .wav files, .mp3, .ogg, .flac, and .midi files. This is based on the sdl2\_mixer library, and so more details about the file formats accepted can be found by examining that library. Examples of using LoadSound are found in ``demo tests testaudio.pbl`` When the file gets loaded, it gets automatically transcoded into a stereo 44100-sampling rate audio stream, regardless of its original playback rate. We have reports that in some cases, this can cause some problems, especially if a mono file gets loaded multiple times in an experiment. If you experience playback problems, try converting your audio to stereo 44100 hz and see if it helps. **Usage:** .. code-block:: pebl LoadSound() **Example:** .. code-block:: pebl woof <- LoadSound("dog.wav") PlayBackground(woof) Wait(200) Stop(woof) PlayForeground(woof) **See Also:** :func:`PlayForeground`, :func:`PlayBackground`, :func:`LoadAudioFile`, :func:`LoadMovie` .. index:: MakeAudioInputBuffer MakeAudioInputBuffer() ---------------------- *Creates a buffer to record audio input* **Description:** Creates a sound buffer to use for audio recording or voicekey sound input. It is currently very simple, allowing only to set the duration. By default, it record mono at 44100 hz. **Usage:** .. code-block:: pebl MakeAudioInputBuffer() **Example:** .. code-block:: pebl buffer <- MakeAudioInputBuffer(5000) resp0 <- GetVocalResponseTime(buffer,.35, 200) SaveAudioToWaveFile("output.wav",buffer) **See Also:** :func:`GetVocalResponseTime()`, :func:`SaveAudioToWaveFile()`, .. index:: MakeCanvas MakeCanvas() ------------ *Creates a blank canvas* **Description:** Makes a canvas object ```` pixels by ``y`` pixels, in color ````. A canvas is an object that other objects can be attached to, and imprinted upon. When the canvas gets moved, the attached objects move as well. The background of a canvas can be made invisible by using a color with alpha channel == 0. The Setpixel and SetPoint functions let you change individual pixels on a canvas, to enable adding noise, drawing functional images, etc. A canvas gets 'cleared' by calling ResetCanvas(canvas). Any object added to a canvas creates an 'imprint' on the canvas that remains if the object is moved. This allows you to use another image as a paintbrush on the canvas, and lets you to add noise to text. Because a text label gets re-rendered when its drawn, if you want to add pixel noise to a stimulus, you can create a label, add it to a canvas, then add pixel noise to the canvas. **Usage:** .. code-block:: pebl MakeCanvas(, , ) **Example:** .. code-block:: pebl gWin <- MakeWindow() clear <- MakeColor("white") clear.alpha <- 0 #make a transparent canvas: x <- MakeCanvas(300,300,clear) AddObject(x,gWin) Move(x,300,300) img <- MakeImage("pebl.png") AddObject(img,x) Move(img,100,100) Draw(x) #imprint the image on the canvas Move(img,100,200) Draw(x) #imprint the image on the canvas Hide(img) #draw a line on the canvas i <- 10 red <- MakeColor("red") while(i < 200) { SetPixel(x,20,i,red) i <- i + 1 } Draw() WaitForAnyKeyPress() **See Also:** :func:`MakeImage()`, :func:`SetPixel()`, :func:`MakeGabor()`, :func:`ResetCanvas()` .. index:: MakeColor MakeColor() ----------- *Creates a color based on a color name* **Description:** Makes a color from ```` such as ``red'', ``green'', and nearly 800 others. Color names and corresponding RGB values can be found in ``doc/colors.txt``. **Usage:** .. code-block:: pebl MakeColor() **Example:** .. code-block:: pebl green <- MakeColor("green") black <- MakeColor("black") **See Also:** :func:`MakeColorRGB()`, :func:`RGBtoHSV()` .. index:: MakeColorRGB MakeColorRGB() -------------- *Creates a color based on red, green, and blue values* **Description:** Makes an RGB color by specifying ````, ````, and ```` values (between 0 and 255). **Usage:** .. code-block:: pebl MakeColorRGB(, , ) **See Also:** :func:`MakeColor()`, :func:`RGBtoHSV()` .. index:: MakeCustomObject MakeCustomObject() ------------------ *Creates custom object.* **Description:** Creates a 'custom' object that can encapsulate multiple properties. It takes a name as an argument, but this is currently not accessible. **Example:** .. code-block:: pebl obj <- MakeCustomObject("myobject") obj.taste <- "buttery" obj.texture <- "creamy" SetProperty(obj,"flavor","tasty") list <- GetPropertyList(obj) loop(i,list) { if(PropertyExists(obj,i) { Print(i + ": " + GetProperty(obj,i)) } } **See Also:** :func:`GetPropertyList()`, :func:`PropertyExists()`, :func:`SetProperty()`, :func:`IsCustomObject()`, :func:`PrintProperties()`, :func:`GetProperty()` .. index:: MakeFont MakeFont() ---------- *Creates a font which can be used to make labels* **Description:** Makes a font. The first argument must be a text name of a font. The font can reside anywhere in PEBL's search path, which would primarily include the media/fonts directory, and the working directory (where the script is saved). - style changes from normal to bold/underline, italic. 0=normal, 1=underline, 2=italic,3=bolditalic - fgcolor and bgcolor need to be colors, not just names of colors - if show-backing is 0, the font gets rendered with an invisible - background; otherwise with a bgcolor background. (Note: previous to PEBL 0.11, the final argument = 0 rendered the font with non anti-aliased background, which I can see almost no use for.) **Usage:** .. code-block:: pebl MakeFont(,