bewerking=bewerking3.proc
!if $taal=nl
    nivo_title=Bepaal de co&ouml;rdinaten van het eerste maximum en minimum.
    evenwicht=eventwichts lijn
    xas=x-as
    yas=y-as
!else
    nivo_title=determine the co&ouml;rdinates of the first maximum and minimum.
    evenwicht="balance" line
    xas=x-axis
    yas=y-axis    
!endif
letter=!randitem f,g,h,k,m

a=!randitem 1/2,1,3/2,2,5/2,3,-1/2,-1,-3/2,-2,-5/2,-3
b=!randitem 1/2,1,3/2,2,5/2,3
c=!randitem 1/3,1/2,1,3/2,2,5/2,7/2,9/2,1/8,1/4,1/3,1/2,1,3/2,2,5/2,1/9,1/10,3/10,2/9
e=$[1/($c)]
d=!randint 0,$e 

SIN=!randitem sin,cos
mp=!randitem +,-

!if $graad=1
    !if $SIN=sin and $mp=+
	MAX1=P/(2*$c)
	MAX2=$a+$b
	MIN1=3*P/(2*$c)
	MIN2=$a-$b
    !else
	!if $SIN=sin and $mp=-
	    MAX1=3*P/(2*$c)
	    MAX2=$a+$b
	    MIN1=P/(2*$c)
	    MIN2=$a-$b
	!else
	    !if $SIN=cos and $mp=+
		MAX1=0
		MAX2=$a+$b
		MIN1=P/($c)
		MIN2=$a-$b
	    !else
		!if $SIN=cos and $mp=-
		    MAX1=P/($c)
		    MAX2=$a+$b
		    MIN1=0
		    MIN2=$a-$b
		!endif
	    !endif
	!endif
    !endif
    	    
    TUSSEN=!exec pari  $MAX1 \
    $MAX2 \
    $MIN1 \
    $MIN2 
    
    X1=!line 1 of $TUSSEN
    Y1=!line 2 of $TUSSEN
    X2=!line 3 of $TUSSEN
    Y2=!line 4 of $TUSSEN

    X1=!replace internal P by pi in $X1   
    Y1=!replace internal P by pi in $Y1    
    X2=!replace internal P by pi in $X2    
    Y2=!replace internal P by pi in $Y2    
    
    GOED$n=$X1,$Y1,$X2,$Y2
    f$n=$a $mp $b*$SIN($c*x)
    goed$n= ($X1:$Y1) &and;  ($X2:$Y2)
    functie$n=!texmath $letter(x) = $(f$n)
!endif

!if $graad=2
    !if $d=0
	f$n=$a $mp $b*$SIN($c*x)
    !else
	f$n=$a $mp $b*$SIN($c*x - $d)
    !endif
    !if $SIN=sin and $mp=+
	MAX1=(4*($d)+2*P)/(4*($c))
	MAX2=($a)+($b)
	MIN1=(4*($d)+6*P)/(4*($c))
	MIN2=($a)-($b)
    !else
	!if $SIN=sin and $mp=-
	    MAX1=(4*($d)+6*P)/(4*($c))
	    MAX2=($a)+($b)
	    MIN1=(4*($d)+2*P)/(4*($c))
	    MIN2=($a)-($b)
	!else
	    !if $SIN=cos and $mp=+
    		MAX1=($d)/($c)
		MAX2=($a)+($b)
    		MIN1=(($d)+P)/($c)
		MIN2=($a)-($b)
	    !else
		!if $SIN=cos and $mp=-
		    MAX1=(($d)+P)/($c)
		    MAX2=($a)+($b)
		    MIN1=($d)/($c)
		    MIN2=($a)-($b)
		!endif
	    !endif
	!endif
    !endif	    

    TUSSEN=!exec pari  $MAX1\
    $MAX2 \
    $MIN1 \
    $MIN2 
    
    X1=!line 1 of $TUSSEN
    Y1=!line 2 of $TUSSEN
    X2=!line 3 of $TUSSEN
    Y2=!line 4 of $TUSSEN
    X1=!replace internal P by pi in $X1    
    Y1=!replace internal P by pi in $Y1    
    X2=!replace internal P by pi in $X2    
    Y2=!replace internal P by pi in $Y2    

    goed$n= ($X1:$Y1) &and;  ($X2:$Y2)
    functie$n=!texmath $letter(x) = $(f$n)
    GOED$n=$X1,$Y1,$X2,$Y2
    ##x_min=min1
    ##y_min=min2
    ##x_max=max1
    ##y_max=max2
!endif

insdraw_animate=yes
ins_anim_frames=2
ins_anim_delay=0.8
ins_anim_loop=0

plaatje=300,400\
transparent white\
xrange -1,$[6*pi/($c)]\
yrange -6,6\
linewidth 2\
vline 0,0,blue\
hline 0,0,blue\
linewidth 2\
curve red,$(f$n)\
linewidth s*24\
point $X1,$Y1,lightgreen\
point $X2,$Y2,lightgreen\
linewidth 6\
point $X1,$Y1,darkgreen\
point $X2,$Y2,darkgreen\
textup black,0,4,normal,$yas\
text black,$[3*pi/($c)],0,normal,$xas

helpplaatje$n=$plaatje

plaatje$n=$plaatje\
linewidth 1\
dvline pi,0,green\
dvline 2*pi,0,green\
dvline 3*pi,0,green\
dvline 4*pi,0,green\
dvline 6*pi,0,green\
dvline 8*pi,0,green\
dvline 10*pi,0,green\
dvline 12*pi,0,green\
dvline 14*pi,0,green\
hline 0,-6,green\
hline 0,-5,green\
hline 0,-4,green\
hline 0,-3,green\
hline 0,-2,green\
hline 0,-1,green\
hline 0,1,green\
hline 0,2,green\
hline 0,3,green\
hline 0,4,green\
hline 0,5,green\
hline 0,6,green\
linewidth 2\
hline 0,$a,orange\
text orange,0,$a-0.1,normal,$evenwicht\
text blue,pi,-0.2,normal,pi\
text blue,2*pi,-0.2,normal,2pi\
text blue,3*pi,-0.2,normal,3pi\
text blue,4*pi,-0.2,normal,4pi\
text blue,6*pi,-0.2,normal,6pi\
text blue,8*pi,-0.2,normal,8pi\
text blue,10*pi,-0.2,normal,10pi\
text blue,12*pi,-0.2,normal,12pi\
text blue,14*pi,-0.2,normal,14pi\
text blue,0,1,normal,1\
text blue,0,-1,normal,-1
