# dynamic generation of  obj-files
# filewriting required
!if jm.evers notin $wims_site_manager
    !exit
!endif
    
bewerking=bewerking7.proc
n=$teller
!if $graad=0
    R=$teller
!else
    R=$graad
!endif        
kubus=$empty
woordmax=10
varcnt=0
ATOMS=N,S,O,N,S,O,N,S,O,N,S,O
DINGEN=blauwe@N,gele@S,roodachtige@O  
DING=!randitem $DINGEN
DING=!replace internal @ by , in $DING
KLEUR=!item 1 of $DING
GOEDE_ATOM=!item 2 of $DING
objecten=!randitem balletjes,knikkers,kogels,ruimte knikkers,atomen
TOTAAL=0
hit=0
!if $R=1    
    a=0
    b=0
    c=0
    U=!randitem 5,6,7,8
    V=!randitem 5,6,7
    W=!randitem 5,6,7
    !for u=1 to $U
	!for v=1 to $V	
	    ATOM=!randitem $ATOMS
	    !for w=1 to $W
		!if $ATOM=$GOEDE_ATOM
		    !increase hit
		!endif
		kubus=!append line $ATOM $a $b $c to $kubus
		!increase a
		!increase TOTAAL
	    !next w
	    a=0
	    !increase b
	!next v
	    b=0
	    !increase c
    !next u
    !filewrite tmp/object.$wims_session.$n  $kubus
!endif

!if $R=2
    a=0
    b=0
    c=0
    U=!randitem 3,4,4,5,4,4,3,2
    V=!randitem 2,2,3,3,3,4,4,4,5,5,5,5,6
    W=!randitem 3,4,3,4,3,5,5,5,5,6
    ATOM1=C
    ATOM2=S
    ATOM3=X
    ATOM4=P
    !for u=1 to $U
	!for v=1 to $V
    	    !for w=1 to $W
		ATOM=!item $w of $ATOMS
		!if $ATOM=$GOEDE_ATOM
		    hit=$[$hit+4]
		!endif
	
		kubus=!append line $ATOM $a $b $c to $kubus
		kubus=!append line $ATOM $a $[$b+10] $c to $kubus
		kubus=!append line $ATOM $a $b $[$c+10] to $kubus
		kubus=!append line $ATOM $a $[$b+10] $[$c+10] to $kubus
		!increase a
		TOTAAL=$[$TOTAAL + 4]
	    !next w
	    a=0
	    !increase b
	!next v
	    b=0
	    !increase c
    !next u
    !filewrite tmp/object.$wims_session.$n  $kubus
!endif
!if $R=3
    a=0
    b=0
    c=0
    U=!randitem 3,4,5
    V=!randitem 2,3,4
    W=!randitem 2,3,4
    
    !for u=1 to $U
	!for v=1 to $V
	    !for w=1 to $W
		ATOM=!randitem $ATOMS
		!if $ATOM=$GOEDE_ATOM
		    hit=$[$hit+4]
		!endif
		kubus=!append line $ATOM $a $b $c to $kubus
		kubus=!append line $ATOM $a $[$b+10] $c to $kubus
		kubus=!append line $ATOM $a $b $[$c+10] to $kubus
		kubus=!append line $ATOM $a $[$b+10] $[$c+10] to $kubus
		a=$[$a+10]
		TOTAAL=$[$TOTAAL + 4]
	    !next w
		a=0
		b=$[$b+10]
	!next v
		a=0
		b=0
		c=$[$c+10]
    !next u
    !filewrite tmp/object.$wims_session.$n  $kubus
!endif
!if $R=4
    a=0
    b=0
    c=0
    U=!randitem 2,3,4
    V=!randitem 2,3,4
    W=!randitem 2,3,4
    !for u=1 to $U
	!for v=1 to $V
	    !for w=1 to $W
		ATOM=!randitem $ATOMS 
		!if $ATOM=$GOEDE_ATOM
		    hit=$[$hit + 8]
		!endif
		kubus=!append line $ATOM $a $b $c to $kubus
		kubus=!append line $ATOM $a $[$b+2] $c to $kubus
		kubus=!append line $ATOM $a $b $[$c+2] to $kubus
		kubus=!append line $ATOM $a $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM $[$a+2] $b $c to $kubus
		kubus=!append line $ATOM $[$a+2] $[$b+2] $c to $kubus
		kubus=!append line $ATOM $[$a+2] $b $[$c+2] to $kubus
		kubus=!append line $ATOM $[$a+2] $[$b+2] $[$c+2] to $kubus
		a=$[$a+12]
		TOTAAL=$[$TOTAAL + 8]
	    !next w
		a=0
		b=$[$b+12]
	!next v
		a=0
		b=0
		c=$[$c+12]
    !next u
    !filewrite tmp/object.$wims_session.$n  $kubus
!endif 

!if $R>4
    a=0
    b=0
    c=0
    U=!randitem 2,3,4
    V=!randitem 2,3,4
    W=!randitem 2,3,4
    !for u=1 to $U
	!for v=1 to $V
	    !for w=1 to $W
		ATOM=!randitem $ATOMS
		!if $ATOM=$GOEDE_ATOM
		 hit=$[$hit+12]
		!endif 
		kubus=!append line $ATOM $a $b $c to $kubus
		kubus=!append line $ATOM $a $[$b+2] $c to $kubus
		kubus=!append line $ATOM $a $b $[$c+2] to $kubus
		kubus=!append line $ATOM $a $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM $[$a+2] $b $c to $kubus
		kubus=!append line $ATOM $[$a+2] $[$b+2] $c to $kubus
		kubus=!append line $ATOM $[$a+2] $b $[$c+2] to $kubus
		kubus=!append line $ATOM $[$a+2] $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM $[$a+4] $b $c to $kubus
		kubus=!append line $ATOM $[$a+4] $[$b+2] $c to $kubus
		kubus=!append line $ATOM $[$a+4] $b $[$c+2] to $kubus
		kubus=!append line $ATOM $[$a+4] $[$b+2] $[$c+2] to $kubus
		a=$[$a+12]
		TOTAAL=$[$TOTAAL + 12]
	    !next w
		a=0
		b=$[$b+12]
	!next v
		a=0
		b=0
		c=$[$c+12]
    !next u
    !filewrite tmp/object.$wims_session.$n  $kubus

!endif 

GOED$n=$[(round((10^$R)*100*$hit/$TOTAAL))/(10^$R)]
somtekst$n=<b>Tel het totale aantal $objecten ...</b>
!if $HINT=1
    hint=je kunt met je muis de $objecten laten draaien in de "ruimte"<br>\
    zo kun je ze vaak wat gemakkelijker tellen
!endif
nivo_title=tel het aantal $objecten en bereken het percentage $KLEUR $objecten<br>Dit sommetje is niet echt geschikt voor kleurenblinden...
applet$n=<applet codebase="$appletdir" archive="ThreeD.jar"  code="XYZApp.class" width="600" height="400">\
<param name=model value=$module_dir/tmp/object.$wims_session.$n></applet>


opgave$n=<b>en wat is het percentage $KLEUR $objecten ?<br>\
Als er geen mooi rond percentage uitkomt,<br>\
rond dan je antwoord af op $R decimaal nauwkeurig<br>

antwoord$n=$(opgave$n) <p>\
In het totaal waren er $TOTAAL gekleurde $objecten.<br>Het aantal $KLEUR $objecten was $hit<br>Het waren dus 100% &times; $hit/$TOTAAL = $(GOED$n) % $objecten.<center><applet codebase="$appletdir" archive="ThreeD.jar"  code="XYZApp.class" width="300" height="300"><param name=model value=$module_dir/tmp/object.$wims_session.$n></applet>
