Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

deutsche Version

SVG data can also be used in processing, but note that some SVG files may not be supported by processing. 

PShape elShape;
PShape warningShape;
float  rotAngle = 0.0;
 
void setup()
{
  size(600,600);      // def. window size
 
  // Load the svg file
  elShape       = loadShape("High_voltage_warning.svg");
  warningShape  = loadShape("Achtung.svg");
  shapeMode(CENTER);    // the zero point of the SVG object is in the middle
  smooth();
}
 
void draw()
{
  background(255);
 
  pushMatrix();
    translate(width *.5,height *.5);
    rotate(rotAngle);
    shape(elShape,0,0,200,200);
  popMatrix();
  rotAngle+=.01;
 
  shape(warningShape,mouseX,mouseY,100,100);
}

Download source

In this example, 2D images (bitmap) are displayed and arrays are used. Here we use a 1. Dimensional array. To access an element of this array, we use these '[index]' brackets.

PImage[] imageList = null;    // create an empty array
 
void setup()
{
  size(600,600);      // def. window size
 
  imageList = new PImage[3];
  imageList[0] = loadImage("./images/1.jpg");
  imageList[1] = loadImage("./images/2.jpg");
  imageList[2] = loadImage("./images/3.jpg");
}
 
void draw()
{
  background(255);
 
  pushMatrix();
    translate(10,100);
    for(int i=0;i < imageList.length; i++)
    {
       image(imageList[i],0,0,140,140);
       translate(150,0);
    }
  popMatrix();
}

Download source

Exercise

Draw a 4th planet (4.jpg) and let this planet follow the mouse. Change the program (and the image file) so that the planet is shown without the white box surrounding it. What file types are best suited for this?