PROGRAM example_copy_struc_and_two_dimensional_arrays ;

PRIVATE
    i; j;  k;   t; s;
    press;
    pks;
    byte bbc[128,128];
    g[255];
struct pok[4]
   a; string b;  c;

end  =0,"",0,2,"hello",4,5,"goodbye",7,8,"future",10,11,"past",0;


pok_count=4;

BEGIN
    set_mode(800600);
    set_fps(60,0);
    write_int(0,10,10,0,&fps);
   write(0,50,40,0,"The text in the table shows the data from an array of five structures (0 - 5).");
   write(0,50,50,0,"Press 'space' to copy a random structure (1 - 4) into struct 0.");


    pks=sizeof(pok)/(1+pok_count);




    for( j=0; j<= pok_count; j+=1)

        write_int(0,50+100*j,70,0,&pok[j].a);
        write(0,50+100*j,80,0,pok[j].b);
        write_int(0,50+100*j,90,0,&pok[j].c);

    end

    draw(3,15,15,0,0,120,800,130);

    graph=new_map(3*128,3*128,0,0,1);
    mouse.x=200; mouse.y=200;


   for(i=0; i<256;i+=1)
   g[i]=new_map(3,3,0,0,i);
   end
   for(i=0; i<128; i+=1)
   for(j=0;j<128;j+=1)
        bbc[i,j]=(i+16*j) mod 256;

       map_put(0,graph,g[bbc[i,j]],i*3,j*3);
   end
   end
   write(0,50,160,0,"The image reperesents the values stored in a 2d array as colour values.");

   write(0,50,170,0,"Press 'enter' change values and update the image.");




    loop
    x=mouse.x; y=mouse.y;
    if(key(_space))
        if(press==0)
           copy_struc(&pok,pks,0,rand(1,4));

        end
        press=1;
    else
        press=0;
    end

       if(key(_enter))

   for(i=0; i<128; i+=1)
   for(j=0;j<128; j+=1)

        bbc[i,j]=  (bbc[i,j]+17) mod 256;
       map_put(0,graph,g[bbc[i,j]],i*3,j*3);


       end
       end
       end



    frame;
    end
end



process copy_struc(pk,pks,copyto,copyfrom)
private i;
begin
            for(i=0; i<pks;i+=1)
                *(pk+i+pks*copyto) = *(pk+i+pks*copyfrom);
            end
end


