关于processing

语法可以认为就是Java

运行:

processing-java --output=/tmp/processing-xx --run --force --sketch=/home/ning/soft/processing-2.0b8/modes/java/examples/Demos/Graphics/

最近在研究processing,下面是我对processing用法的简单总结

processing的语法比较类似于java

变量

区分大小写 类型: - int 整数 例:3, 20, -5, 0 - float浮点数 例:1.2301, -0.02 - String 字串 boolean True/False

坐标

判断

< == > != >= <= && || !

Object & Class

3D

pushMatrix();
translate(width/2, height/2);
rotateX(1);
box(150);
popMatrix();

这在需要多个坐标系的情况下很有用. 比如地球绕太阳公转.

lights(); //在draw里面调用即可.

看教程

一小时

http://wenku.baidu.com/view/ad62e7d6240c844769eaee08.html

Processing Tutorial 视频01-24 (7:29:00)

这个教程的一个好处是,还会介绍一些常用的库. 不介绍每个函数, ellipse, box 的参数, 很适合有程序经验的同学.

多个文件之间,想当于直接把多个文件放在一起执行. 同一个project 里面,不需要import

循环

for (int i=0;i<20;i++) {
  for (int j=0;j<20;j++) {
    if (i<10) {
      fill(255, 0, 0);
    }else{
      fill(255, 255, 0);
    }

    ellipse(i*20, j*20, 20, 20);

  }
}

函数

函数可以写在函数里面.

class

Ball myBall;
void setup() {
  size(600, 600);
  background(0);
  myBall = new Ball(500, 100);
}

void draw()
{
  myBall.display();
}

class Ball{
  int x = 500;
  int y = 500;

  Ball(int x, int y){
    this.x = x;
    this.y = y;
  }
  void display(){
    ellipse(x, y, 20, 20);
  }
}

数组

Ball[] balls = new Ball[20];

for (int i=0;i<balls.length;i++){
    balls[i] = new Ball(random(0, width), random(0, height), 5, 5);
}

ArrayList

发现和Java几乎一样, 不过Java 几乎都忘了.

不需要范型. 哈哈:

ArrayList myList;
mylist.add(new Ball(200, 200));
mylist.size();
mylist.get(1);

External Libraries

http://processing.org/reference/libraries/

如: http://toxiclibs.org/

放在 sketchbook 的libraries 下:

(ENV)[email protected] ~/idning/langtest/processing/sketchbook/libraries$ ll
total 32K
5022553 drwx------ 5 ning ning 4.0K 2013-03-09 11:29 verletphysics
5022577 drwx------ 5 ning ning 4.0K 2013-03-09 11:29 volumeutils
5022429 drwx------ 5 ning ning 4.0K 2013-03-09 11:29 audioutils
5022441 drwx------ 5 ning ning 4.0K 2013-03-09 11:29 colorutils
5022457 drwx------ 5 ning ning 4.0K 2013-03-09 11:29 datautils
5022470 drwx------ 5 ning ning 4.0K 2013-03-09 11:29 simutils
5022505 drwx------ 5 ning ning 4.0K 2013-03-09 11:29 toxiclibscore
5022495 drwx------ 5 ning ning 4.0K 2013-03-09 11:29 toxiclibs_p5

重启processing.

我们可以通过 $ cp -r libraries/ libs2 把libraries 当成一个sketch 浏览. 看它的例子:

toxiclib.Vec3d (11-12)

一个 Vec 表示一个点. (有x, y, z)

toxi 库里面的:

Vec3D loc = new Voc3D(0, 0, 0);
ellipse(loc.x, loc.y, 20, 20);

Vec3D speed = new Voc3D(1, 0, 0);

可以加减:

loc.addSelf(speed);
loc.normalize(); //变成1.
loc.scaleSelf(100); //乘以100.

注意, 向量加法(平行四边形)
Vec3D newVec = loc.add(speed) ; 不一样. 产生一个新的vec.

Agents

全局变量, 不分文件.

这是一个稍微复杂的 粒子模型. 可以模拟扩散, 聚合. (应该不是按照物理规律的.)

3D

PeasyCam

不兼容Processing 2.0

camera()

camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ)

The default values are camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0)

PeasyCam

实现鼠标控制的Cam, 很好.

A mouse driven camera-control library for 3D sketches.

UI

提供 滑块 等元素

Follow Mouse

这个我在flash 做过.

输出&输入

这个3d图不错.

PrintWriter output;
output = createWrite("data/points.csv");

if (keyPressed) {
  for (int i=0; i<cols; i++) {
    for (int j=0; j<cols; j++) {
      Vec3D loc = grid[i][j].loc;
      output.println(loc.x + "," + loc.y + "," + loc.z);
    }
  }

  output.flush();
  output.close();
}

注意单引号,双引号不同.

例子

递归(t19, 520)

很简单, 可以自己实现

Game of Life

实现Spring

这也是我从前用Flash 搞过 . 它用的是 toxi 的VerletPhyiscs 库.

verlet VerletParticle. 粒子. VerletSpring. 弹簧.

GravityBehavior()

粒子落下效果

织网效果

时间: 2024-12-11 15:41:58

关于processing的相关文章

Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n

错误如下: 2017-09-19 15:05:24.659 INFO 9986 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]56528192: startup date [Tue Sep 19 15:05:24 CST 2017]; root of context hierarchy 2017-09-19 15:05:24.858 INFO 9986 --

Multithreading Batch Processing Framework

1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # Author: f0rsaken 4 5 import argparse 6 import importlib 7 import sys 8 import threadpool 9 import time 10 11 def main(): 12 parser = argparse.ArgumentParser(description="Multithreading Batch Proce

SNC processing failed_SAProuter_证书重新生成

文章为原创,转载请联系我,欢迎交流[email protected] 参照note 1178684 - No service connection: "SNC processing failed" 确认证书所在位置 Execute the following commands on your SAProuter machine: sapgenpse seclogin -l sapgenpse get_my_name -n validity 在cmd直接运行报错 利用everything

DirectX Video Processing AppWizard--CDxVideoGraphBase

http://www.ifp.illinois.edu/~chenyq/research/Utils/DxVideoAppWiz/DxVideoAppWiz.html 一个非常棒的DirectX Video Processing AppWizard,备忘.

转: rdlc报表An error occurred during local report processing错误

在开发环境的电脑上可生成报表,但是一到客户端就提示An error occurred during local report processing错误. 猜想是缺dll,补充上 Microsoft.ReportViewer.Common.dll Microsoft.ReportViewer.WinForms.dll 结果问题依旧,难道还缺? google后得知还缺一个 Microsoft.ReportViewer.ProcessingObjectModel.dll 这个可不好找,在C:\Wind

如何解决“Error detected while processing /root/.vimrc:”

使用crontab -e添加定时任务时,遇到如下错误"Error detected while processing /root/.vimrc:": [root@~]# crontab -e Error detected while processing /root/.vimrc: line 30: E518: Unknown option: fdm=syntax line 34: E518: Unknown option: autochdir 第一种方法: 直观地,根据提示,应该是不

解决方法:An error occurred on the server when processing the URL. Please contact the system administrator

在WINDOWS7或SERVER2008上安装了IIS7.5,调试ASP程序时出现以下错误: An error occurred on the server when processing the URL. Please contact the system administrator 解决方法如下:     设置方法一: 以管理员身份运行CMD,将目录定位到%windir%\system32\inetsrv\,然后执行appcmd set config -section:asp -script

【processing】小代码

今天无意间发现的processing 很有兴趣 实现很简洁 void setup(){ } void draw(){ background(255); if(mouseX < width/2 && mouseY > height/2) { fill(0); rect(0,height/2,width/2,height/2); } } 这个小小的代码可以实现 当鼠标位于画布左下方时显示一个黑色的框 -----------------------------------------

数据可视化之Processing【1】

说Processing之前得先说一下数据可视化 数据可视化--顾名思义,是关于数据之视觉表现形式的研究,将数据用其他方式表现出来,使之更直观, 更清晰,更容易分析和处理,常见的表达方式如word中使用广泛的直方图.树状图.折线图.饼状图等. 数据可视化技术的基本思想是将数据库中每一个数据项作为单个图元元素表示,大量的数据集构成数据 图像,同时将数据的各个属性值以多维数据的形式表示,可以从不同的维度观察数据,从而对数据进行 更深入的观察和分析. 我们知道,单纯的一连串数字摆在人们眼前很难分析其特点

HDU 3049 Data Processing 数论题解

Problem Description Chinachen is a football fanatic, and his favorite football club is Juventus fc. In order to buy a ticket of Juv, he finds a part-time job in Professor Qu's lab. And now, Chinachen have received an arduous task--Data Processing. Th