//write high res BMP of circles

bmp_size=520; //pixel width and height of image
cx=bmp_size/2; //center point
cy=cx;
hr=cx-1; //scaled radius for 1 unit
min_angle_step=(2*%pi)/(%pi*bmp_size*2); //trace arcs by taking these angular steps
min_r_step=4/(bmp_size*2);
bmp_data=ones(bmp_size,bmp_size); //the pixel data, 0=black, 1=white

r_end=1.0;
r_second=0.86;
r_minute=0.45;
r_align=0.01;
re2=(hr*r_end)^2;
rs2=(hr*r_second)^2;
rm2=(hr*r_minute)^2;
ra2=(hr*r_align)^2;

smult=720;
mmult=12;
isrotor=%t;

sbwidth=2*%pi/(smult-1);
sbslot=sbwidth * ((smult)/(2*smult-1))*1.2; 
sbgap=sbwidth-sbslot;
srwidth=2*%pi/smult;
srslot=sbgap*1.5;

mbwidth=2*%pi/(mmult-1);
mbslot=mbwidth * ((mmult)/(2*mmult-1))*1.2; 
mbgap=mbwidth-mbslot;
mrwidth=2*%pi/mmult;
mrslot=mbgap*1.5;

if(isrotor)
    s_width=srwidth;
    s_slot=srslot;
    s_shift=s_slot/2;
    m_width=mrwidth;
    m_slot=mrslot;
    m_shift=m_slot/2;
else
    s_width=sbwidth;
    s_slot=sbslot;
    s_shift=s_width-sbgap/2;
    m_width=mbwidth;
    m_slot=mbslot;
    m_shift=m_width-mbgap/2;
end


for(x=1:bmp_size)
    for(y=1:bmp_size)
        xc=x-cx;
        yc=y-cx;
        r2=xc^2+yc^2;
        if(r2<=re2)
            if(r2>=rs2) //second hand vernier
                theta=modulo(atan(yc,xc)+%pi+s_shift,s_width);
                if(theta<=s_slot)
                    bmp_data(x,y)=0;
                end
            else
                if(r2>=rm2) //minute hand vernier
                    theta=modulo(atan(yc,xc)+%pi+m_shift,m_width);
                    if(theta<=m_slot)
                        bmp_data(x,y)=0;
                    end
                else
                    if(r2<=ra2)
                        bmp_data(x,y)=0;
                    else
                        if(isrotor & xc<=0) //hour hand semicircle
                            bmp_data(x,y)=0;
                        end
                    end
                end
            end
        end
    end
end

if(isrotor)
    imwrite(bmp_data,"rotor.bmp");
else
    imwrite(bmp_data,"stator.bmp");
end

