用Processing生成屏保(二)
代码
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生成屏保(二)的更多相关文章
- 用processing生成屏保程序
想法 利用随机数控制圆圈的大小.位置以及颜色,可以产生随机的美感. 让小球动起来,并且在屏幕边界处产生反弹效果. 代码 1: float circle_x = (float) 0.0; 2: floa ...
- C#制作简易屏保
前言:前段时间,有个网友问我C#制作屏保的问题,我瞬间懵逼了(C#还可以制作屏保!).于是我去查阅相关资料,下面把C#如何制作屏保的过程及我学习过程的心得也记录下来,希望对需要的人能有帮助. 基本思路 ...
- 一个仿windows泡泡屏保的实现
一个仿windows泡泡屏保的实现 有天看到有人在百度知道上问windows 泡泡屏保该怎么用C#做,一时有趣,就做了一个出来,对于其中几个要点总结如下: 一,屏保程序的制作要求 屏保程序的扩展名是. ...
- 【转】android 电容屏(二):驱动调试之基本概念篇
关键词:android 电容屏 tp 工作队列 中断 多点触摸协议平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:S5PV310(samsung ...
- JAVA中生成、解析二维码图片的方法
JAVA中生成.解析二维码的方法并不复杂,使用google的zxing包就可以实现.下面的方法包含了生成二维码.在中间附加logo.添加文字功能,并有解析二维码的方法. 一.下载zxing的架包,并导 ...
- 024_mac配置屏保命令
注意吃饭等离开工位的时候养成随时开启屏保的功能,养成信息保护的好习惯,mac如何配置屏幕保护呢? 一. 通过mac"设置"里的"Desktop & Screen ...
- [archlinux][plasma][screensaver] plasma5配置屏保程序,没成功(-_-#)
plamsa用了好久,一直没有屏保.我想要玄酷的屏保! 用xscreensaver, 之前用FVWM2的时候,就用过了,很玄酷. 一,安装 pacman -S xscreensaver 二,配置 xs ...
- python实现屏保计时器
什么都不说先上图吧,Python 初学者实现屏保计时器 原理:利用 Python turtle 库实现快速画图,每隔一秒钟擦除屏幕,然后获得电脑实时时间,再次画图,呈现动态时间. 关于数字如果画,可以 ...
- 3D屏保: 线圈
LineFlower3DSP 一个3D屏保程序,算法的原理类似于圆内轮旋线的生成. 下载地址: http://files.cnblogs.com/WhyEngine/LineFlower3D_sp.z ...
随机推荐
- jmeter 导入csv数据中json格式数据取值不完整
1.jmeter中添加csv数据文件时,数据是json格式 2.jmeter中执行取值发现只取了一部分 分析原因,json格式数据,中间有逗号,而csv是根据逗号来分割的,这回导致我们取值错位. 解决 ...
- Html5 学习笔记 【PC固定布局】 实战7 风景欣赏 联系我们
风景欣赏最终效果: 关于公司最终效果: 风景欣赏Html代码: <!DOCTYPE html> <html lang="zh-cn"> <head&g ...
- MongoDB Windows之ZIP安装
下载.下载地址同MSI下载地址:https://www.mongodb.com/download-center/community .Package选择Zip. 下载完成后解压到对应文件夹,该文件夹就 ...
- 这么简单的 Redis 面试题都不懂,怎么拿offer?
来源:mp.weixin.qq.com/s/daBkliC8dAT_zYyoLiS7WA 随着系统访问量的提高,复杂度的提升,响应性能成为一个重点的关注点.而缓存的使用成为一个重点.redis 作为缓 ...
- NOIP2015D1T2 信息传递
题目描述 有 n 个同学(编号为 1 到 n )正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为 i 的同学的信息传递对象是编号为 Ti 的同学. 游戏开始时,每人都只 ...
- ES6几大特性,让你的代码更优美
1.Default Parameters(默认参数) in ES6 还记得我们以前不得不通过下面方式来定义默认参数: var link = function (height, color, url ...
- smb.conf免密登录文件
# This is the main Samba configuration file. You should read the# smb.conf(5) manual page in order t ...
- [心得]Ubuntu無法ssh登入
裝好ssh後,發覺無法用root登入,可是sshd_config接正確. 後來發現原因在於,Ubuntu沒有root帳號,但是可以透過sudo -s拿到root權限. su root 密碼怎樣打也行不 ...
- android pull 解析器解析xml文档
person.xml <?xml version="1.0" encoding="UTF-8"?> <persons> <pers ...
- 使用while循环实现菜单