Difference between revisions of "Array"

From Design Computation
Jump to: navigation, search
(Created page with "Category:Processing Category:.PDE An array is a list of data. Each piece of data in an array is identified by an index number representing its position in the array....")
 
Line 1: Line 1:
[[Category:Processing]]
+
[[Category:Processing Code]]
 
[[Category:.PDE]]
 
[[Category:.PDE]]
 +
[[Category:Code]]
 +
[[Category:Scripts]]
  
 
An array is a list of data. Each piece of data in an array is identified by an index number representing its position in the array. Arrays are zero based, which means that the first element in the array is [0], the second element is [1], and so on.  
 
An array is a list of data. Each piece of data in an array is identified by an index number representing its position in the array. Arrays are zero based, which means that the first element in the array is [0], the second element is [1], and so on.  

Revision as of 17:40, 18 December 2018


An array is a list of data. Each piece of data in an array is identified by an index number representing its position in the array. Arrays are zero based, which means that the first element in the array is [0], the second element is [1], and so on.

In this example, an array named "coswave" is created and filled with the cosine values. This data is displayed three separate ways on the screen.

Synonyms

Definition

Application

Processing

float[] coswave;

void setup() {

 size(640, 360);
 coswave = new float[width];
 for (int i = 0; i < width; i++) {
   float amount = map(i, 0, width, 0, PI);
   coswave[i] = abs(cos(amount));
 }
 background(255);
 noLoop();

}

void draw() {

 int y1 = 0;
 int y2 = height/3;
 for (int i = 0; i < width; i++) {
   stroke(coswave[i]*255);
   line(i, y1, i, y2);
 }
 y1 = y2;
 y2 = y1 + y1;
 for (int i = 0; i < width; i++) {
   stroke(coswave[i]*255 / 4);
   line(i, y1, i, y2);
 }
 
 y1 = y2;
 y2 = height;
 for (int i = 0; i < width; i++) {
   stroke(255 - coswave[i]*255);
   line(i, y1, i, y2);
 }
 

}

Cross-References

Recommended Reading

[1]