Structuring the code

edited May 2016 in Library Questions

Sorry to post it here, but I'm having a huge problem structuring my code. I have just started working with processing, so I'm more of a beginner. Would really appreciate if anyone could help me with this.

The idea behind my project is to be able to control the amount of negative and positive information we want to see. I tried to combine rss reader code of two different websites and make a working slider that would change the background colour. Headlines of the bad news would be displayed in black and the good news would be in white. Depending on type of information we want to see, the background would change from black to white revealing only headlines we want to read.

This is a v simple idea, been trying to structure it out so the headlines would work in colour too but I don't think I've got enough knowledge to do so.

rss code:

String[] titles;
String[] titles2;

PFont font;
//color textColor = 255;
void setup() {

  // Setup font
  font = loadFont("din.vlw");
  textFont(font, 18);

  // Load RSS feed

  String url = ""; 
  XML rss = loadXML(url);

  // Get title of each element

  XML[] titleXMLElements = rss.getChildren("channel/item/title");
  titles = new String[titleXMLElements.length];
  for (int i = 0; i < titleXMLElements.length; i++) {
    String title = titleXMLElements[i].getContent();

    titles[i] = title;

    String url2 = "";
  XML rss2 = loadXML(url2);
  // Get title of each element

  XML[] title2XMLElements = rss2.getChildren("channel/item/title");
  titles2 = new String[title2XMLElements.length];
  for (int i = 0; i < title2XMLElements.length; i++) {
    String title2 = title2XMLElements[i].getContent();
    // Store title in array for later use
    titles2[i] = title2; }


void draw() {

  for (int i = 0; i < titles.length; i++) {
    float y = (i+1) * 15;

    fill(0, 220);
    text(titles[i], 100, y*6, 500, 200);   


  for (int i = 0; i < titles2.length; i++) {
    float y = (i+1) * 15;

    text(titles2[i], 800, y*6, 500, 100);

Slider ( got this one from and been trying to use some parts of it)

PGraphics letters;   //news headlines
PGraphics sliders;   //control sliders/background colour 

import controlP5.*;

ControlP5 cp5;

int myColor = color(255);
int c1,c2;
float n,n1;

void setup() {
  cp5 = new ControlP5(this);

  letters = createGraphics(width, height);
  sliders = createGraphics(width, height); 

  // create a new button with name 'buttonA'

  // and add another 2 buttons


void draw() {
  myColor = lerpColor(c1,c2,n);
  n += (1-n)* 0.1; 

public void controlEvent(ControlEvent theEvent) {
  n = 0;

// function colorA will receive changes from 
// controller with name colorA
public void colorA(int theValue) {
  println("a button event from colorA: "+theValue);
  c1 = c2;
  c2 = color(0,0,0);

// function colorB will receive changes from 
// controller with name colorB
public void colorB(int theValue) {
  println("a button event from colorB: "+theValue);
  c1 = c2;
  c2 = color(255);

public void play(int theValue) {
  println("a button event from buttonB: "+theValue);
  c1 = c2;
  c2 = color(0,0,0);

I have been trying to use PGraphics but again, I cannot think what's the best way to structure my code. I'd really appreciate any help,

Thank you!!



  • Your question is ambiguous.

    I'm assuming you have two tabs, rsscode.pde and slider.pde. Unless you are writing a class Object, you can only have a single draw() and setup() in the main program.

    object O;
    void setup() { 
      // main 
      O = new object();
    void draw() { 
      // main 
    class object {
      object {  // empty constructor  }
      public draw() {
        // class draw
    } // end class
Sign In or Register to comment.