想法

利用随机数控制圆圈的大小、位置以及颜色,可以产生随机的美感。

让小球动起来,并且在屏幕边界处产生反弹效果。

代码

   1: float circle_x = (float) 0.0;

   2: float circle_y = (float) 0.0;

   3: float circle_radius = (float) 0.0;

   4: int circle_color = 0;

   5:  

   6: public void setup() {

   7:   size(displayWidth, displayHeight);

   8:   background(0);

   9:   frameRate(10);

  10: }

  11:  

  12: public void draw() {

  13:   

  14:   circle_x = random(0, displayWidth);

  15:   circle_y = random(0, displayHeight);

  16:   circle_radius = random(0, (displayWidth + displayHeight) / 20);

  17:   

  18:   circle_color = (int) random(0, 255);

  19:   

  20:   colorMode(RGB, 255);

  21:   fill(0,0,0,5);

  22:   rect(0, 0, displayWidth, displayHeight);

  23:   

  24:   noStroke();

  25:   colorMode(HSB, 255);

  26:   fill(circle_color, 255, 255);

  27:   ellipse(circle_x, circle_y, circle_radius, circle_radius);

  28:     

  29: }

截图

生成exe文件

将上述代码粘贴到Processing编辑器中,选择“Export Application”,导出成exe文件。

设置为屏幕保护程序

将exe文件更改后缀名为scr,右键->安装。

做一些变化

   1: float circle_x = (float) 0.0;

   2: float circle_y = (float) 0.0;

   3: float circle_radius = (float) 0.0;

   4: int circle_color = 0;

   5:  

   6: public void setup() {

   7:     size(displayWidth, displayHeight);

   8:     background(0);

   9:     frameRate(10);

  10: }

  11:  

  12: public void draw() {

  13:     

  14:       circle_x = random(0, displayWidth);

  15:       circle_y = random(0, displayHeight);

  16:       circle_radius = random(0, (displayWidth + displayHeight) / 5);

  17:       

  18:       circle_color = (int) random(0, 255);

  19:       

  20:       colorMode(RGB, 255);

  21: //      fill(0,0,0,5);

  22: //      rect(-1, -1, displayWidth+1, displayHeight+1);

  23:       

  24:       //noStroke();

  25:       colorMode(HSB, 255);

  26:       stroke(circle_color, 255, 255);

  27:       fill(circle_color, 255, 255);

  28:       noFill();

  29:       ellipse(circle_x, circle_y, circle_radius, circle_radius);

  30:       ellipse(circle_x, circle_y, circle_radius-1, circle_radius-1);

  31:         

  32: }

截图

运动的泡泡

   1: public static final int circle_nums = 200;

   2:  

   3: class BCircle

   4: {

   5:     public BCircle(float x, float y, float radius, float x_delta, float y_delta, int color) {

   6:         super();

   7:         this.x = x;

   8:         this.y = y;

   9:         this.radius = radius;

  10:         this.x_delta = x_delta;

  11:         this.y_delta = y_delta;

  12:         this.color = color;

  13:     }

  14:     private float x = (float) 0.0;

  15:     private float y = (float) 0.0;

  16:     private float radius = (float) 0.0;

  17:     

  18:     private float x_delta = (float) 0.0;

  19:     private float y_delta = (float) 0.0;    

  20:     private int color = 0; // 0 - 255

  21:     

  22:     private boolean valueInRange(float val, float min, float max)

  23:     {

  24:         return (val >= min >> val < max);

  25:     }

  26:     

  27:     public void moveOneStep()

  28:     {

  29:         if (valueInRange(x+x_delta, 0, displayWidth) >> 

  30:                 valueInRange(y+y_delta, 0, displayHeight))

  31:         {

  32:             x += x_delta;

  33:             y += y_delta;

  34:         }

  35:  

  36:         if (!valueInRange(x+x_delta, 0, displayWidth))

  37:         {

  38:             x_delta = -x_delta;

  39:             x += x_delta;

  40:         }

  41:         

  42:         if (!valueInRange(y+y_delta, 0, displayHeight))

  43:         {

  44:             y_delta = - y_delta;

  45:             y += y_delta;

  46:         }

  47:             

  48:     }

  49:     

  50:     public void draw(int theme)

  51:     {      

  52:         switch(theme)

  53:         {

  54:             case 1:

  55:             {

  56:                 noFill();

  57:                 colorMode(HSB, 255);

  58:                 stroke(color, 255, 255);

  59:                 ellipse(x, y, radius+2, radius+2);

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

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

  62:             }

  63:             break;

  64:             case 2:

  65:             {

  66:                 colorMode(HSB, 255);

  67:                 fill(color, 255, 255);

  68:                 ellipse(x, y, radius+2, radius+2);

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

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

  71:             }

  72:         }

  73:         

  74:     }

  75: }

  76:  

  77: List<BCircle> circles;

  78:  

  79: public void setup() {

  80:   size(displayWidth, displayHeight);

  81:   background(0);

  82:   frameRate(10);

  83:   

  84:   circles = new ArrayList<BCircle>(circle_nums);

  85: }

  86:  

  87: public void draw() {

  88:   

  89:     colorMode(RGB, 255);

  90:     fill(0,0,0,30);

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

  92:     

  93:     if (circles.size() < circle_nums)

  94:     {

  95:         float x = random(0, displayWidth);

  96:         float y = random(0, displayHeight);

  97:         float radius = random(20, (displayWidth + displayHeight) / 20);

  98:         float x_delta = random(-50, 50); 

  99:         float y_delta = random(-50, 50);

 100:         int color = (int) random(0, 255);

 101:         BCircle circle = new BCircle(x, y, radius, x_delta, y_delta, color);

 102:         

 103:         circles.add(circle);

 104:     }

 105:     

 106:     for(int i=0;i<circles.size();i++)

 107:     {

 108:         circles.get(i).moveOneStep();

 109:         circles.get(i).draw(1);

 110:     }    

 111: }

两种主题,截图

 

用processing生成屏保程序的更多相关文章

  1. 用Processing生成屏保(二)

    代码 1: class TPoint 2: { 3: public TPoint(int _x, int _y) { 4: super(); 5: this._x = _x; 6: this._y = ...

  2. wpf 制作播放视频的屏保程序、而且能分屏显示

    这个程序用到了WPF里  “visual_Brush”(主要是为了实现分屏显示) , “UserControl” ,这两个知识点: 在屏保状态下播放指定文件夹下的视频,而且能分屏显示: 把编译好的屏保 ...

  3. 用Qt写的简单屏保程序

    近日老大提别人家产品都有屏保程序,貌似我们也该有,简单在qtcn.org请教了一下,写了个小程序! 晕倒,半天没找到上传功能!我已经上传到qtcn上了,地址如下: http://www.qtcn.or ...

  4. WinForm 屏保程序

    this.ShowInTaskbar = false; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWind ...

  5. 3D屏保程序:汉诺塔

    学过程序的人一定记得汉诺塔.我们学的第一个程序是HelloWorld,而碰到的第一个坑就是汉诺塔,短短十几行代码,不知花费了多少时间精力去理解.我记得当年的开发环境还是蓝屏的,汉诺塔程序的输出还是一行 ...

  6. python写的屏保程序

    __author__ = 'ChenYan' from random import randint from tkinter import * class Randball(): def __init ...

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

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

  8. 3D屏保: 线圈

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

  9. 3D屏保:N皇后

    前几天园子里有人发表关于8皇后的算法.只有代码,没有能运行的DEMO多枯燥.于是我这两天抽时间写了个N皇后的屏保程序.程序启动后会从4皇后到14皇后显示其所有排列,每隔0.5秒自动切换一次.按下空格键 ...

随机推荐

  1. Window随笔 - Windows Server 2012 評估版與延長使用期限【转载】

    Windows Server 2012 評估版與延長使用期限 下載與安裝 至 微軟的評估中心 下載 Windows Server 2012 SP1 180 天軟體試用版 (Windows Server ...

  2. 加载的DAL数据访问层的类型

    using System; using System.Collections; using System.Reflection; using CSFrameworkV4_5.Core; using C ...

  3. Could not resolve placeholder'XXX' in string value "XXXX"

    练习SSM项目的demo中遇到一个问题,我在applicationContext.xml中使用了<context:property-placeholder location="clas ...

  4. setTimeout,clearTimeout,setInterval,clearInteral详解

    设置定时器,在一段时间之后执行指定的代码,setTimeout与setInterval的区别在于setTimeout函数指定的代码仅执行一次 方法一: window.setTimeout(" ...

  5. Head First Java 读书笔记(完整)

    第0章:学习方法建议 该如何学习Java? 1.慢慢来.理解的越多,就越不需要死记硬背.时常停下来思考. 2.勤作笔记,勤做习题. 3.动手编写程序并执行,把代码改到出错为止. 需要哪些环境和工具? ...

  6. 【转】linux下使用man查看C函数用法

    大家都知道在Unix/Linux中有个man命令,可以查询常用的命令,函数.可是对于我们这样只知道用"man 函数名"来查询的人来说,会遇到很多问题,比如: man read,我想 ...

  7. Sql Server Management Studio 18 打开闪退问题

    解决方案 找到MSSMS安装位置,例如我是安装到了D:\Program Files (x86)\Microsoft SQL Server Management Studio 18 将D:\Progra ...

  8. shell位置参数处理举例

  9. CNN基础一:从头开始训练CNN进行图像分类(猫狗大战为例)

    本文旨在总结一次从头开始训练CNN进行图像分类的完整过程(猫狗大战为例,使用Keras框架),免得经常遗忘.流程包括: 从Kaggle下载猫狗数据集: 利用python的os.shutil库,制作训练 ...

  10. c++后台开发面试常见知识点总结(五)场景设计

    搜索引擎的实现,会用到哪些重要的数据结构 设计实现一个HTTP代理服务器 / web服务器 / FTP服务器/ 设计实现cache缓存web服务器的网页访问记录 把一个文件快速下发到100w个服务器 ...