I understand the use of PGraphics now, but i’m still doing it wrong
//Global Variables
int c,r; //rows/coloms
int space=10; //space
int w=1920; //width of display
int h=1080;//height of display
float[][] tgrid;
float cloud=0;
PGraphics myLine;
PGraphics cloudfunction;
PGraphics starField;
void setup(){
size(1920,1080,P3D);
c=w/space;
r=h/space;
tgrid=new float [c][r];
myLine= createGraphics(width,height);
cloudfunction= createGraphics(width,height);
starField=createGraphics(width,height);
}
void draw(){
// for(int i=0;i<350;i++);
cloudfunction.beginDraw();
cloud-=0.04; //cloud speed
float moveY=cloud;
for(int y=0; y<r;y++){
float moveX=2;
for(int x=0; x<c;x++){
tgrid[x][y]=map(noise(moveX,moveY),0,1,-150,150);
moveX +=0.05;
}
moveY +=0.05;
}
background(0);
stroke(#4C6FEA);
noFill();
translate(width/2,height/2);
rotateX(PI/2.6);
translate(-w/2,-h/2);
for (int y=0; y<r-1;y++){
beginShape(TRIANGLES);
for(int x=0; x<c;x++){
vertex(x*space,y*space,tgrid[x][y]);
vertex(x*space,(y+1)*space,tgrid[x][y+1]);
}
endShape();
}
cloudfunction.endDraw();
image(cloudfunction,width,height);
starField.beginDraw();
starField(10,10,250,0,10,10,10);
starField.endDraw();
image(starField,width,height);
//myLine(140, 200, 1, 100, 1000, 1920, 100);
myLine.beginDraw();
myLine(#FFE079, 10, 20, -100, 0, 0, 30);
myLine.endDraw();
image(myLine,width,height);
//saveFrame("ball-####.jpg");
}
void myLine(int colour, int transparency, int weight, int size, int midpointX, int midpointY, int separation){
for(int y = 0; y < 2000; y = y + separation)
{
for (int x = 0; x < 2000; x = x + separation)
{
stroke(colour, transparency);
strokeWeight(weight);
line(midpointX, midpointY, x + size , y + size);
}
}
}
void starField(float xstar, float ystar,int rstar, int gstar, int bstar, int fRate1,int fRate2) {
frameRate(fRate1);
fill(0,30);
rect(0,0,width,height);
frameRate(fRate2);
fill(rstar,gstar,bstar);
noStroke();
ellipse(random(width),random(height),xstar,ystar);
}