Draw a consecutive curve
in
Programming Questions
•
2 years ago
Hello everyone, I have a big problem with curve function in Processing. Recently, I want to draw a dynamic picture with hills, clouds and even a sun. But I don't know how to draw a continuous curve, only one way I can come up with is to create two arrays. In my mind, the height of hills is random and hills will move from right to left. After I tried several ways, the hills always interrupt. Can anyone give me some examples? Or tell me another way to create hills. Thanks everyone reads my question. Here is my code:
- int widths=500;
- int heights=500;
- int arr_size=15;
- int[] arrayx1 = new int[arr_size];
- int[] arrayy1 = new int[arr_size];
- int[] arrayx2 = new int[arr_size];
- int[] arrayy2 = new int[arr_size];
- int distance=50;
- int gap=50;
- void setup()
- {
- size(500,500);
- smooth();
- frameRate(10);
- for(int i=0;i<arr_size;i++)
- {
- arrayx1[i]=widths+gap+50*i;
- arrayy1[i]=heights/2;
- arrayx2[i]=widths+gap+600+50*i;
- arrayy2[i]=heights/2;
- }
- }
- int condition=1;
- static int i=0;
- static int j=0;
- void draw()
- {
- background(255);
- noStroke();
- fill(0,0,255);
- int k;
- int decision;
- stroke(0);
- fill(255);
- if(arrayx2[2]==50 && condition==1)
- {
- condition=2;
- for(k=0;k<arr_size;k++)
- {
- arrayx1[k]=widths+gap+50*k;
- arrayy1[k]=heights/2;
- }
- }
- else if(arrayx1[2]==50 && condition==2)
- {
- condition=1;
- for(k=0;k<arr_size;k++)
- {
- arrayx2[k]=widths+gap+50*k;
- arrayy2[k]=heights/2;
- }
- }
- decision=int(random(2));
- if((arrayy1[i]==heights/2 && j==0) || i==1 || j==12)
- {
- arrayy1[1]=arrayy2[13];
- while(arrayy1[i]==heights/2)
- {
- if(decision==0)
- arrayy1[i]= arrayy1[i]+int(random(distance));
- else
- arrayy1[i]= arrayy1[i]-int(random(distance));
- }
- i++;
- if(i==15)
- i=0;
- }
- if((arrayy2[j]==heights/2 && i==0) || j==1 || i==12)
- {
- arrayy2[1]=arrayy1[13];
- while(arrayy2[j]==heights/2)
- {
- if(decision==0)
- arrayy2[j]= arrayy2[j]+int(random(distance));
- else
- arrayy2[j]= arrayy2[j]-int(random(distance));
- }
- j++;
- if(j==14)
- j=0;
- }
- for(k=0;k<arr_size;k++)
- {
- arrayx1[k]=arrayx1[k]-50*widths/500;
- arrayx2[k]=arrayx2[k]-50*widths/500;
- }
- for(k=0;k<arr_size-3;k++)
- {
- curve(arrayx1[k],arrayy1[k],arrayx1[k+1],arrayy1[k+1],arrayx1[k+2],arrayy1[k+2],arrayx1[k+3],arrayy1[k+3]);
- curve(arrayx2[k],arrayy2[k],arrayx2[k+1],arrayy2[k+1],arrayx2[k+2],arrayy2[k+2],arrayx2[k+3],arrayy2[k+3]);
- }
- }
- static int num=0;
- void mousePressed()
- {
- if(num%2==0)
- {
- noLoop();
- num++;
- }
- else
- {
- loop();
- num++;
- }
- }
1