# dynamic generation of obj-files
# file-writing required
!if jm.evers notin $wims_site_manager
    !exit
!endif    

n=$teller
kubus=$empty
!if $graad=0
    R=$teller
!else
    R=$graad
!endif
        
bewerking=bewerking7.proc
woordmax=10
varcnt=0
ATOMS=C,H,N,P,S,O,C,H,N,P,S
ATOMS=!shuffle $ATOMS

#C=grijs H=wit N=blauw P=paars
#S=geel O=oranje

!if $R=1
    a=0
    b=0
    c=0
    U=!randitem 2,3,4,4,4,5
    V=!randitem 2,3,3,3,4,4,4,4,5,5
    W=!randitem 3,3,3,3,4,4,4,5,5,5,6,6,6
    !for u=1 to $U
	!for v=1 to $V	
	    ATOM=!item $v of $ATOMS
	    !for w=1 to $W
		kubus=!append line $ATOM $a $b $c to $kubus
		!increase a
	    !next w
	    a=0
	    !increase b
	!next v
	    b=0
	    !increase c
    !next u
    GOED$n=$[$U*$V*$W]
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=balletjes
!endif

!if $R=2
    a=0
    b=0
    c=0
    U=!randitem 3,4,4,5,4,4,3,2
    V=!randint 2,2,3,3,3,4,4,4,5,5,5,5,6
    W=!randint 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
		kubus=!append line $ATOM1 $a $b $c to $kubus
		kubus=!append line $ATOM2 $a $[$b+10] $c to $kubus
		kubus=!append line $ATOM3 $a $b $[$c+10] to $kubus
		kubus=!append line $ATOM4 $a $[$b+10] $[$c+10] to $kubus
		!increase a
	    !next w
	    a=0
	    !increase b
	!next v
	    b=0
	    !increase c
    !next u
    GOED$n=$[$U*$V*$W*4]
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=balletjes
!endif
!if $R=3
    a=0
    b=0
    c=0
    U=!randint 3,6
    V=!randint 2,6
    W=!randint 2,6
    
    !for p=1 to 4
	ATOM$p =!item $p of $ATOMS
    !next
    !for u=1 to $U
	!for v=1 to $V
	    !for w=1 to $W
		kubus=!append line $ATOM1 $a $b $c to $kubus
		kubus=!append line $ATOM2 $a $[$b+4] $c to $kubus
		kubus=!append line $ATOM3 $a $b $[$c+4] to $kubus
		kubus=!append line $ATOM4 $a $[$b+4] $[$c+4] to $kubus
		a=$[$a+10]
	    !next w
		a=0
		b=$[$b+10]
	!next v
		a=0
		b=0
		c=$[$c+10]
    !next w
    GOED$n=$[$U*$V*$W*4]
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=atomen
!endif
!if $R=4
    a=0
    b=0
    c=0
    U=!randint 2,4
    V=!randint 2,4
    W=!randint 2,4
    
    ATOM1=P
    ATOM2=N
    ATOM3=O
    ATOM4=S
    !for u=1 to $U
	!for v=1 to $V
	    !for w=1 to $W
		kubus=!append line $ATOM1 $a $b $c to $kubus
		kubus=!append line $ATOM1 $a $[$b+2] $c to $kubus
		kubus=!append line $ATOM2 $a $b $[$c+2] to $kubus
		kubus=!append line $ATOM2 $a $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM3 $[$a+2] $b $c to $kubus
		kubus=!append line $ATOM3 $[$a+2] $[$b+2] $c to $kubus
		kubus=!append line $ATOM4 $[$a+2] $b $[$c+2] to $kubus
		kubus=!append line $ATOM4 $[$a+2] $[$b+2] $[$c+2] to $kubus
		a=$[$a+12]
	    !next w
		a=0
		b=$[$b+12]
	!next v
		a=0
		b=0
		c=$[$c+12]
    !next u
    GOED$n=$[$U*$V*$W*8]
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=atomen?
    tekst=$U rijen en $V kolomen met daarin $W "blokken van 8" balletjes diep
!endif 

!if $R=5
    a=0
    b=0
    c=0
    U=!randint 2,4
    V=!randint 2,4
    W=!randint 2,4
    
    ATOM1=P
    ATOM2=N
    ATOM3=O
    ATOM4=S
    !for u=1 to $U
	!for v=1 to $V
	    !for w=1 to $W
		kubus=!append line $ATOM1 $a $b $c to $kubus
		kubus=!append line $ATOM1 $a $[$b+2] $c to $kubus
		kubus=!append line $ATOM2 $a $b $[$c+2] to $kubus
		kubus=!append line $ATOM2 $a $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM3 $[$a+2] $b $c to $kubus
		kubus=!append line $ATOM3 $[$a+2] $[$b+2] $c to $kubus
		kubus=!append line $ATOM4 $[$a+2] $b $[$c+2] to $kubus
		kubus=!append line $ATOM4 $[$a+2] $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM3 $[$a+4] $b $c to $kubus
		kubus=!append line $ATOM3 $[$a+4] $[$b+2] $c to $kubus
		kubus=!append line $ATOM4 $[$a+4] $b $[$c+2] to $kubus
		kubus=!append line $ATOM4 $[$a+4] $[$b+2] $[$c+2] to $kubus
		a=$[$a+12]
	    !next
		a=0
		b=$[$b+12]
	!next
		a=0
		b=0
		c=$[$c+12]
    !next
    GOED$n=$[$U*$V*$W*12]
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=atomen
    tekst=$U rijen en $V kolomen met daarin "blokken" van 12 atomen
!endif 

!if $R=6
    U=!randitem 7,7,7,7,8,8,8,8,9,10
    V=!randitem 2,3,4,4,4,4,5,6
    W=!randitem 3,4,5,5,5,5,5,5,6
	!for c=1 to $V
	    !for b=1 to $W
		!for a=1 to $U
		    ATOM=!item $a of $ATOMS
		    kubus=!append line $ATOM $a $b $c to $kubus
		    !increase GOED$n
		!next a
		a=1    
		ATOM=!item $b of $ATOMS
		kubus=!append line $ATOM $a $b $c to $kubus
	    !next b
	    b=1
	    a=1
	    ATOM=!item $c of $ATOMS
	    kubus=!append line $ATOM $a $b $c to $kubus
	    U=$[$U-1]
	!next c
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=balletjes 
!endif


!if $R>6
    a=0
    b=0
    c=0
    U=!randint 2,4
    V=!randint 2,4
    W=!randint 2,4
    
    ATOM1=P
    ATOM2=N
    ATOM3=O
    ATOM4=S
    !for u=1 to $U
	!for v=1 to $V
	    !for w=1 to $W
		kubus=!append line $ATOM1 $a $b $c to $kubus
		kubus=!append line $ATOM1 $a $[$b+2] $c to $kubus
		kubus=!append line $ATOM2 $a $b $[$c+2] to $kubus
		kubus=!append line $ATOM2 $a $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM3 $[$a+2] $b $c to $kubus
		kubus=!append line $ATOM3 $[$a+2] $[$b+2] $c to $kubus
		kubus=!append line $ATOM4 $[$a+2] $b $[$c+2] to $kubus
		kubus=!append line $ATOM4 $[$a+2] $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM1 $[$a+4] $b $c to $kubus
		kubus=!append line $ATOM1 $[$a+4] $[$b+2] $c to $kubus
		kubus=!append line $ATOM2 $[$a+4] $b $[$c+2] to $kubus
		kubus=!append line $ATOM2 $[$a+4] $[$b+2] $[$c+2] to $kubus
		kubus=!append line $ATOM3 $[$a+6] $b $c to $kubus
		kubus=!append line $ATOM3 $[$a+6] $[$b+2] $c to $kubus
		kubus=!append line $ATOM4 $[$a+6] $b $[$c+2] to $kubus
		kubus=!append line $ATOM4 $[$a+6] $[$b+2] $[$c+2] to $kubus
		a=$[$a+12]
	    !next w
		a=0
		b=$[$b+12]
	!next v
		a=0
		b=0
		c=$[$c+12]
    !next u
    GOED$n=$[$U*$V*$W*16]
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=atomen
    tekst=$U rijen en $V kolomen met daarin "klonten" van 16 atomen

!endif 



somtekst$n=<b>Kun je het aantal $objecten tellen?</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
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 hoeveel zijn het er?</b>

antwoord$n=$(opgave$n)<p>\
Het waren dus $(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>
