SlideShare a Scribd company logo
1 of 8
Generative Coding
arrays
• Using variables , we can store information at one step in the program
for use at a later time. We store a single value per variable. Arrays now
allow us to cache multiple values ​​at once. An array is a list of
variables where each element has the same data type . An array is a
data structure.
Declaration of an array
• Arrays must be declared like variables before they can be used, except that there are square brackets after the data type:
// Declaration of an integer variable
int number;
// declaration of an integer array
int [] numbers;
To initialize an array, we need to define the length of the array . The length determines how many elements can be stored in the array.
In the following example we define our array numbers so that five elements (of type int) can be stored in it, and the other array positionen so that we float
can store 30 elements, i.e. 30 values.
// Array with five integer elements
int [] numbers = new int [5];
// Array of thirty point number elements
float [] positions = new float [30];
An array is initialized like this: new data type[length]; so for example new float[4];
Access to individual items
• We can access each item through an index . This index is always an integer and starts with 0 . Each element
is of the same data type and can be used like a normal variable. When we access a single element of the array,
we can read and write its value.
• Here we see how to assign new values ​​to the elements of an array
int x = 5;
int [] numbers = new int [5];
numbers[0] = 100;
numbers[1] = 255;
numbers[2] = 2;
numbers[3] = width ;
numbers[4] = 10 * x;
Access to individual items
• We can use the individual elements as well as variables:
int x = new numbers[4];
int y = 4;
y = y + numbers[3];
line (x, y, numbers[1], numbers[2]);
• And of course we can also use a variable or expressions for the index:
int number = 10;
// Be it initialization
char [] character = new char [number];
// Or when accessed
int i = 5;
numbers[i] = numbers[2 + 1];
Arrays & Loops
• When using or computing a lot of similar data, arrays are very useful.
• For example, if we wanted to animate a ball, we had to store its
position and speed in variables: x, y, vx, vy. If not just one but several
balls are to be displayed, you would have to use four variables per ball
( x2, y2, vx2, vy2, x3, y3, ...), which would be very tedious. Instead, we
can use arrays.
• So the purpose of arrays is that we can store many of the same kind
of variables together — and save us a lot of unnecessary typing and
programming.
Using arrays
• In order to access each element, we can either specify each position
individually ( ), or access all of them numbers[3] using a for loop .
• We can then use the counter variable of a for loop directly as an
index:
int [] numbers = new int [5];
for ( int i = 0; i < 5; i++) {
numbers[i] = i * 10;
}
Example:
draws ten circles using the values ​​of two arrays as positions.
float [] x = new float [10];
float [] y = new float [10];
Void setup ( ) {
size (200, 200);
// Initialize all elements of both arrays
for ( int i = 0; i < 10; i++) {
x[i] = random ( width );
y[i] = random ( height );
}
}
void draw () {
// Draw circles using a loop and the arrays
for ( int i = 0; i < 10; i++) {
ellipse (x[i], y[i], 20, 20);
}
]

More Related Content

Similar to Generative Coding Lecture notes using coding

Similar to Generative Coding Lecture notes using coding (20)

Learn Java Part 9
Learn Java Part 9Learn Java Part 9
Learn Java Part 9
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Learn Java Part 8
Learn Java Part 8Learn Java Part 8
Learn Java Part 8
 
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
 
2 arrays
2   arrays2   arrays
2 arrays
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
CHAPTER-5.ppt
CHAPTER-5.pptCHAPTER-5.ppt
CHAPTER-5.ppt
 
Lecture_01.2.pptx
Lecture_01.2.pptxLecture_01.2.pptx
Lecture_01.2.pptx
 
C96e1 session3 c++
C96e1 session3 c++C96e1 session3 c++
C96e1 session3 c++
 
arrayy.ppt
arrayy.pptarrayy.ppt
arrayy.ppt
 
Week06
Week06Week06
Week06
 
Cso gaddis java_chapter8
Cso gaddis java_chapter8Cso gaddis java_chapter8
Cso gaddis java_chapter8
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Lecture 6 - Arrays
Lecture 6 - ArraysLecture 6 - Arrays
Lecture 6 - Arrays
 
Array lecture
Array lectureArray lecture
Array lecture
 
Array
ArrayArray
Array
 
Array-part1
Array-part1Array-part1
Array-part1
 
Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
Introduction to programming class 11 exercises
Introduction to programming   class 11 exercisesIntroduction to programming   class 11 exercises
Introduction to programming class 11 exercises
 

Recently uploaded

The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdfThe_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdfAmirYakdi
 
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵anilsa9823
 
VIP Call Girls Bhiwandi Ananya 8250192130 Independent Escort Service Bhiwandi
VIP Call Girls Bhiwandi Ananya 8250192130 Independent Escort Service BhiwandiVIP Call Girls Bhiwandi Ananya 8250192130 Independent Escort Service Bhiwandi
VIP Call Girls Bhiwandi Ananya 8250192130 Independent Escort Service BhiwandiSuhani Kapoor
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...Call Girls in Nagpur High Profile
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightDelhi Call girls
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentationamedia6
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Douxkojalkojal131
 
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...Amil baba
 
VIP Kolkata Call Girl Gariahat 👉 8250192130 Available With Room
VIP Kolkata Call Girl Gariahat 👉 8250192130  Available With RoomVIP Kolkata Call Girl Gariahat 👉 8250192130  Available With Room
VIP Kolkata Call Girl Gariahat 👉 8250192130 Available With Roomdivyansh0kumar0
 
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130Suhani Kapoor
 
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk GurgaonCheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk GurgaonDelhi Call girls
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsCharles Obaleagbon
 
PODSCAPE - Brochure 2023_ prefab homes in Bangalore India
PODSCAPE - Brochure 2023_ prefab homes in Bangalore IndiaPODSCAPE - Brochure 2023_ prefab homes in Bangalore India
PODSCAPE - Brochure 2023_ prefab homes in Bangalore IndiaYathish29
 
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...Suhani Kapoor
 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...Suhani Kapoor
 
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779Delhi Call girls
 

Recently uploaded (20)

The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdfThe_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
The_Canvas_of_Creative_Mastery_Newsletter_April_2024_Version.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
 
VIP Call Girls Bhiwandi Ananya 8250192130 Independent Escort Service Bhiwandi
VIP Call Girls Bhiwandi Ananya 8250192130 Independent Escort Service BhiwandiVIP Call Girls Bhiwandi Ananya 8250192130 Independent Escort Service Bhiwandi
VIP Call Girls Bhiwandi Ananya 8250192130 Independent Escort Service Bhiwandi
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
 
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
 
escort service sasti (*~Call Girls in Prasad Nagar Metro❤️9953056974
escort service sasti (*~Call Girls in Prasad Nagar Metro❤️9953056974escort service sasti (*~Call Girls in Prasad Nagar Metro❤️9953056974
escort service sasti (*~Call Girls in Prasad Nagar Metro❤️9953056974
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentation
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
 
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
 
VIP Kolkata Call Girl Gariahat 👉 8250192130 Available With Room
VIP Kolkata Call Girl Gariahat 👉 8250192130  Available With RoomVIP Kolkata Call Girl Gariahat 👉 8250192130  Available With Room
VIP Kolkata Call Girl Gariahat 👉 8250192130 Available With Room
 
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
 
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk GurgaonCheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past Questions
 
PODSCAPE - Brochure 2023_ prefab homes in Bangalore India
PODSCAPE - Brochure 2023_ prefab homes in Bangalore IndiaPODSCAPE - Brochure 2023_ prefab homes in Bangalore India
PODSCAPE - Brochure 2023_ prefab homes in Bangalore India
 
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
VIP Russian Call Girls in Gorakhpur Deepika 8250192130 Independent Escort Ser...
 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
 
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
 

Generative Coding Lecture notes using coding

  • 2. arrays • Using variables , we can store information at one step in the program for use at a later time. We store a single value per variable. Arrays now allow us to cache multiple values ​​at once. An array is a list of variables where each element has the same data type . An array is a data structure.
  • 3. Declaration of an array • Arrays must be declared like variables before they can be used, except that there are square brackets after the data type: // Declaration of an integer variable int number; // declaration of an integer array int [] numbers; To initialize an array, we need to define the length of the array . The length determines how many elements can be stored in the array. In the following example we define our array numbers so that five elements (of type int) can be stored in it, and the other array positionen so that we float can store 30 elements, i.e. 30 values. // Array with five integer elements int [] numbers = new int [5]; // Array of thirty point number elements float [] positions = new float [30]; An array is initialized like this: new data type[length]; so for example new float[4];
  • 4. Access to individual items • We can access each item through an index . This index is always an integer and starts with 0 . Each element is of the same data type and can be used like a normal variable. When we access a single element of the array, we can read and write its value. • Here we see how to assign new values ​​to the elements of an array int x = 5; int [] numbers = new int [5]; numbers[0] = 100; numbers[1] = 255; numbers[2] = 2; numbers[3] = width ; numbers[4] = 10 * x;
  • 5. Access to individual items • We can use the individual elements as well as variables: int x = new numbers[4]; int y = 4; y = y + numbers[3]; line (x, y, numbers[1], numbers[2]); • And of course we can also use a variable or expressions for the index: int number = 10; // Be it initialization char [] character = new char [number]; // Or when accessed int i = 5; numbers[i] = numbers[2 + 1];
  • 6. Arrays & Loops • When using or computing a lot of similar data, arrays are very useful. • For example, if we wanted to animate a ball, we had to store its position and speed in variables: x, y, vx, vy. If not just one but several balls are to be displayed, you would have to use four variables per ball ( x2, y2, vx2, vy2, x3, y3, ...), which would be very tedious. Instead, we can use arrays. • So the purpose of arrays is that we can store many of the same kind of variables together — and save us a lot of unnecessary typing and programming.
  • 7. Using arrays • In order to access each element, we can either specify each position individually ( ), or access all of them numbers[3] using a for loop . • We can then use the counter variable of a for loop directly as an index: int [] numbers = new int [5]; for ( int i = 0; i < 5; i++) { numbers[i] = i * 10; }
  • 8. Example: draws ten circles using the values ​​of two arrays as positions. float [] x = new float [10]; float [] y = new float [10]; Void setup ( ) { size (200, 200); // Initialize all elements of both arrays for ( int i = 0; i < 10; i++) { x[i] = random ( width ); y[i] = random ( height ); } } void draw () { // Draw circles using a loop and the arrays for ( int i = 0; i < 10; i++) { ellipse (x[i], y[i], 20, 20); } ]