# dynamic generation of  obj-files
# filewriting required
!if jm.evers notin $wims_site_manager
    !exit
!endif    
n=$teller
kubus=$empty
bewerking=bewerking7.proc
woordmax=10
varcnt=0
!if $graad=0
    R=$teller
!else
    R=$graad
!endif        
!if $R=1
    a=0
    b=0
    c=0
    diepte=!randint 2,4
    hoogte=!randint 2,4
    breedte=!randint 3,5
    !for t=1 to $diepte
	!for s=1 to $hoogte
	    !for p=1 to $breedte
		kubus=!append line v $a $b $c to $kubus
		kubus=!append line v $[$a+2] $[$b] $c to $kubus
		kubus=!append line v $[$a+1] $[$b+2] $c to $kubus
		kubus=!append line v $[$a+1] $[$b+1] $[$c+2] to $kubus
		kubus=!append line l $[1+$d] $[2+$d] $[3+$d] $[1+$d] to $kubus
		kubus=!append line l $[1+$d] $[4+$d] to $kubus
		kubus=!append line l $[2+$d] $[4+$d] to $kubus
		kubus=!append line l $[3+$d] $[4+$d] to $kubus
		d=$[$d+4]
		a=$[$a+5]
	    !next	
	    a=0
	    b=$[$b+5]
	!next
	a=0
	b=0
	c=$[$c+5]
    !next
    GOED$n=$[$hoogte*$breedte*$diepte]
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=tetraeders
!endif
!if $R=2
    a=0	
    b=0
    c=0
    diepte=!randint 2,4
    hoogte=!randint 2,4
    breedte=!randint 3,5
    !for t=1 to $diepte
	!for s=1 to $hoogte
	    !for p=1 to $breedte
		kubus=!append line v $a $b $c to $kubus
		kubus=!append line v $[$a+4] $b $c to $kubus
		kubus=!append line v $[$a+4] $[$b+4] $c to $kubus
		kubus=!append line v $a $[$b+4] $c to $kubus
		kubus=!append line v $[$a+2] $[$b+2] $[$c+4] to $kubus
		kubus=!append line l $[1+$d] $[2+$d] $[3+$d] $[4+$d] $[1+$d] to $kubus
		kubus=!append line l $[1+$d] $[5+$d] to $kubus
		kubus=!append line l $[2+$d] $[5+$d] to $kubus
		kubus=!append line l $[3+$d] $[5+$d] to $kubus
		kubus=!append line l $[4+$d] $[5+$d] to $kubus
		d=$[$d+5]
		a=$[$a+6]
	    !next
	    a=0
	    b=$[$b+6]
	!next  
	b=0  
	c=$[$c+6]
    !next
    GOED$n=$[$hoogte*$breedte*$diepte]
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=pyramides
!endif
!if $R=3 or $R=4
    START=!randint $[2*$R],$[3*$R]
    EINDE=$[$START+20]
    aantal_kubussen=!randint $START,$EINDE
    GOED$n=$aantal_kubussen
    a=0
    b=0
    c=0
    !for p=1 to $aantal_kubussen
	kubus=!append line v $a $b $c to $kubus
        kubus=!append line v $[$a+1] $b $c to $kubus
	kubus=!append line v $[$a+1] $[$b+1] $c to $kubus
	kubus=!append line v $a $[$b+1] $c to $kubus
	kubus=!append line v $a $b $[$c+1] to $kubus
	kubus=!append line v $[$a+1] $b $[$c+1] to $kubus
	kubus=!append line v $[$a+1] $[$b+1] $[$c+1] to $kubus
	kubus=!append line v $a $[$b+1] $[$c+1] to $kubus
	kubus=!append line l $[1+$d] $[2+$d] $[3+$d] $[4+$d] $[1+$d] to $kubus
	kubus=!append line l $[5+$d] $[6+$d] $[7+$d] $[8+$d] $[5+$d] to $kubus
	kubus=!append line l $[1+$d] $[5+$d] to $kubus
	kubus=!append line l $[2+$d] $[6+$d] to $kubus
	kubus=!append line l $[3+$d] $[7+$d] to $kubus
	kubus=!append line l $[4+$d] $[8+$d] to $kubus
	kubus=!append line l $[1+$d] $[5+$d] to $kubus
	d=$[$d+8]
	r=!randitem 1,2,3,4,5
	!if $r=1
	    !increase a
	!endif
	!if $r=2
	    !increase b
	!endif
	!if $r=3
	    !increase c
	!endif   
	!if $r=4
	    !increase a
	    !increase c
	    b=$[$b-1]
	!endif
	!if $r=5
	    a-$[$a-1]
	    !increase b
	    c=$[$c-1]
	!endif
	
    !next
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=kubussen
!endif 


!if $R >4
    breedte=!randitem 3,4
    hoogte=!randitem 2,3
    diepte=!randitem 2,3
    a=0
    b=0
    c=0
    aantal_kubussen=0
    !for t=1 to $diepte
	!for s=1 to $hoogte
	    !for p=1 to $breedte
		wegwezen=!randint 0,$breedte
		!if $p=$wegwezen
		    !goto WEG
		!endif
		!increase aantal_kubussen
		kubus=!append line v $a $b $c to $kubus
		kubus=!append line v $[$a+1] $b $c to $kubus
		kubus=!append line v $[$a+1] $[$b+1] $c to $kubus
		kubus=!append line v $a $[$b+1] $c to $kubus
		kubus=!append line v $a $b $[$c+1] to $kubus
		kubus=!append line v $[$a+1] $b $[$c+1] to $kubus
		kubus=!append line v $[$a+1] $[$b+1] $[$c+1] to $kubus
		kubus=!append line v $a $[$b+1] $[$c+1] to $kubus
		kubus=!append line l $[1+$d] $[2+$d] $[3+$d] $[4+$d] $[1+$d] to $kubus
		kubus=!append line l $[5+$d] $[6+$d] $[7+$d] $[8+$d] $[5+$d] to $kubus
		kubus=!append line l $[1+$d] $[5+$d] to $kubus
		kubus=!append line l $[2+$d] $[6+$d] to $kubus
		kubus=!append line l $[3+$d] $[7+$d] to $kubus
		kubus=!append line l $[4+$d] $[8+$d] to $kubus
		kubus=!append line l $[1+$d] $[5+$d] to $kubus
		d=$[$d+8]     
		!increase a
	    !next 	
	    :WEG  
    	    a=0
	    !increase c
	!next
	a=0
	c=0
	!increase b
    !next
    GOED$n=$aantal_kubussen
    !filewrite tmp/object.$wims_session.$n  $kubus
    objecten=kubussen
!endif 

somtekst$n=Kun je het aantal $objecten tellen?
!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="ThreeD.class" width="600" height="400">\
<param name=model value=$module_dir/tmp/object.$wims_session.$n>\
</applet>

opgave$n=<b>en hoeveel $objecten zijn het?</b>
 
antwoord$n=$(opgave$n)<p>\
Het waren dus $(GOED$n) $objecten.<center>\
<applet codebase="$appletdir" archive="ThreeD.jar"  code="ThreeD.class" width="300" height="300">\
<param name=model value=$module_dir/tmp/object.$wims_session.$n>\
</applet>
