[LON-CAPA-users] multiple random-label images?

Guy Albertelli II lon-capa-users@mail.lon-capa.org
Thu, 20 Mar 2003 13:13:58 -0500 (EST)


Hi John,

> Can I make a random label image map problem that randomizes a selection 
> of images, in addition to randomizing the labels? What I'm thinking is 
> to have, say, 4 or 5 variants of an image. I would need to be able to 
> specify label locations for each variant independently. I've played a 
> little in construction space on this, but can't figure it out.

There are two ways one might do this, I like the first one best.

Using the xml constructs:
<problem>
  <script type="loncapa/perl">$whichimage=&random(1,2,1);</script>
  <block condition="$whichimage == 1">
     <randomlabel bgimg="/res/msu/bio/EnzymeEnergy/graphics/ADP_P_symb.gif">
        <labelgroup type="text" name="rlimage">
           <label>A</label>
           <label>B</label>
           <location x="1" y="50"></location>
           <location x="1" y="100"></location>
        </labelgroup>
     </randomlabel>
  </block>
  <block condition="$whichimage == 2">
    <randomlabel bgimg="/res/msu/bio/EnzymeEnergy/graphics/ATP_symbol.gif">
       <labelgroup type="text" name="rlimage">
          <label>!A</label>
          <label>!B</label>
          <location x="100" y="100"></location>
          <location x="100" y="50"></location>
       </labelgroup>
    </randomlabel>
  </block>
</problem>


Using <script> to do everything,

<problem>
  <script type="loncapa/perl">
    $whichimage=&random(0,1,1);
    $location=([1,50,1,100],[100,100,100,50])[$whichimage];
    $image=('ADP_P_symb.gif','ATP_symbol.gif')[$whichimage];
    $labels=(['A','B'],['!A','!B'])[$whichimage];
  </script>
  <randomlabel bgimg="/res/msu/bio/EnzymeEnergy/graphics/$image">
    <labelgroup type="text" name="rlimage">
      <label>$$labels[0]</label>
      <label>$$labels[1]</label>
      <location x="$$location[0]" y="$$location[1]"></location>
      <location x="$$location[2]" y="$$location[3]"></location>
    </labelgroup>
  </randomlabel>
</problem>
-- 
guy@albertelli.com  LON-CAPA Developer  0-7-7-1-