Patterns



  • Colored Checkered Patterns

        I saw the first pattern(Pattern 1) when I was reading the book 'Java Complete Reference'.Original code was written in JAVA .I converted it to MATLAB code and generated these patterns.Different combination of Boolean functions and multiplication can be used to generate patterns.  
        
MATLAB code for generating the Pattern 1.
 len =510;
wide=510;
img=zeros(len,wide,3);

for m =1:len
    for n =1:wide
           img(m,n,1)=bitand(bitxor(2*m,2*n),255);
           img(m,n,2)=bitand(bitxor(1*m,1*n),255);
           img(m,n,3)=bitand(bitxor(4*m,4*n),255);

    end
end

img8=uint8(img);
image(img8);
axis tight square
imwrite(img8,'texture.png','png');


 
Pattern 2
 
Pattern 3
 
Pattern 4
 


  • Trigonometric contour plot

  Introduction

                    We can also call it as Trigonometric density plot or Trigonometric moire pattern . We know about trigonometric functions and their curves.These curves are drawn in 2D (x axis for time or angle and y axis for magnitude of function).But how these functions look like when drawn with 2 variables(e.g. sin(x)+cos(y) )? We need 3 dimensions for plotting these functions.X axis for x ,Y axis for y and Z axis for magnitude of function .But one out of three dimensions can be reduced by using colors.Z axis can be removed by using colors for the magnitude of function.Evaluate function on each point on the xy plane and then color that point according to the magnitude of the function on that point.

Example :Left image is sin(x)  evaluated on xy plane, x varies from (-2pi to 2 pi) and y varies from (-2pi to 2pi).Variation of color is only on vertical axis because function has no y variable.
               Right image is of function sin(x)+cos(y) evaluated on xy plane,x varies from (-2pi to 2pi) and y varies from (-2pi to 2pi).Variation of color is on both vertical and horizontal axis because function has both  x and y variable. 

           
  sin(x) sin(x)+cos(y)
   
    
 

  MATLAB code

 MATLAB code for generating these patterns. The image shown on right side is generated after execution of this code, a=x, b=y
 formula:   sin(sin(cos(a+b)*sin(b-a)*b)-cos(sin(b-a)*cos(a+b)*a))*
            cos(sin(cos(a+b)*sin(b-a)*b)-cos(sin(b-a)*cos(a+b)*a));

total=500;
lim=2*pi;
x = linspace(-lim,lim,total);
y = linspace(-lim,lim,total);
c = zeros(length(y),length(x));
a=0;
b=0;
lenx = length(x);
leny = length(y);
const = 100;

for n = 1:lenx
    c(n,:) = x(n)+i*y(:);
end

zval = zeros(lenx,leny);
m  =  1;
n  =  lenx*leny;

for m=1:n
     a=real(c(m));
     b=imag(c(m));
     zval(m)=sin(sin(cos(a+b)*sin(b-a)*b)-cos(sin(b-a)*cos(a+b)*a))*...
             cos(sin(cos(a+b)*sin(b-a)*b)-cos(sin(b-a)*cos(a+b)*a));
end
 cmap=colormap(gray);
 imagesc(x,y,zval);
 axis off square

 

  Some Examples

   The images given below are generated with even more complicated functions.