Saturday, December 09, 2006


Allright. This has been an astonishing day - much to report. Just finished the code for my X-mas cards this year:

% XMAS CARD - JOEY GERONDALE
% 12/9/06

% INITIALIZE
clc
clear all
load rand1
num=randn;
format long
width=520*2; %picture size width in pixels
height=339*2; %picture size height in pixels
hblock=12; %desired number of vertical blocks
wblock=18; %desired number of horiz blocks

% CALCULATE
wdr=ceil(width/wblock); %number of horiz pixels per block
hdr=ceil(height/hblock); %number of vert pixels per block

pic=zeros(height,width,3);

for k=1:hblock
for r=1:wblock
tt=clock;
rand('state',floor(tt(6)*1000-50*rand(1)*k-25*rand(1)*r))
if(num(floor(10000*rand(1))))>127.5 % choose red bias
rd_st=(floor(9999*rand(1)));
gr_st=(floor(9999*rand(1)));
bl_st=(floor(9999*rand(1)));
while num(rd_st)<120>255
rd_st=rd_st+1;
end
while num(gr_st)<0>20
gr_st=gr_st+1;
end
while num(bl_st)<0>60
bl_st=bl_st+1;
end
red=num(rd_st)/256;
green=num(gr_st)/256;
blue=num(bl_st)/256;
pic(((k-1)*hdr+1):(k*hdr),((r-1)*wdr+1):(r*wdr),1)=red; %assign red
pic(((k-1)*hdr+1):(k*hdr),((r-1)*wdr+1):(r*wdr),2)=green; %assign green
pic(((k-1)*hdr+1):(k*hdr),((r-1)*wdr+1):(r*wdr),3)=blue; %assign blue
else %choose green bias
rd_st=(floor(9999*rand(1)));
gr_st=(floor(9999*rand(1)));
bl_st=(floor(9999*rand(1)));
while num(rd_st)<0>80
rd_st=rd_st+1;
end
while num(gr_st)<110>190
gr_st=gr_st+1;
end
while num(bl_st)<0>60
bl_st=bl_st+1;
end
red=num(rd_st)/256;
green=num(gr_st)/256;
blue=num(bl_st)/256;
pic(((k-1)*hdr+1):(k*hdr),((r-1)*wdr+1):(r*wdr),1)=red; %assign red
pic(((k-1)*hdr+1):(k*hdr),((r-1)*wdr+1):(r*wdr),2)=green; %assign green
pic(((k-1)*hdr+1):(k*hdr),((r-1)*wdr+1):(r*wdr),3)=blue; %assign blue
end
end
end

% OUTPUT

imwrite(pic,'xmascrd30.jpeg','jpeg')


So I just finished running the thing 30 times (so you can all get a unique card, of course) and I'm off to Wal-mart to print them off. This isn't extremely interesting or complex (it's a variation on an idea from an earlier post) - but I want to thank Alex for helping me figure out the flaws in my logic. Now it works!

Peace.

No comments: