用processing做雨

2015-01-292.1万
AI 快速预览详细 收起
本文介绍了如何在Processing中实现一个简单的下雨效果动画。通过几行代码,可以在800x800像素的窗口中生成随机位置、长度和方向的雨滴。这个项目适合零基础新手和编程启蒙,无需复杂的前置技能,即可完成一个生动的动画效果。


3分钟代码30分钟注释

几行代码在processing中得到一个下雨的效果。
效果图:

用processing做雨图1用processing做雨图2






  1. //PROCESSING
  2. //draw rain v 0.1
  3. //LEE
  4. //processing QQ group : 7726768
  5. void setup() {
  6.   size(800, 800);//set window size 800 by 800
  7. background(255);//backgound color is white
  8. }
  9. void draw() {//the main function, same as the loop in Arduino code
  10.   
  11. rain(); // call the rain function;
  12. }
  13. void rain()
  14. {
  15.    background(255,100); //use a semitransparent background to renew the window
  16.   
  17.     for(int i =0; i<100; i++)
  18.   {
  19.     float x =random(800); // get a random raindrop's start loction at X axis
  20.     float y =random(800);// get a random raindrop's start loction at Y axis
  21.     float l =random(30);// get a random raindrop's length
  22.     float deg = random(10); // get a random raindrop direction
  23.     float a = random(100); // get a randow raindrop weight
  24.    
  25.    stroke(0,a); // set the weight of raindrop
  26.    
  27.    //draw the rain!
  28.   line(x,y,x+(cos((75.0+deg)/180.0*3.14)*(l+40)), y+sin((75.0+deg)/180.0*3.14)*(l+50));
  29.   
  30.   }
  31. }
复制代码




创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(7)
babykeke
babykeke
用随机数做的哦
cj2q
cj2q
哈哈哈 看出来是processing了
我爱小宇宙
我爱小宇宙
那里看效果图,我怎么没有看到呢...
Jane
Jane
这雨滴有点抽象哈
Jane
Jane
求效果图 +!
Ash1
Ash1

求看效果图~+1
gckulo
gckulo
求看效果图~
gckulo
gckulo回复苦海
哈哈 辛苦啦
苦海
苦海
作者
回复gckulo
我目标也是那样,但是我只有1天时间,,,,:'(
共9条回复,已加载2条,点击查看更多共9条回复,已加载全部
- 没有更多了 -