int amount = 500; int [] a= new int[amount]; int [] b= new int[amount]; int [] d= new int[amount]; int t; void setup(){ size(1024, 768,P3D); background(0); noFill(); stroke(255); t = 5; point();// must write here and write void point below } void draw(){ background(0); pushMatrix(); translate(width/2,height/2+500); rotateY(frameCount/1000.0);// translate rate for(int i = 0; i<amount; i++){//for loop, when i is smaller than amount i plus one in one time point(a[i],b[i],d[i]);// position x,y,z strokeWeight(random(1,3));// bian kuang cu xi, this is the bian kuang of point, which means the size of star. } strokeWeight(1); speedS = 5; sphere(500); popMatrix(); delay(10); } void point (){ strokeWeight(t); for (int i = 0; i<amount; i++){ a[i] = int(random(-800,800)); b[i] = int(random(-800,300)); d[i] = int(random(-800,800)); } }
Add a gradient background
int amount = 1000; int [] a = new int[amount]; int [] b = new int[amount]; int [] d = new int[amount]; void setup(){ size(1000,1000,P3D); noFill(); stroke(255); point(); //line(); } void draw(){ pushMatrix(); stroke(255); translate(width/2,height/2+500); rotateY(frameCount/300.0); strokeWeight(1); sphere(500); for (int j = 0; j<amount; j++){ point(a[j],b[j],d[j]); strokeWeight(random(1,3)); } popMatrix(); color from = color(0); color to = color(#150D6C); for (int i = 0; i<height;i++){ float amt = map(i,0,height,0,1); color c = lerpColor(from, to, amt); stroke(c); line(0,i,height,i); } } void point(){ for (int j = 0; j<amount;j++){ a[j] = int(random(-800,800)); b[j] = int(random(-800,300)); d[j] = int(random(-800,800)); } }
遇到和之前差不多的问题不过这次很快就解决了
改动一个地方(比如说之改动背景颜色怎么不让这个改动到别的地方 比如同时改动了球的颜色)
解决办法:for loop弄混了 如果不同的array变量要用不同的字母(i,j…) 分别写一个for loop并且括号分开 不为包含关系