programing studying notes no.1--用processing描述球体碰撞
来源:互联网 发布:nginx tcp 域名重定向 编辑:程序博客网 时间:2024/05/16 13:48
i will use this blog to track down my programing life.
these days,i am focousing on processing.how to imitate balls colliding,this is what i am thinking.
and this below is what i get gradually:
--------------------------------------this is the first one i make ,only one ball-----------------------------------------
Circle mycircle;void setup(){ size(400,400); smooth(); mycircle=new Circle();}void draw(){ background(255); mycircle.move(); mycircle.judge(); mycircle.display(); }class Circle{ float x; float y; int r; float angle; Circle() { x=100; y=100; r=20; angle=HALF_PI-20; } void move() { x+=5*cos(angle); y+=5*sin(angle); } void judge() { if(y+r>=400||y-r<=0) angle=2*PI-angle; if(x+r>=400||x-r<=0) angle=3*PI-angle; } void display() { ellipse(x,y,2*r,2*r); }}
------------------------------------the second one---------------------------------
Circle mycircle0;Circle mycircle1;Circle mycircle2;void setup(){ size(400,400); smooth(); mycircle0=new Circle(200,200,60); mycircle1=new Circle(250,320,160); mycircle2=new Circle(100,150,250); }void draw(){ background(0); mycircle0.move(); mycircle0.judge(); mycircle0.display(); mycircle1.move(); mycircle1.judge(); mycircle1.display(); mycircle2.move(); mycircle2.judge(); mycircle2.display(); }class Circle{ float x; float y; int r; float angle;Circle(int xx,int yy,int zz) { x=xx; y=yy; r=20; angle=HALF_PI-zz; } void move() { x+=5*cos(angle); y+=5*sin(angle); } void judge() { if(y+r>=400||y-r<=0) angle=2*PI-angle; if(x+r>=400||x-r<=0) angle=3*PI-angle; } void display() { fill(255,0,0); ellipse(x,y,2*r,2*r); }}
------------------------------the third one--------------------------------
int M=5;int speed=5;Circle [] mycircle=new Circle[M];int k=0;int c=255;void setup(){ size(400,400); smooth(); for(int i = 0; i < M; i ++) { mycircle[i] =new Circle(random(50,300),random(50,300),random(50,300)); }}void draw(){ background(0); for(int i = 0; i < M; i ++) { mycircle[i].move(); mycircle[i].judge(); mycircle[i].display(); for(int j = 0; j < M; j ++) { if(i!=j) { if(dist(mycircle[i].x,mycircle[i].y,mycircle[j].x,mycircle[j].y)<=mycircle[i].r+mycircle[j].r) { c=(int)random(20,240); k++; float m; m=atan((mycircle[i].y-mycircle[j].y)/(mycircle[i].x-mycircle[j].x)); mycircle[i].angle=PI-mycircle[i].angle-2*m; mycircle[j].angle=PI-mycircle[j].angle-2*m; println("cash in NO "+k); } } } } }class Circle{ float x; float y; int r; float angle;Circle(float xx,float yy,float zz) { x=xx; y=yy; r=(int)random(12,20); angle=HALF_PI-zz; } void move() { x+=speed*cos(angle); y+=speed*sin(angle); } void judge() { if(y+r>=400||y-r<=0) angle=2*PI-angle; if(x+r>=400||x-r<=0) angle=3*PI-angle; } void display() { fill(c,255,0); ellipse(x,y,2*r,2*r); }}
from this i learn:math is of great importance; learning can be intersting.
0 0
- programing studying notes no.1--用processing描述球体碰撞
- C Programing Lanuage Notes
- J2EE - Notes For Studying
- Scala Studying Notes
- 2d球体碰撞
- Notes of studying Oracle 11g database (1)
- ACE studying notes(continuing update....)
- some studying matlab notes(reprinted)
- OGRE 碰撞检测之球体检测
- Natrual Language Processing Technical Notes
- 碰撞描述类 collision
- my original studying notes for readn(),writen(),and readline() function
- QGraphicsItem中的碰撞检测描述
- Matlab studying~程序设计1
- 用球体模拟天空
- OO Programing in C (1)
- Processing - 1
- Studying note 1 of mysql
- Mysql优化之问题定位
- 索引ListView
- AndroidStudio启动异常:Caused by: java.lang.IllegalArgumentException: Argument for @NotNull paramet
- HDU 1171 Big Event in HDU(01背包问题)
- maven的安装配置
- programing studying notes no.1--用processing描述球体碰撞
- Maven详解之仓库------本地仓库、远程仓库
- HDU 5492 Find a path
- 在Win32上用VC编译nginx
- Maven安装及与Eclipse集成
- Binary Tree Zigzag Level Order Traversal
- HDU 1196 Lowest Bit(水~)
- 条款20:宁以pass-by-reference-to-const替换pass-by-value
- Cannot open the disk 'F:\vmvare2\shared40' or one of the snapshot disks it depends on.