代码

   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. idea下web工程的编译和输出设置

    公司的一个项目,别人用的eclipse,我这边用IDEA,路径上出了点问题,现在大概有点头绪了,记录下来. 打开project structure后,看到如下设置,最重要的是Modules和Artif ...

  2. 解决 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

    原文链接:https://blog.csdn.net/sea_snow/article/details/82498791 感谢原作者大大  提示:ERROR 1044 (42000): Access ...

  3. 禁止修改input内容

    有什么问题请到<a href='/bbs/index.asp?boardid=2'>论坛</a>中发表<br> <!--# 特效来源:http://www.o ...

  4. python- ' % '运算符的用途(非常重要)

    %运算符就是用来格式化字符串的. 在字符串内部, %s表示用字符串替换, %d表示用整数替换, 有几个%?占位符,后面就跟几个变量或者值,顺序要对应好. 如果只有一个%?,括号可以省略. 另一种格式化 ...

  5. Selenium:八种元素定位方法

    前言: 我们在做WEB自动化时,最根本的就是操作页面上的元素,首先我们要能找到这些元素,然后才能操作这些元素.工具或代码无法像我们测试人员一样用肉眼来分辨页面上的元素.那么我们怎么来定位他们呢? 在学 ...

  6. C# 几进制 转换到几进制

    public string ConvertString(string value, int fromBase, int toBase) { int intValue = Convert.ToInt32 ...

  7. MySQL分表备份

    #!/bin/bash DUMP=/usr/bin/mysqldump MYSQL=/usr/bin/mysql IPADDR=127.0.0.1 PORT=3306 USER=abc PASSWD= ...

  8. [未解决]报错:ssh_exchange_identification: read: Connection reset by peer

    报错代码: ssh_exchange_identification: read: Connection reset by peer fatal: 无法读取远程仓库. 请确认您有正确的访问权限并且仓库存 ...

  9. linux缺頁異常處理--內核空間[v3.10]

    缺頁異常被觸發通常有兩種情況—— 1.程序設計的不當導致訪問了非法的地址 2.訪問的地址是合法的,但是該地址還未分配物理頁框 下面解釋一下第二種情況,這是虛擬內存管理的一個特性.盡管每個進程獨立擁有3 ...

  10. mqtt haproxy 代理及负载搭建

    目录 mqtt 分布集群搭建 haproxy 安装配置 解压 安装 配置haproxy.cfg 启动haproxy 配置mqtt 测试 负载配置说明 负载均衡算法 ACL规则定义 全局配置 默认配置 ...