% returns a sXs grayscale scene that is:
%       (1) rotated about the center by phi radians, then
%       (2) shifted by (x0,y0)

function [Im] = shapes2(s,x0,y0,phi,sx)

  % create hi res image at hisXhis resolution
  fac = 4;
  his = fac*s;

  Im = zeros(s,s);
  hiIm = zeros(his,his);

  index = 1:his;
  dsin = (index - his/2)*sin(phi);
  dcos = (index - his/2)*cos(phi);

  a1 = his/4; a2 = his/32; ax = -his/8; ay = -his/8;
  b1 = his/16; b2 = his/6; bx = -his/3; by = his/8;
  c1 = his/8; c2 = his/8; cx = his/4; cy = -his/4;
  d1 = his/8; d2 = his/8; dx = his/12; dy = his/4;

  r0 = his/8;

  for i=1:his,
    for j=1:his,

	x = dcos(i) - dsin(j) + sx*dcos(j);
	y = dsin(i) + dcos(j) + sx*dsin(j);

	% add cross at (ax,ay)
	rx = abs(x-ax); ry = abs(y-ay);
	if ( ( (rx <= a1) & (ry <= a2) ) | ...
	     ( (rx <= a2) & (ry <= a1) ) )
		hiIm(i,j) = (r0 - min(rx,ry))^2;
	end;

	% add ellipse at (bx,by)
	d = sqrt( (x-bx)^2/b1^2 + (y-by)^2/b2^2 );
	if (d <= 1), hiIm(i,j) = (r0-4*d)^2; end;

        % add a grayscale circle of radius c1 at (cx,cy)
	d = sqrt( (x-cx)^2 + (y-cy)^2 );
	if (d <= c1), hiIm(i,j) = (r0-d/2)^2; end;

        % add sin modulated rect at (dx,dy)
	rx = abs(x-dx); ry = abs(y-dy);
	if ( ( (rx <= d1) & (ry <= d2) ) )
		hiIm(i,j) = (r0*(0.8 + 0.1*sin(y*pi/32) + 0.1*sin(x*pi/16)))^2;
	end;

    end;
  end;

  % low-pass filter hi res image to nyquist of lo res
  hlow = sinc((-3*fac:3*fac)/fac)/fac;
  hlow = hlow.*hamming(length(hlow))';
  filtHiIm = conv2(hlow,hlow,hiIm);

  % sample hi res image to get low res
  shiftx = round(x0*fac);
  xi = shiftx+1:fac:shiftx+his;
  xi = mod(xi-1,his)+1;

  shifty = round(y0*fac);
  yi = shifty+1:fac:shifty+his;
  yi = mod(yi-1,his)+1;
	
  Im = filtHiIm(xi,yi);

return;