用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 ...
随机推荐
- Java学习之多线程(定义)
进程:正在运行中的程序线程:负责执行程序的控制单元(执行路径)一个进程中可以有多个执行路径,称之为多线程一个进程中至少要有一个线程 创建新执行线程有两种方式 一.继承Thread类步骤:1.定义一个类 ...
- iterm2简易登录服务器
文章目录 添加文件 添加配置 直接登录 方法一 方法二 添加文件 在mac任意目录添加 10.0.1.1.txt ,这里的名字可以随意起,也可以不是txt #!/usr/bin/expect set ...
- 安装Elasticsearch5.4.0以及head,kibana插件
可以在网盘中下载也可以去官网下载 网盘: Elasticsearch 地址:http://pan.baidu.com/s/1hrI0AFU elasticsearch-head 地址:http:// ...
- 《单词的减法》state1~state17(第二遍学习记录)
单词的减法(二) 2016.05.18.2016.05.21 state 1 advisory 顾问的,劝告的 anticipate/participate 期望/参加 state 2 applian ...
- vue (UI)
- element checkbox 勾选时出现弹框提示。
复选框选中的时候,必须提示是否确定选中,取消勾选的时候也要. 不能解决的思路: 1.element的checkbox只有一个change事件,该事件只返回该选项最新的值(true,false)(不会返 ...
- linux随笔-01
认识linux 开源共享精神 低风险 高品质 低成本 更透明 开源软件的特点 使用自由.修改自由.传播自由.收费自由以及创建衍生品的自由 常见的开源许可协议 GNU GPL(GNU General P ...
- 2019HDU多校训练第三场 Planting Trees 暴力 + 单调队列优化
题意:有一个n * n的网格,每个网格中间有一颗树,你知道每棵树的高,你可以选择一个矩形区域把里面的树都围起来,但是矩形区域里面任意两棵树的高度差的绝对值不超过m,问这个矩形的最大面积是多少? 思路: ...
- SessionFactory是线程安全的吗?Session是线程安全的吗?两个线程能共享一个Session吗?
(1)SessionFactory对应Hibernate的一个数据存储的概念,它是线程安全的,可以被多个线程并发访问.SessionFactory一般只会在启动的时候构建.对于应用程序,最好将Sess ...
- jquey弹出框demo
默认 $('#btn-01').click(function(){ $.dialog({ contentHtml : '<p>我是默认弹出对话框示例展示.我只是用来占位的内容展示,仅仅用来 ...