In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use Matlab to create a scratch raffle special effect. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Effect display
The effect of the program is as follows:
As shown in the figure, press and hold the mouse without releasing and sliding the mouse to scrape off the layer:
two。 Description of the principle of the program 2.1 Award setting
The award settings are written in an array of cell cells, with the first column as text information and the second as the probability of extraction:
StrSet= {'520 yuan red envelope one', 15 shock 100; '1314 yuan red packet one', 5 swap 100; 'black silk sailor suit', 20 shock 100; 'black silk maid suit', 20 shock 100; 'hug x 50 times', 20 shock 100; 'kiss x 50 times', 20 shock 100;}; probVal=cell2mat (strSet (:, 2));% extract the second list of probability information 2.2 randomly
Firstly, we transform the discrete probability density function into the probability distribution function.
Convert the probability density function to the probability distribution function for i=2:length (probVal) probVal (I) = probVal (I) + probVal (iMur1); end
For example
The probability density and probability distribution are as follows:
Probability density probability distribution 0.150.150.050.20.20.40.20.60.20.80.21
Then if the random number I drew is 0.7 between the fourth and fifth number of the probability distribution, we think we have the fifth option. The code of this part is as follows:
RandNum=rand (); numRange=probVal > randNum;strPos=find (numRange,1)
After determining the number of awards, you can display the string, and use the text function to display it in the coordinate area:
Text (300, 100, 100, strSet {strPos,1},... 'HorizontalAlignment','center','FontSize',60) 2.3 draw layers
Use image to draw a picture with a gray color and a transparency of 1 for each position:
CoverageMat_C=ones (200, 600, 3). * 0.62; coverageHdl=image (0600), [0200], coverageMat_C,... 'AlphaData',coverageMat_A); 2. 4 swipe mouse award
Determine whether the mouse is clicked or not
Assuming that our current figure is called fig and the following settings are set on the basis of fig, we first need to determine whether the mouse is held down or not. So we set up a callback function named isClicking and set the mouse down and mouse release callback functions, setting isClicking to true when the mouse is clicked and isClicking to false when the mouse is released.
IsClicking=false;set (fig,'WindowButtonDownFcn',@bt_down); function bt_down (~, ~), isClicking=true;endset (fig,'WindowButtonUpFcn',@bt_up); function bt_up (~, ~), isClicking=false;end
Mouse slide scraping award
This part of the code:
[xMesh,yMesh] = meshgrid (1set 600); set (fig,'WindowButtonMotionFcn',@bt_move); function bt_move (~, ~) if isClicking mousePos=fig.CurrentPoint; boolPos=sqrt ((xMesh-mousePos (1)). ^ 2 + (yMesh-mousePos (2)). ^ 2) randNum;strPos=find (numRange,1); text (300 strPos,1 {strPos,1},... 'HorizontalAlignment','center','FontSize',60) coverageMat_C=ones (2007.600 and 3). * 0.62 xMesh,yMesh coverageMatrices meshgrid (200600); coverageHdl=image ([0600], [0200], coverageMat_C,...) 'AlphaData',coverageMat_A); isClicking=false;set (fig,'WindowButtonDownFcn',@bt_down); function bt_down (~, ~), isClicking=true;endset (fig,'WindowButtonUpFcn',@bt_up); function bt_up (~, ~), isClicking=false;end set (fig,'WindowButtonMotionFcn',@bt_move); function bt_move (~, ~) if isClicking mousePos=fig.CurrentPoint; boolPos=sqrt ((xMesh-mousePos (1)). ^ 2 + (yMesh-mousePos (2)). ^ 2)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.