One way to imitate a "canvas" is to use a MATLAB image. The idea is to manually change its pixels and update the 'CData'
pending image.
Please note that you can use an image with the same dimensions as the size of your screen (the pixel pixels will correspond to the pixels of the screen one to one), but the update will be slower. The trick is to keep it small and allow MATLAB to display it in full screen mode. Thus, the image can be represented as having "bold" pixels. Of course, the resolution of the image will affect the size of the marker you draw.
To illustrate, consider the following implementation:
function draw_buffer() %# paramters (image width/height and the indexed colormap) IMG_W = 50; %# preferably same aspect ratio as your screen resolution IMG_H = 32; CMAP = [0 0 0 ; lines(7)]; %# first color is black background %# create buffer (image of super-pixels) %# bigger matrix gives better resolution, but slower to update %# indexed image is faster to update than truecolor img = ones(IMG_H,IMG_W); %# create fullscreen figure hFig = figure('Menu','none', 'Pointer','crosshair', 'DoubleBuffer','on'); WindowAPI(hFig, 'Position','full'); %# setup axis, and set the colormap hAx = axes('Color','k', 'XLim',[0 IMG_W]+0.5, 'YLim',[0 IMG_H]+0.5, ... 'Units','normalized', 'Position',[0 0 1 1]); colormap(hAx, CMAP) %# display image (pixels are centered around xdata/ydata) hImg = image('XData',1:IMG_W, 'YData',1:IMG_H, ... 'CData',img, 'CDataMapping','direct'); %# hook-up mouse button-down event set(hFig, 'WindowButtonDownFcn',@mouseDown) function mouseDown(o,e) %# convert point from axes coordinates to image pixel coordinates p = get(hAx,'CurrentPoint'); x = round(p(1,1)); y = round(p(1,2)); %# random index in colormap clr = randi([2 size(CMAP,1)]); %# skip first color (black) %# mark point inside buffer with specified color img(y,x) = clr; %# update image set(hImg, 'CData',img) drawnow end end
