Patterns

Checkered Pattern

The first pattern is given in book 'Java Complete Reference'. Original code was written in JAVA . Equivalent MATLAB code is given below. Different combination of bit wise functions and multiplication can be used to generate patterns.

%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 square

imwrite(img8,'texture.png','png');

%Pattern 2

%Pattern 3

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(2*n,2*m),255);

img(m,n,3)=bitand(bitxor(1*m,1*n),255);

end

end

img8=uint8(img);

image(img8);

axis square

imwrite(img8,'texture.png','png');

%Pattern 4

len =510;

wide=510;

img=zeros(len,wide,3);

for m =1:len

for n =1:wide

img(m,n,1)=bitand(bitor(abs(m-n),abs(-n-m)),255);

img(m,n,2)=bitand(bitor(abs(n-m),abs(m+n)),255);

img(m,n,3)=bitand(bitxor(2*abs(m+n),2*abs(n-m)),255);

end

end

img8=uint8(img);

image(img8);

axis square

imwrite(img8,'texture.png','png');

%Pattern 5

len =510;

wide=510;

img=zeros(len,wide,3);

for m =1:len

for n =1:wide

img(m,n,1)=bitand(bitor(abs(m-n),abs(-n-m)),255);

img(m,n,2)=bitand(bitor(2*abs(n-m),2*abs(m+n)),255);

img(m,n,3)=bitand(bitor(4*abs(m+n),4*abs(n-m)),255);

end

end

img8=uint8(img);

image(img8);

axis square

imwrite(img8,'texture.png','png');

%Pattern 6

len =510;

wide=510;

img=zeros(len,wide,3);

for m =1:len

for n =1:wide

img(m,n,1)=bitand(bitor(m,abs(-m+n)),255);

img(m,n,2)=bitand(bitor(m,abs(m+n)),255);

img(m,n,3)=bitand(bitxor(n,abs(n-m)),255);

end

end

img8=uint8(img);

image(img8);

axis square

imwrite(img8,'texture.png','png');

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. Link to gallery.

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