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 11
Syllabus

Day 11

  • Day 11

    Day 11

    Lists

    So far we've used arrays when we've had to store multiple values – even an array of objects is perfectly feasible. The issue with arrays is that they're static by nature: changing their size is cumbersome and slow, and may involve useless copying of data back and forth. Inserting values into an array is likewise tricky. There are common situations where we would like to have more flexibility, for example in a game where enemies keep appearing and dyidisappearing. For this purpose we have lists. Processing has the following kinds available for you:

    • IntList
    • FloatList
    • StringList
    • And ArrayList which lets you store objects – we'll discuss this in From Data to Pixels


    The most common operations you'll need are get() – get an item from the list, append() – add one more at the end, size() – the number of items, useful for looping, and remove() – take out one item from the list. See here for a complete list of available functionality and an example.

    Why wouldn't we use lists always then? Traditionally they've been slower than plain arrays, in addition to which they may consume more memory. Furthermore, it's a bit trickier to access the individual elements of a list as opposed to an array.

    Using Event Handlers (Callbacks) for Input

    Like with the mouse, the simplest way to read the keyboard is to check the global variable keyPressed. If it’s true, key will contain the pressed key. It can be either a character in single quotes or a special value such as ENTER or BACKSPACE.

    However, when you get serious about it, both the mouse and keyboard are better supported using event handlers, such as mouseClicked. A simple keyboard example: keyboard.pde. An advanced example of the use of event handlers: eventhandlers.pde

    By using event handlers you can be sure that you'll never miss mouse clicks or button presses, unlike with the simpler method. Another plus is that you have more advanced control over the mouse movement, for instance mouseDragged, which would be hard to implement otherwise.

    Homework

    This time let's combine lists and event handlers. Let the user place green dots around the window by clicking the mouse. Store the mouse coordinates in a list so that you can redraw all the dots each frame – clear the window at the beginning of draw(). mousePressed() is a good event handler for this purpose.

    Face

    Example solution: dotlist.pde

    Previous section

    ◄Day 10

    Next section

    Day 12►
    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)‎