bewerking=bewerking1.proc
PLAATJE=1
n=$teller
!if $graad=0
    R=$teller
!else
    R=$graad
!endif
percentage=1
HLINE=$empty
VLINE=$empty
LINES=$empty
FILL=$empty

!if $taal=nl
    nivo_title=Hoeveel procent van het oppervlak is gekleurd?<br>Tellen en uitrekenen	
    !if $HINT=1
	hint=eerst het totale oppervlak uitrekenen<br>\
	Stel het plaatje is 5 hokjes breed en 6 hokjes hoog<br>\
	In't totaal zijn er dan dus 5 &times; 6 = 30 hokjes.<br>\
	Stel we tellen 9 blauwe hokjes<br>\
	Het percentage blauw is dan dus: 100% &times; 9 &divide; 30 = 100% &times; 0.3 = 30%<br>\
	Snap je , $voornaam ?	
    !endif
    COLORS=red,green,blue,orange,yellow,purple,pink,lightgreen,cyan,grey,maroon
    KLEUREN=rood,groen,blauw,oranje,geel,paars,roze,lichtgroen,helderblauw,grijs,bruin
!else
    nivo_title=What percentage of the surface is colored <br>Count and calculate	
    !if $HINT=1
	hint=First You should calculate the total area<br>\
	Suppose the surface is 5 boxes wide and 6 boxes high<br>\
	In total the surface is  5 &times; 6 = 30 boxes.<br>\
	Let's say we can count 9 blue boxes<br>\
	the percentage blue surface then will be: 100% &times; 9 &divide; 30 = 100% &times; 0.3 = 30%<br>\
	Get it , $voornaam ?
    !endif
    COLORS=red,green,blue,orange,yellow,purple,pink,lightgreen,cyan,grey,maroon
    KLEUREN=red,green,blue,orange,yellow,purple,pink,lightgreen,cyan,grey,brown
!endif

aantal_kleuren=!itemcnt $COLORS
k=!randint 1,$[$aantal_kleuren-1]
good_color=!item $k of $COLORS
goede_kleur=!item $k of $KLEUREN
    
!if $R=1
    breedte = !randitem 3,4
    hoogte= !randitem   2,3
    !for q=0 to $hoogte
	HLINE=!append line hline 0,$q,black to $HLINE
    !next
    !for p=0 to $breedte
	VLINE=!append line vline $p,0,black to $VLINE
    !next    

    Y=!randint 0,$hoogte 
    totaal=0
    LINES=0,$Y
    !for p=1 to $breedte
	pm=!randitem +1,-1,+0
	!if $pm=+1
	    totaal = $[$totaal + 0.5]
	!endif
	!if $pm=-1
	    totaal = $[$totaal - 0.5]
	    !if $p=1
		FILL=!append line filltoborder 0.1,$[$Y-0.25],black,$good_color to $FILL 
	    !endif
	!endif
	totaal=$[$totaal+$Y]
	Y=$[$Y $pm ]	
	!if $Y>$hoogte
	    Y=$[$hoogte -1]
	    totaal = $[$totaal - 1]
	!endif
	!if $Y<0
	    Y=0
	    totaal = $[$totaal + 0.5]
	!endif    

	LINES=!append item $p,$Y to $LINES   
	FILL=!append line filltoborder $p,$[$Y-0.25],black,$good_color to $FILL 
    !next p
	FILL=!append line filltoborder $[$breedte-0.1],$[$Y-0.25],black,$good_color to $FILL 
    decimaal=decimaal
    afrondingsfactor=$[10^$R]
    GOED$n=$[100*$totaal/($breedte*$hoogte)]    
    goed$n=$[(round($afrondingsfactor*$(GOED$n)))/$afrondingsfactor]
!endif


!if $R>1
    decimaal=decimalen
    breedte = !randitem 3,4,5,6,7,8,9,10
    hoogte= !randitem   4,5,6,7,8,9,10
    !for q=0 to $hoogte
	HLINE=!append line hline 0,$q,black to $HLINE
    !next
    !for p=0 to $breedte
	VLINE=!append line vline $p,0,black to $VLINE
    !next    

    Y=!randint 0,$hoogte 
    totaal=0
    LINES=0,$Y
    !for p=1 to $breedte
	pm=!randitem +1,-1,+0
	!if $pm=+1
	    totaal = $[$totaal + 0.5]
	!endif
	!if $pm=-1
	    totaal = $[$totaal - 0.5]
	    !if $p=1
		FILL=!append line filltoborder 0.1,$[$Y-0.25],black,$good_color to $FILL 
	    !endif
	!endif
	totaal=$[$totaal+$Y]
	Y=$[$Y $pm ]	
	!if $Y>$hoogte
	    Y=$[$hoogte -1]
	    totaal = $[$totaal - 1]
	!endif
	!if $Y<0
	    Y=0
	    totaal = $[$totaal + 0.5]
	!endif    

	LINES=!append item $p,$Y to $LINES   
	FILL=!append line filltoborder $p,$[$Y-0.25],black,$good_color to $FILL 
    !next p
	FILL=!append line filltoborder $[$breedte-0.1],$[$Y-0.25],black,$good_color to $FILL 
    
    afrondingsfactor=$[10^$R]
    GOED$n=$[100*$totaal/($breedte*$hoogte)]    
    goed$n=$[(round($afrondingsfactor*$(GOED$n)))/$afrondingsfactor]
!endif

	
plaatje$n=400,400\
xrange 0,$breedte\
yrange 0,$hoogte\
linewidth 4\
lines black,$LINES\
linewidth 4\
rect 0,0,$breedte,$hoogte,black\
$FILL\
linewidth 1\
$VLINE\
$HLINE
    
!if $taal=nl
    somtekst$n=<font size=+1>$voornaam, bekijk het volgende plaatje. Bereken hoeveel procent van het plaatje $goede_kleur gekleurd is.</font>
    opgave$n=<font size=+1>$voornaam. Hoeveel procent van het plaatje is $goede_kleur.<br>\
    Of anders gezegd: hoeveel procent is het oppervlak onder de dikke zwarte lijn.<br><small>\
    Bij gebroken getallen, geef je antwoord op tenminste $R $decimaal</b> nauwkeurig...</small><br>
    
    antwoord$n=Er waren $totaal $goede_kleur gekleurde vierkantjes in het plaatje.<br>\
    in het totaal waren er: hoogte &times; breedte = $hoogte &times; $breedte = $[$hoogte*$breedte] vierkantjes<br>\
    Dus het percentage $goede_kleur is 100 &times; $totaal/$[$hoogte*$breedte] = $(GOED$n) %<br>\
    en afgerond is dit dus $(goed$n) %
!else
    somtekst$n=<font size=+1>$voornaam, calculate the percentage of the $goede_kleur colored surface.</font>
    opgave$n=<font size=+1>$voornaam. calculate the percentage of the $goede_kleur colored surface.<br>\
    Or: calculate the percentage under the thick black line <br>\
    <small>If the answer is a broken number, give your aswer in at least $R decimal(s)</b> accurate...</small><br>
    
    antwoord$n=The are $totaal $goede_kleur colored "squares" in the image.<br>\
    The total surface is; height &times; length = $hoogte &times; $breedte = $[$hoogte*$breedte] squares<br>\
    Thus the percentage $goede_kleur is 100 &times; $totaal/$[$hoogte*$breedte] = $(GOED$n) %<br>\
    or -rounded off- $(goed$n) %
!endif
