Skip to main content
MyCourses MyCourses
  • Schools
    School of Arts, Design, and Architecture (ARTS) School of Business (BIZ) School of Chemical Engineering (CHEM) –sGuides for students (CHEM) – Instructions for report writing (CHEM) School of Electrical Engineering (ELEC) School of Engineering (ENG) School of Science (SCI) Language Centre Open University Library Aalto university pedagogical training program UNI (exams) Sandbox
  • CORONAVIRUS INFO
    Koronavirus - tietoa opiskelijalle Coronavirus - information for students Coronavirus - information för studerande Koronaviruksen vaikutus opiskeluun: kysymyksiä ja vastauksia Effects of the coronavirus on studies: questions and answers Coronaviruset och studierna: frågor och svar Corona help for teachers
  • Service Links
    MyCourses - Instructions for Teachers - Teacher book your online session with a specialist - Digital tools for teaching - Personal data protection instructions for teachers - Instructions for Students - Workspace for thesis supervision WebOodi Into portal for students Courses.aalto.fi Library Services - Resourcesguides - Imagoa / Open science and images IT Services Campus maps - Search spaces and see opening hours Restaurants in Otaniemi ASU Aalto Student Union Aalto Marketplace
  • ALLWELL?
    Study Skills Support for Studying Starting Point of Wellbeing About AllWell? study well-being questionnaire
  •   ‎(en)‎
      ‎(en)‎   ‎(fi)‎   ‎(sv)‎
  • Toggle Search menu
  • Hi guest! (Log in)

close

DOM-E5152 - Introduction to Creative Coding, 08.09.2020-25.09.2020

  1. Home
  2. Courses
  3. school of art...
  4. Department of Media
  5. dom-e5152 - i...
  6. Sections
  7. Day 6
Syllabus

Day 6

  • Day 6

    Day 6

    Arrays (taulukot)

    So far we’ve used variables, which let you store single values and work with them. Often we need to process large amounts of data, and single variables aren’t enough for that. Arrays let you store multiple values of similar type. Like variables, arrays too have: a name, a type, value(s), and a scope. In addition to that they have size, which is the amount of members in the array. So, if a variable is a box, an array would be a pile of those boxes.

    An array can be declared the following way:

    int ourstuff[] = {2,4,6,7,8};

    After this line ourstuff is at our disposal and contains five numbers. It’s possible to create arrays also without assigning any values, only specifying their size. An array with 100 members:

    int ourstuff[] = new int[100];

    Array members (also known as items) can be used exactly like variables, through referencing (viittaus):

    ourstuff[1]=2;
    ellipse(ourstuff[1],ourstuff[2], 10,10);

    The number inside the brackets is known as index. The first index in C-like languages such as Java and Processing is zero. So, for ourstuff the indices are in the range 0..4

    Arrays and loops

    In general, arrays go together with loops, especially for loops. With a loop you can walk through all the members of the array when needed. The loop counter is used as the index. See here for an example: arrayloop.pde

    Often we don’t know the size of the array beforehand, or its size might change. A safe way to go through all the items is to use the length property that all arrays have:

    for(i=0; i<ourstuff.length; i++)

    Homework

    Make an array that holds the following data set consisting of consecutive x and y coordinates and colors:

    100,100,#ff0000, 500,200,#00ff00, 300,500,#0000ff, 200,400,#808080

    Plot it from the array using a loop. The outcome should look like this:

    Plot

    Ver solución: dataplot.pde

    Previous section

    ◄Day 5

    Next section

    Day 7►
    Skip Upcoming events
    Upcoming events
    Loading There are no upcoming events
    Go to calendar...
    • DOM-E5152 - Introduction to Creative Coding, 08.09.2020-25.09.2020
    • Sections
    • General
    • Materials
    • Assignments
    • Day 1
    • Day 2
    • Day 3
    • Day 4
    • Day 5
    • Day 6
    • Day 7
    • Day 8
    • Day 9
    • Day 10
    • Day 11
    • Day 12
    • Home

    Aalto logo

    Tuki / Support
    • MyCourses help
    • mycourses(at)aalto.fi
    Palvelusta
    • MyCourses rekisteriseloste
    • Tietosuojailmoitus
    • Palvelukuvaus
    • Saavutettavuusseloste
    About service
    • MyCourses protection of privacy
    • Privacy notice
    • Service description
    • Accessibility summary
    Service
    • MyCourses registerbeskrivining
    • Dataskyddsmeddelande
    • Beskrivining av tjänsten
    • Sammanfattning av tillgängligheten
    
    Hi guest! (Log in)
    • Schools
      • School of Arts, Design, and Architecture (ARTS)
      • School of Business (BIZ)
      • School of Chemical Engineering (CHEM)
      • –sGuides for students (CHEM)
      • – Instructions for report writing (CHEM)
      • School of Electrical Engineering (ELEC)
      • School of Engineering (ENG)
      • School of Science (SCI)
      • Language Centre
      • Open University
      • Library
      • Aalto university pedagogical training program
      • UNI (exams)
      • Sandbox
    • CORONAVIRUS INFO
      • Koronavirus - tietoa opiskelijalle
      • Coronavirus - information for students
      • Coronavirus - information för studerande
      • Koronaviruksen vaikutus opiskeluun: kysymyksiä ja vastauksia
      • Effects of the coronavirus on studies: questions and answers
      • Coronaviruset och studierna: frågor och svar
      • Corona help for teachers
    • Service Links
      • MyCourses
      • - Instructions for Teachers
      • - Teacher book your online session with a specialist
      • - Digital tools for teaching
      • - Personal data protection instructions for teachers
      • - Instructions for Students
      • - Workspace for thesis supervision
      • WebOodi
      • Into portal for students
      • Courses.aalto.fi
      • Library Services
      • - Resourcesguides
      • - Imagoa / Open science and images
      • IT Services
      • Campus maps
      • - Search spaces and see opening hours
      • Restaurants in Otaniemi
      • ASU Aalto Student Union
      • Aalto Marketplace
    • ALLWELL?
      • Study Skills
      • Support for Studying
      • Starting Point of Wellbeing
      • About AllWell? study well-being questionnaire
    •   ‎(en)‎
      •   ‎(en)‎
      •   ‎(fi)‎
      •   ‎(sv)‎