代码

   1: class TPoint

   2: {

   3:     public TPoint(int _x, int _y) {

   4:         super();

   5:         this._x = _x;

   6:         this._y = _y;

   7:     }

   8:     public int _x;

   9:     public int _y;

  10:     TPoint _next;

  11: }

  12:  

  13: List<TPoint> points;

  14: int x;

  15: int y;

  16: final int speed = 20;

  17: final int radius = 5;

  18: int points_num = 20;

  19: int xspeed;

  20: int yspeed;

  21: double angle;

  22: TPoint startPoint;

  23: TPoint endPoint;

  24:  

  25: void calcAngle()

  26: {

  27:     if (endPoint._y == startPoint._y >>

  28:             endPoint._x > startPoint._x)

  29:     {

  30:         angle = HALF_PI;

  31:     }

  32:     else if (endPoint._y == startPoint._y >>

  33:             endPoint._x < startPoint._x)

  34:     {

  35:         angle = PI + HALF_PI;

  36:     }

  37:     else

  38:     {

  39:         angle =  atan((float) ((double)(endPoint._x - startPoint._x)/(double)(endPoint._y - startPoint._y)));

  40:     }

  41: }

  42:  

  43: void calcSpeed()

  44: {

  45:     if (endPoint._x >= startPoint._x)

  46:     {

  47:         xspeed = (int) (speed * abs(sin((float) angle)));

  48:     }

  49:     else

  50:     {

  51:         xspeed = -(int) (speed * abs(sin((float) angle)));

  52:     }

  53:  

  54:     if (endPoint._y >= startPoint._y)

  55:     {

  56:         yspeed = (int) (speed * abs(cos((float) angle)));

  57:     }

  58:     else

  59:     {

  60:         yspeed = -(int) (speed * abs(cos((float) angle)));

  61:     }

  62: }

  63:  

  64: void setupTheme(int theme)

  65: {

  66:     switch(theme)

  67:     {

  68:     case 0:    // random

  69:         {

  70:               points = new ArrayList<TPoint>(points_num);

  71:  

  72:               for (int i=0;i<points_num;i++)

  73:               {

  74:                   points.add(new TPoint((int)random(100, displayWidth - 100), 

  75:                  (int)(random(100, displayHeight - 100))));

  76:               }

  77:  

  78:               for (int i=0;i<points_num;i++)

  79:               {

  80:                   points.get(i)._next = points.get((i+1) % points_num);

  81:               }

  82:  

  83:               startPoint = points.get(0);

  84:               endPoint = points.get(1);

  85:  

  86:               x = startPoint._x;

  87:               y = startPoint._y;

  88:  

  89:               calcAngle();

  90:               calcSpeed();

  91:         }

  92:         break;

  93:     case 1: // stars

  94:         {

  95:              List<TPoint> stars = new ArrayList<TPoint>(5);

  96:               stars.add(new TPoint(452, 196));

  97:               stars.add(new TPoint(867, 189));

  98:               stars.add(new TPoint(526, 494));

  99:               stars.add(new TPoint(669, 67));

 100:               stars.add(new TPoint(822, 472));

 101:  

 102:               points_num = 5;

 103:               points = stars;

 104:  

 105:               for (int i=0;i<points_num;i++)

 106:               {

 107:                   points.get(i)._next = points.get((i+1) % points_num);

 108:               }

 109:  

 110:               startPoint = points.get(0);

 111:               endPoint = points.get(1);

 112:  

 113:               x = startPoint._x;

 114:               y = startPoint._y;

 115:  

 116:               calcAngle();

 117:               calcSpeed();

 118:         }

 119:         break;

 120:     case 2:

 121:         {

 122:             List<TPoint> pulse = new ArrayList<TPoint>(points_num + 2);

 123:  

 124:             pulse.add(new TPoint(100, displayHeight / 2));

 125:             for (int i=0;i<points_num;i++)

 126:             {

 127:                 pulse.add(new TPoint(100 + (i * (displayWidth - 200) / points_num), 

 128:                  (int) (displayHeight / 2  +  

 129:                  (pow(-1, (i % 2))) * (int)(random(100, displayHeight / 2 - 100)))));

 130:             }

 131:             pulse.add(new TPoint(displayWidth - 100, displayHeight / 2));

 132:  

 133:             points_num += 2;

 134:  

 135:             points = pulse;

 136:  

 137:             for (int i=0;i<points_num;i++)

 138:             {

 139:                 points.get(i)._next = points.get((i+1) % points_num);

 140:             }

 141:  

 142:             startPoint = points.get(0);

 143:             endPoint = points.get(1);

 144:  

 145:             x = startPoint._x;

 146:             y = startPoint._y;

 147:  

 148:             calcAngle();

 149:             calcSpeed();

 150:         }

 151:         break;

 152:     default:

 153:         {

 154:  

 155:         }

 156:         break;

 157:     }

 158: }

 159:  

 160: @Override

 161: public void setup() {

 162:   size(displayWidth, displayHeight);

 163:   background(0);

 164:   frameRate(90);

 165:  

 166:   setupTheme(2);

 167: }

 168:  

 169: void determineNextPos()

 170: {

 171:     if (endPoint._y == y >> abs(endPoint._x - x) < abs(speed))

 172:     {

 173:         startPoint = endPoint;

 174:         endPoint = endPoint._next;

 175:  

 176:         calcAngle();

 177:         calcSpeed();

 178:  

 179:         x = startPoint._x;

 180:         y = startPoint._y;

 181:     }

 182:     else if (endPoint._x == x >> abs(endPoint._y - y) < abs(speed))

 183:     {

 184:         startPoint = endPoint;

 185:         endPoint = endPoint._next;

 186:  

 187:         calcAngle();

 188:         calcSpeed();

 189:  

 190:         x = startPoint._x;

 191:         y = startPoint._y;

 192:     }

 193:     else if ((endPoint._x != x) >>

 194:             (endPoint._y != y) >>

 195:             (abs(endPoint._x - x) < abs(speed * sin((float) angle) / 2) ||

 196:             abs(endPoint._y - y) < abs(speed * cos((float) angle) /2 )))

 197:     {

 198:         startPoint = endPoint;

 199:         endPoint = endPoint._next;

 200:  

 201:         calcAngle();

 202:         calcSpeed();

 203:  

 204:         x = startPoint._x;

 205:         y = startPoint._y;

 206:     }

 207:     else

 208:     {

 209:         x += xspeed;

 210:         y += yspeed;

 211:     }

 212: }

 213:  

 214: @Override

 215: public void draw() {

 216:  

 217:  determineNextPos();

 218:  

 219:   colorMode(RGB, 255);

 220:   fill(0,0,0,10);

 221:   rect(-1, -1, displayWidth+1, displayHeight+1);

 222:  

 223:   noFill();

 224:   colorMode(HSB, 255);

 225:   stroke(random(0, 255), 255, 255);

 226:  

 227:   ellipse(x, y, radius, radius);

 228:   ellipse(x, y, radius + 1, radius + 1);

 229:  

 230: }

截图

 

 

用Processing生成屏保(二)的更多相关文章

  1. 用processing生成屏保程序

    想法 利用随机数控制圆圈的大小.位置以及颜色,可以产生随机的美感. 让小球动起来,并且在屏幕边界处产生反弹效果. 代码 1: float circle_x = (float) 0.0; 2: floa ...

  2. C#制作简易屏保

    前言:前段时间,有个网友问我C#制作屏保的问题,我瞬间懵逼了(C#还可以制作屏保!).于是我去查阅相关资料,下面把C#如何制作屏保的过程及我学习过程的心得也记录下来,希望对需要的人能有帮助. 基本思路 ...

  3. 一个仿windows泡泡屏保的实现

    一个仿windows泡泡屏保的实现 有天看到有人在百度知道上问windows 泡泡屏保该怎么用C#做,一时有趣,就做了一个出来,对于其中几个要点总结如下: 一,屏保程序的制作要求 屏保程序的扩展名是. ...

  4. 【转】android 电容屏(二):驱动调试之基本概念篇

    关键词:android  电容屏 tp 工作队列 中断 多点触摸协议平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:S5PV310(samsung ...

  5. JAVA中生成、解析二维码图片的方法

    JAVA中生成.解析二维码的方法并不复杂,使用google的zxing包就可以实现.下面的方法包含了生成二维码.在中间附加logo.添加文字功能,并有解析二维码的方法. 一.下载zxing的架包,并导 ...

  6. 024_mac配置屏保命令

    注意吃饭等离开工位的时候养成随时开启屏保的功能,养成信息保护的好习惯,mac如何配置屏幕保护呢? 一. 通过mac"设置"里的"Desktop & Screen ...

  7. [archlinux][plasma][screensaver] plasma5配置屏保程序,没成功(-_-#)

    plamsa用了好久,一直没有屏保.我想要玄酷的屏保! 用xscreensaver, 之前用FVWM2的时候,就用过了,很玄酷. 一,安装 pacman -S xscreensaver 二,配置 xs ...

  8. python实现屏保计时器

    什么都不说先上图吧,Python 初学者实现屏保计时器 原理:利用 Python turtle 库实现快速画图,每隔一秒钟擦除屏幕,然后获得电脑实时时间,再次画图,呈现动态时间. 关于数字如果画,可以 ...

  9. 3D屏保: 线圈

    LineFlower3DSP 一个3D屏保程序,算法的原理类似于圆内轮旋线的生成. 下载地址: http://files.cnblogs.com/WhyEngine/LineFlower3D_sp.z ...

随机推荐

  1. 1.OpenCV数据类型

    基础类型 1.模板类cv::Vec<> 固定向量类,维度已知的小型向量——处理效率高 2.cv::Point类(Point2i,Point2f,Point2d;Point3i,Point3 ...

  2. 并发数/QPS/PV/ 服务器响应时间公示

    QPS:每秒查询率(Query Per Second) ,每秒的响应请求数,也即是最大吞吐能力.QPS = req/sec = 请求数/秒QPS统计方式 [一般使用 http_load 进行统计]QP ...

  3. 手机网页制作的认识(有关meta标签)(转)

    仅用来记录学习: 链接地址:https://blog.csdn.net/ye1992/article/details/22714621

  4. javaIO流(一)--File类的基本使用

    一.File文件操作类 在java语言中提供有对于文件操作系统的支持,这个支持就在java.io.File类中进行了定义,也就是说在整个java.io包中File类是唯一一个与文件本身操作有关的类(创 ...

  5. Java数组遍历

    1.数组声明格式: 数据类型 [] 数组名 = new 数据类型[长度]: 数组长度一旦确定无法更改. 数组里的数据必须是相同类型或自动向上转型后兼容的类型 2.数组遍历 //一维数组 String ...

  6. 【串线篇】MyBatis简介

    一.MyBatis 和数据库进行交互:持久化层框架(SQL映射框架): 1).纯手工 从原始的JDBC----dbutils(QueryRunner)-------JdbcTemplate----xx ...

  7. mongodb与java的整合

    mongodb的相关命令我们这里不在赘述,因为其文档下写的非常清楚,也很容易懂.这里我们说一下其余java的整合,mongodb配置请查看官方文档 1.首先我们应该导入期相关依赖, org.mongo ...

  8. oracle 数据库 锁

    首先你要知道表锁住了是不是正常锁?因为任何DML语句都会对表加锁. 你要先查一下是那个会话那个sql锁住了表,有可能这是正常业务需求,不建议随便KILL session,如果这个锁表是正常业务你把se ...

  9. 18.synchronized

    同步的前提:  必须要有两个或者两个以上的线程  必须是多个线程使用同一个锁  必须保证同步中只能有一个线程在运行  好处:解决了多线程的安全问题  弊端:多个线程需要判断锁,较为消耗资源.抢锁的资源 ...

  10. 【leetcode】552. Student Attendance Record II

    题目如下: Given a positive integer n, return the number of all possible attendance records with length n ...