matlab写中秋祝福

效果如下:

close all
clear
clc

bg=imread('back1.jpg');% read background image

x0=[50 150 250 350 450 550 650];
y0=[850 850 850 850 850 850 850];% position of text
s0=[40 40 40 40 40 40 40 ];% size of text
r0=[0 0 0 0 0 0 0]; % rotation of text
txt=['祝小赵中秋快乐'];

x_max=x0+10;
x_min=x0-10; 
y_max=y0+10;
y_min=y0-10; % max and min position
s_max=s0+20;
s_min=s0-20; % max and min size
r_max=r0+20;
r_min=r0-20; % max and min rotation
cr_max=ones(1,7);
cg_max=ones(1,7);
cb_max=ones(1,7); % max of rgb
cr_min=[0.5 0.5 0.5 0.5 0.5 0.5 0.5];
cg_min=[0.5 0.5 0.5 0.5 0.5 0.5 0.5];
cb_min=zeros(1,7); % min of rgb

x=rand(1,7);
y=rand(1,7);
s=rand(1,7);
r=rand(1,7);
cr=rand(1,7);
cg=rand(1,7);
cb=rand(1,7); % initial rand number

while(1) % loop, never stop
    x=x+0.2*rand(1,7)-0.1;
    y=y+0.2*rand(1,7)-0.1;
    s=s+0.2*rand(1,7)-0.1;
    r=r+0.2*rand(1,7)-0.1;
    cr=cr+0.2*rand(1,7)-0.1;
    cg=cg+0.2*rand(1,7)-0.1;
    cb=cb+0.2*rand(1,7)-0.1; %generate rand number
    
    % equation:
    % number = min_number + rand_number * (max_number - min_number)
    % where rand_number is 0~1 and it changes smoothly
    
    x(x>1)=1;
    x(x<0)=0;
    y(y>1)=1;
    y(y<0)=0;
    s(s>1)=1;
    s(s<0)=0;
    r(r>1)=1;
    r(r<0)=0;
    cr(cr>1)=1;
    cr(cr<0)=0;
    cg(cg>1)=1;
    cg(cg<0)=0;
    cb(cb>1)=1;
    cb(cb<0)=0; % limit rand_number in 0~1
    

    cla(gcf)
    imshow(bg) % main function 1 imshow
    hold on

    for i=1:7;
    text(x_min(i)+x(i)*(x_max(i)-x_min(i)),...
        y_min(i)+y(i)*(y_max(i)-y_min(i)),...
        txt(i),...
        'FontSize',s_min(i)+s(i)*(s_max(i)-s_min(i)),...
        'Rotation',r_min(i)+r(i)*(r_max(i)-r_min(i)),...
        'Color',[cr_min(i)+cr(i)*(cr_max(i)-cr_min(i)),...
        cg_min(i)+cg(i)*(cg_max(i)-cg_min(i)),...
        cb_min(i)+cb(i)*(cb_max(i)-cb_min(i))],...
        'FontName','榛戜綋')
    end % main function 2 text
    
    xs=randi(1000,1,50);
    ys=randi(1000,1,50);
    plot(xs,ys,'LineStyle','none','Marker','*','MarkerSize',10,'MarkerEdgeColor',[1 1 rand]) % main function 3 plot
    
    pause(0.01)
    
end
 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值