function pollock(varargin)
% POLLOCK - Allows the user to paint in the style of Jackson Pollock.
%
% By clicking and dragging the mouse across the canvas, the user will
% splatter paint across the canvas like Jackson Pollock. The faster the
% user moves the mouse, the smaller the platters become and vice versa.
% The user can, using the menu options, choose to save the canvas to a
% file, start over, close the window, choose the background color of the
% canvas, or choose the specific color or palette of colors of paint.
%
% There are no optional inputs to pollock.m - just start it up and start
% painting!
%
% James Roberts
% jamescroberts (at) gmail (dot) com
% Release : 1.1
% Release Date: 2008/07/03
handles.N = 800;
handles.M = 600;
handles.lastPoint = [NaN, NaN];
handles.color = rand(1,3);
handles.drawFlag = 0;
handles.randFlag = 1;
handles.paletteFlag = 'none';
% Generate the figure
hFig = figure;
set(hFig,'Units','pixels',...
'Position',[100 100 handles.N handles.M],...
'NumberTitle','off', ...
'Name','Pollock',...
'DoubleBuffer','on', ...
'CloseRequestFcn',@CloseFcn,...
'MenuBar','none');
% Generate menus
filemenu = uimenu('Label','File');
uimenu(filemenu,'Label','Save','Callback',@SaveFcn,'Accel','S');
uimenu(filemenu,'Label','Clear Canvas','Callback',@ClearFcn,'Accel','S');
uimenu(filemenu,'Label','Exit','Callback',@CloseFcn,'Accel','X');
handles.colormenu = uimenu('Label','Color');
uimenu(handles.colormenu,'Label','Red','Callback',@RedFcn,'Accel','R');
uimenu(handles.colormenu,'Label','Orange','Callback',@OrangeFcn,'Accel','O');
uimenu(handles.colormenu,'Label','Yellow','Callback',@YellowFcn,'Accel','Y');
uimenu(handles.colormenu,'Label','Green','Callback',@GreenFcn,'Accel','G');
uimenu(handles.colormenu,'Label','Blue','Callback',@BlueFcn,'Accel','B');
uimenu(handles.colormenu,'Label','Purple','Callback',@PurpleFcn,'Accel','P');
uimenu(handles.colormenu,'Label','White','Callback',@WhiteFcn,'Accel','W');
uimenu(handles.colormenu,'Label','Black','Callback',@BlackFcn,'Accel','K');
uimenu(handles.colormenu,'Label','Random','Callback',@RandFcn,'Accel','A');
uimenu(handles.colormenu,'Label','Custom...','Separator','on','Callback',@CustomFcn,'Accel','U');
uimenu(handles.colormenu,'Label','Background','Separator','on','Callback',@BackgroundFcn);
paletteMenu = uimenu('Label','Palettes');
uimenu(paletteMenu,'Label','All','Callback',@AllPaletteFcn);
uimenu(paletteMenu,'Label','Grayscale','Callback',@GraysPaletteFcn);
uimenu(paletteMenu,'Label','Reds','Callback',@RedsPaletteFcn);
uimenu(paletteMenu,'Label','Greens','Callback',@GreensPaletteFcn);
uimenu(paletteMenu,'Label','Blues','Callback',@BluesPaletteFcn);
uimenu(paletteMenu,'Label','Yellows','Callback',@YellowsPaletteFcn);
uimenu(paletteMenu,'Label','Purples','Callback',@PurplesPaletteFcn);
uimenu(paletteMenu,'Label','Warms','Callback',@WarmsPaletteFcn);
uimenu(paletteMenu,'Label','Cools','Callback',@CoolsPaletteFcn);
uimenu(paletteMenu,'Label','Pastels','Callback',@PastelsPaletteFcn);
uimenu(paletteMenu,'Label','Neons','Callback',@NeonsPaletteFcn);
uimenu(paletteMenu,'Label','Darks','Callback',@DarksPaletteFcn);
uimenu(paletteMenu,'Label','Lights','Callback',@LightsPaletteFcn);
helpmenu = uimenu('Label','Help');
uimenu(helpmenu,'Label','Help','Callback',['help ' mfilename]);
uimenu(helpmenu,'Label','About','Separator','on','Callback',@AboutFcn);
% Generate the axes
handles.axes1 = axes('tickdir','out',...
'units','pixels',...
'nextplot','add',...
'XLimMode','manual',...
'Position',[1 1 handles.N handles.M],...
'XLim',[1 handles.N],...
'YLimMode','manual',...
'YLim',[1 handles.M],...
'Color',[1 1 1]);
% Define all of the mouse functions
set(hFig,'WindowButtonDownFcn',@DownFcn);
set(hFig,'WindowButtonUpFcn',@UpFcn);
set(hFig,'WindowButtonMotionFcn',@MotionFcn);
% Store data to the figure
guidata(hFig,handles)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% All of the functions for setting colors
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function RedFcn(hFig,event_data)
handles = guidata(hFig);
handles.color = [1 0 0]; handles.randFlag = 0;
guidata(hFig,handles)
end
function OrangeFcn(hFig,event_data)
handles = guidata(hFig);
handles.color = [1 0.5 0]; handles.randFlag = 0;
guidata(hFig,handles)
end
function YellowFcn(hFig,event_data)
handles = guidata(hFig);
handles.color = [1 1 0]; handles.randFlag = 0;
guidata(hFig,handles)
end
function GreenFcn(hFig,event_data)
handles = guidata(hFig);
handles.color = [0 1 0]; handles.randFlag = 0;
guidata(hFig,handles)
end
function BlueFcn(hFig,event_data)
handles = guidata(hFig);
handles.color = [0 0 1]; handles.randFlag = 0;
guidata(hFig,handles)
end
function PurpleFcn(hFig,event_data)
handles = guidata(hFig);
handles.color = [0.67 0 1]; handles.randFlag = 0;
guidata(hFig,handles)
end
function WhiteFcn(hFig,event_data)
handles = guidata(hFig);
handles.color = [1 1 1]; handles.randFlag = 0;
guidata(hFig,handles)
end
function BlackFcn(hFig,event_data)
handles = guidata(hFig);
handles.color = [0 0 0]; handles.randFlag = 0;
guidata(hFig,handles)
end
function RandFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1;
guidata(hFig,handles)
end
function CustomFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 0;
custom_color = [uisetcolor 0 0];
handles.color = custom_color(1:3);
guidata(hFig,handles)
end
function BackgroundFcn(hFig,event_data)
handles = guidata(hFig);
custom_color = [uisetcolor 0 0];
cla
set(handles.axes1,'Color',custom_color(1:3));
guidata(hFig,handles)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% All of the functions for setting the palettes
% These simply set a string flag that will be used later
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function AllPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'none';
guidata(hFig,handles)
end
function GraysPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'grays';
guidata(hFig,handles)
end
function RedsPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'reds';
guidata(hFig,handles)
end
function GreensPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'greens';
guidata(hFig,handles)
end
function BluesPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'blues';
guidata(hFig,handles)
end
function YellowsPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'yellows';
guidata(hFig,handles)
end
function PurplesPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'purples';
guidata(hFig,handles)
end
function WarmsPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'warms';
guidata(hFig,handles)
end
function CoolsPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'cools';
guidata(hFig,handles)
end
function PastelsPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'pastels';
guidata(hFig,handles)
end
function NeonsPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'neons';
guidata(hFig,handles)
end
function DarksPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'darks';
guidata(hFig,handles)
end
function LightsPaletteFcn(hFig,event_data)
handles = guidata(hFig);
handles.randFlag = 1; handles.paletteFlag = 'lights';
guidata(hFig,handles)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Clear the canvas
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ClearFcn(hFig,event_data)
cla
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Save the canvas
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function SaveFcn(hFig,event_data)
[fileName,pathName] = uiputfile({'*.jpg';'*.png';'*.tif';'*.bmp'},...
'Save Canvas');
switch fileName(end-2:end);
case 'jpg'
print(sprintf('%s%s',pathName,fileName),'-djpeg100');
case 'png'
print(sprintf('%s%s',pathName,fileName),'-dpng');
case 'tif'
print(sprintf('%s%s',pathName,fileName),'-dtiff');
case 'bmp'
print(sprintf('%s%s',pathName,fileName),'-dbitmap');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Close the figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function CloseFcn(hFig,event_data)
closereq
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function called during a mouse button press
% This function handles the palettes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function DownFcn(hFig,event_data,handles)
handles = guidata(hFig);
if handles.randFlag
switch handles.paletteFlag
case 'none'
handles.color = rand(1,3);
case 'grays'
handles.color = rand*ones(1,3);
case 'reds'
handles.color = [rand 0 0];
case 'greens'
handles.color = [0 rand 0];
case 'blues'
handles.color = [0 0 rand];
case 'yellows'
while 1
handles.color = rand(1,3);
if (handles.color(1) > .8 && handles.color(2) > .8 && handles.color(3) < .2)
break
end
end
case 'purples'
while 1
handles.color = rand(1,3);
if (handles.color(1) > .5 && handles.color(2) < .1 && handles.color(3) > .5)
break
end
end
case 'warms'
while 1
handles.color = rand(1,3);
if (handles.color(1) > .5 && handles.color(2) < .5 && handles.color(3) < .5)
break
end
end
case 'cools'
handles.color = [0 rand rand];
case 'pastels'
while 1
handles.color = rand(1,3);
if (handles.color(1) > .7 || handles.color(2) > .7 || handles.color(3) > .7) && ...
(handles.color(1) > .3 && handles.color(2) > .3 && handles.color(3) > .3)
break
end
end
case 'neons'
while 1
handles.color = rand(1,3);
if min(handles.color) < .15 && max(handles.color) > .85 && (median(handles.color) < .15 || median(handles.color) > .85)
break
end
end
case 'darks'
while 1
handles.color = rand(1,3);
if (handles.color(1) < .3 && handles.color(2) < .3 && handles.color(3) < .3)
break
end
end
case 'lights'
while 1
handles.color = rand(1,3);
if (handles.color(1) > .7 && handles.color(2) > .7 && handles.color(3) > .7)
break
end
end
end
end
handles.drawFlag = 1;
guidata(hFig,handles)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function called during a mouse button press finish
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function UpFcn(hFig,event_data)
handles = guidata(hFig);
handles.drawFlag = 0;
% Get the pixel data from the axes
tmp = getframe(handles.axes1);
% Clear the axes and reset the parameters
cla(handles.axes1);
set(handles.axes1,...
'tickdir','out',...
'units','pixels',...
'nextplot','add',...
'XLimMode','manual',...
'Position',[1 1 handles.N handles.M],...
'XLim',[1 handles.N],...
'YLimMode','manual',...
'YLim',[1 handles.M]);
% Image the pixel data. this reduces the # of children.
image(tmp.cdata(end:-1:1,1:end,1:end));
guidata(hFig,handles)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function called during a mouse motion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function MotionFcn(hFig,event_data)
handles = guidata(hFig);
if handles.drawFlag
% Get the mouse position and decide how large the mark should be.
% the faster the user moves the mouse, the smaller the mark.
mousePos = get(hFig,'CurrentPoint');
pointDist = (handles.lastPoint(1)-mousePos(1))^2 + (handles.lastPoint(2)-mousePos(2))^2;
handles.lastPoint = mousePos;
markSize = max([.1 ceil(50/(pointDist^(1/3)))]);
% Plot the main mark
tmp = plot(mousePos(1),mousePos(2),'o');
set(tmp,...
'Color',handles.color,...
'MarkerFaceColor',handles.color,...
'MarkerSize',markSize);
% Plot the splatter marks
for iA = 1:5
tmp = mousePos + 1.5*markSize*(rand(1,2)-0.5);
tmp = plot(tmp(1),tmp(2),'o');
set(tmp,...
'Color',handles.color,...
'MarkerFaceColor',handles.color,...
'MarkerSize',markSize*rand/2);
end
end
guidata(hFig,handles);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Opens the 'About' menu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function AboutFcn(hFig,event_data)
msgbox({'Pollock',' Version 1.1 (2008/07/03)','',...
' by James Roberts <jamescroberts (at) gmail (dot) com>'},'About');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%