昨晚上在豆瓣浏览关于arduino的内容时注意到了Processing. 很高兴它是一个开源的框架,并且其语法是JAVA语言并且简化了很多。并且支持现在所有主流的操作系统。对了,早前jquery的作者也把一大部分的功能移植到了WEB上面。对于前端开发者去学习是个好消息。
http://processing.org/learning/ 在官网看到了些教程,写的非常不错。
他主要程序运行的结构是
void setup(){}
void draw(){}
这个结构是比较固定的
其他自定义的方法还是比较随意。
系统封装监听事件 还有
void keyPressed(){ } void mousePressed(){}
分别是 监听键盘和鼠标按下事件,还有好多简化方法不再一一赘述以后的学习笔记再说明。
今天主题是对程序的hello world
/** * * Sketching with Processing. * KnowledgePoint :stroke(255) * Author: TingChao.Guo **/
void setup(){ size(300,300); background(0,0,0); stroke(255); line(150,25,270,350); } void draw(){ stroke(255); // sets the stroke color to white line(150,25,270,450); stroke(255, 255, 255); // identical to the line above line(150,25,270,550); stroke(255, 128, 0); // bright orange (red 255, green 128, blue 0) line(150,25,270,650); stroke(#FF8000); // bright orange as a web color line(150,25,270,750); stroke(255, 128, 0, 128); // bright orange with 50% transparency line(150,25,270,850); }
结果图:
写一个完整点的:
/** * * Sketching with Processing. * KnowledgePoint :stroke(255) * Author: TingChao.Guo * * */ int radius=180; int degree=0; void setup() { size(500, 500); background(0, 0, 0); strokeWeight(3); smooth(); } void draw() { float angle = radians(degree); float x =250 + (cos(angle) * radius); float y =250 + (sin(angle) * radius); stroke(random(256), random(256), random(256), random(256)); line(x,y,250,250); print("x :"+x+'\t'); print("angle :"+x+'\t'); print("y :"+y+'\t'+'\n'); degree++; delay(300); }