increasing/decreasing percentage - pie chart/ circular graph
David McFarlane
mcfarla9 at msu.edu
Wed May 5 14:13:56 UTC 2010
Sorry, couldn't quite let that pair of exhaustive-and-mutually-exclusive
If...Thens stand (and while at it also added a couple comments, and used
line continuation characters to break long lines):
If mySlide.resp = 2 then ' increase pie slice
If c.GetAttrib("CurrentPerc") < 100 then _
c.SetAttrib("CurrentPerc"), c.GetAttrib("CurrentPerc") + 1
c.SetAttrib("myPicture"), "pie" & cstr(c.GetAttrib("CurrentPerc")) _
& ".bmp"
goto Label1
ElseIf mySlide.resp = 1 then ' decrease pie slice
If c.GetAttrib("CurrentPerc") > 1 then c.SetAttrib("CurrentPerc"), _
c.GetAttrib("CurrentPerc") - 1
c.SetAttrib("myPicture"), "pie" & cstr(c.GetAttrib("CurrentPerc")) _
& ".bmp"
goto Label1
End If
Might also use a variable instead of an attribute reference for
CurrentPerc, thus,
Dim currentPerc
If mySlide.resp = 2 then ' increase pie slice
If (currentPerc < 100) then currentPerc = currentPerc + 1
c.SetAttrib("myPicture"), "pie" & cstr(currentPerc) & ".bmp"
goto Label1
ElseIf mySlide.resp = 1 then ' decrease pie slice
If (currentPerc > 1) then currentPerc = currentPerc - 1
c.SetAttrib("myPicture"), "pie" & cstr(currentPerc) & ".bmp"
goto Label1
End If
And to complete the exercise, let's use Select...Case:
Dim currentPerc
Select Case mySlide.RESP
Case 2 ' increase pie slice
If (currentPerc < 100) then currentPerc = currentPerc + 1
c.SetAttrib("myPicture"), "pie" & cstr(currentPerc) & ".bmp"
goto Label1
Case 1 ' decrease pie slice
If (currentPerc > 1) then currentPerc = currentPerc - 1
c.SetAttrib("myPicture"), "pie" & cstr(currentPerc) & ".bmp"
goto Label1
End Select
-- David McFarlane, Professional Faultfinder
On 5 May 2010 Michiel Spape wrote:
> Hi,
> A) You could, of course, just do away with almost all of the inline code, make some nice graphics yourself and just making a little procedure with a slide and a loop. Just name your 100 pictures of pies to be something like pie50.bmp (for 50%). Have a slide (mySlide, with, importantly, a reference to attribute [myPicture]), a little label before that (Label1), a single inline after that:
>
> If mySlide.resp = 2 then
> If c.GetAttrib("CurrentPerc") < 100 then c.SetAttrib("CurrentPerc"), c.GetAttrib("CurrentPerc") + 1
> c.SetAttrib("myPicture"), "pie" & cstr(c.GetAttrib("CurrentPerc")) & ".bmp"
> goto Label1
> end if
> If mySlide.resp = 1 then
> If c.GetAttrib("CurrentPerc") > 1 then c.SetAttrib("CurrentPerc"), c.GetAttrib("CurrentPerc") - 1
> c.SetAttrib("myPicture"), "pie" & cstr(c.GetAttrib("CurrentPerc")) & ".bmp"
> goto Label1
> end if
>
> Should work. Any response other than 1 or 2 is taken as final answer.
>
> B) If you insist on using loads of canvas, my advice is to do something similar to the above - i.e. check for a response (for instance, just use a little, blank textdisplay with duration 0 and timelimit infinite), or even continually check for a response, loop, &c.
>
> Best,
> Mich
>
>
> Michiel Spapé
> Research Fellow
> Perception & Action group
> University of Nottingham
> School of Psychology
>
> -----Original Message-----
> From: e-prime at googlegroups.com [mailto:e-prime at googlegroups.com] On Behalf Of Matt Paffel
> Sent: 04 May 2010 20:14
> To: E-Prime
> Subject: increasing/decreasing percentage - pie chart/ circular graph
>
> Hello,
>
> I'm trying to develop a behavioral choice task in which a participant
> will be able to increase or decrease a percentage of pie dependent
> upon the contingency of the experiment. I've attached the code that I
> was planning on using, which I took from the e-basic help file. There
> are a couple of lines that I plan on removing from the script such as
> the lines referencing "random" and "nCount". However, overall this is
> aesthetically what I want the program to look like. My question is; I
> want the participant to be able to increase and decrease the
> percentage of pie using the 1 and 2 keys. I'm having trouble finding
> lines of script, or references pertaining to, what I'd like to achieve
> within the design. Does anyone have any suggestions?
>
> 'Create a Canvas
> Dim cnvs As Canvas
> 'Set cnvs as the current, onscreen canvas
> Set cnvs = Display.Canvas
> 'Declare variables used to set the size of the canvas
> Dim XRes As Integer, YRes As Integer
> 'Set the canvas size as the entire screen resolution
> XRes = Display.XRes
> YRes = Display.YRes
>
> 'Declare and initialize variables to be used when drawing the sections
> of the circle
> Const nRadius As Integer = 100
> Dim nStartAngle As Integer, nEndAngle As Integer
> Dim nCount As Integer
>
> 'Initialize variables
> nStartAngle = 90
> nEndAngle = 90
>
> 'Declare variables to be used to randomly select the delay value
> Dim nRandom As Integer
> Dim nDelay As Integer
> 'Select a random number to determine the value of the delay between
> the drawing of each section of the circle
> nRandom = Random (1, 2)
> 'If the random number chosen is 1, the nDelay value is set to 500 ms.
> 'Otherwise, the nDelay value is set to 1000 ms.
> If nRandom = 1 Then
> nDelay = 500
> Else
> nDelay = 1000
> End If
>
> 'Set color of pen for pie slice
> cnvs.PenColor = CColor("red")
> cnvs.FillColor = CColor("red")
> 'The For...Next statement repeats a block of statements a specified
> number of times
> 'incrementing a loop counter by a given increment each time through
> the loop
> 'In this sample, the nCount variable is incremented by one each time
> through the loop allowing ten pie slices to be drawn.
>
> For nCount = 1 to 10
>
>
>
> 'Adjust startAngle to specify where to start each section of the
> circle each time a pie slice is drawn
> nStartAngle = nStartAngle - 36
> 'Draw a pie slice with center point at x, y and radius r, starting at
> startAngle and drawing to endAngle.
> cnvs.Pie XRes/2, YRes/2, nRadius, nStartAngle, nEndAngle
> 'Sleep before drawing next pie slice
> Sleep nDelay
> Next nCount
> 'Set fill color to white before clearing canvas
> cnvs.FillColor = CColor("white")
> 'Clear canvas
> cnvs.clear
> 'Set the value of the delay as an attribute in the data file
>
> Thank you.
--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.
More information about the Eprime
mailing list