Spray painting simulation and thickness evaluation

7 views (last 30 days)
I want to simulate a spray painting, like a “brushes” in “paint” program, by using the left mouse.
The idea is that when I click and hold the left mouse, color is continuously sprayed and its coating stroke is uniformed. The thickness is reflected through color intensity
  3 Comments
Anh
Anh on 20 Dec 2023
I want to simulate a spray painting, like a “brushes” in “paint” program, by using the left mouse. When I push the left mouse, color is sprayed and its coating stroke is uniformed. The thickness is reflected through color intensity.
Image Analyst
Image Analyst on 20 Dec 2023
OK, I think you meant "stroke thickness setting". But I don't know how to do it. I'd just use Photoshop for something like that.

Sign in to comment.

Accepted Answer

Angelo Yeo
Angelo Yeo on 20 Dec 2023
Maybe some basic approach is to use a button down callback and scatter dots that are randomly sampled from normal distribution. Below is my simple implementation of the idea. Good luck.
clear; close all;
I = zeros(1000, 1000);
imagesc(1:1000, 1:1000, I, 'ButtonDownFcn', @sprayCallback);
clim([0, 1]);
colormap([1,1,1; 0,0,0])
axis([0, 1000, 0, 1000])
hold on;
function sprayCallback(h, ~)
cursorLocation = get(ancestor(h, 'axes'),'CurrentPoint');
x = cursorLocation(1, 1);
y = cursorLocation(1, 2);
radius = 30;
scatter(randn(100, 1) * radius + x, randn(100,1) * radius + y, 1, [0,0,0], 'filled', 's')
end
  6 Comments
Angelo Yeo
Angelo Yeo on 28 Dec 2023
Strange. I ran the script in R2023b, and it works like below.
Anh
Anh on 28 Dec 2023
It works well. I just forgot to change the radius and size of the plot.
By the way, I want to ask if the is a function like "press" and "hold" in Matlab such that when I click and hold the left mouse, color is continuously uniform with its intensity change from light to dark. This will be exact what I want to do for the spray painting. And by evaluating the overlapped pixels, thickness can be measured relatively.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!