Indexes • tim rodenbröker creative coding

Indexes

An index is a number which points to the element that you want to reference in an array.

Processing

String[] cities = {
  "Amsterdam", 
  "Paris", 
  "Berlin", 
  "Münster", 
  "Lisbon"
};

PFont font;

void setup() {
  size(900, 900);
  font = createFont("sans.otf",900);
}

void draw() {
  background(#f1f1f1);
  fill(0);
  textAlign(CENTER,CENTER);
  textFont(font);
  textSize(150);
  text(cities[0],width/2,height/2);
}

P5.js

let cities = [
  "Amsterdam", 
  "Paris", 
  "Berlin", 
  "Münster", 
  "Lisbon"
];

let font;
function preload() {
  font=("arial");
}

function setup() {
  createCanvas(900, 900);
}

function draw() {
  background("#f1f1f1");
  fill(0);
  textAlign(CENTER,CENTER);
  textFont(font,150);
  textSize(150);
  text(cities[4],width/2,height/2);
}

Published by Tim on Friday February 19, 2021

Last modified on December 8th, 2022 at 11:28

  1. Arrays
  2. Indexes
  3. Example: My favorite cities
  4. Strings are Arrays of Chars
  5. Arrays can have any Datatype
  6. Array flexibility
  7. 2D Arrays
  8. Loading Strings from a Text-File
  9. Example: Barcelona Districts
  10. Example: Array of Images
  11. Example: Array of Colors
  12. Example: Meditations
  13. Wrapping Up