Coding / Session 6

November 6, 2013 § Leave a comment

[Add and watch video on UniLearn when it’s added, noting down what certain code does]

In the coding session today we were started from scratch, for the first time in a while, the result of the below code shows many moving objects on the same canvas, all but one of which were copied using a ‘filing cabinet’ variable in contrast to a ‘box’ variable, this allows me to apply as many objects on screen as I wish, or until my computer explodes =P I also changed the speed and coordinate positions.


import processing.opengl.*;

  // building variables
  // introducing an ‘array’ which is a bit like  a variable, but rather than being a box (like with the variable) it’s more like a chest of drawers
  // the aim is to create something that will essentially dupkoicate behaviours, to produce a more interesting effect

float xpos;
float ypos;
  // these are variables that store decimal points
float xinc;
float yinc;
  // xinc and yinc are the speed variables, these will make things bounce on screen
  // I make a new variable ‘numb=’ (number=) these are the cabinet draws, of which we spicify the number
  // ‘[]’ means float, these are floating points

int numb=10;
  //this is the integer variable
float []xposar;
float []yposar;
float []xincar;
float []yincar;
  //’ar’ stands for array

void setup(){
  xposar=new float[numb];
  yposar=new float[numb];
  xincar=new float[numb];
  yincar=new float[numb];
    //[numb] (for number) is ammount of draws
    // is a random number between 800 etc.
    //here we want to write some code so we can go through the whole structure snd put random numbers in each draw, or information, you don’t have to stop at 10, you could easily do 1000
  for(int lop=0;lop<numb; lop=lop+1){
      // these will now put random information in the ‘cabinet’

void draw(){
  // drawing an elipse within the numbers of ypos and xpos
  //whatever random speed has been picked, we’re going to add that to the current xposition
  //for it to know where the edges of the screen is: if the x pos is greater than 100, then I want to reverse the sign, if xpos is less than 0 then I want to reverse the sign
 if(xpos>800) xinc=xinc*-1;
 if(xpos<0) xinc=xinc*-1;
 if(ypos>600) yinc=yinc*-1;
 if(ypos<0) yinc=yinc*-1;
//now plot multiple balls

  for(int lop=0;lop<numb; lop=lop+1){
     if(lop<numb-1) line(xposar[lop],yposar[lop],xposar[lop+1],yposar[lop+1]);
       //^^if these balls were always looking at the draw above and following it
      //lets draw a line to
      //adding the question if(lop<num-1)

//now check boundaries
 if(xposar[lop]>800) xincar[lop]=xincar[lop]*-1;
 if(xposar[lop]<0) xincar[lop]=xincar[lop]*-1;
 if(yposar[lop]>600) yincar[lop]=yincar[lop]*-1;
 if(yposar[lop]<0) yincar[lop]=yincar[lop]*-1;
 //by placing [lop] at the end of every variable, I am able to move the balls, all the balls. the ‘ar’ at the end of xinc, yinc etc. is the random information, or the random balls that appear

  //going to keep all this code as a template and converting it so we can batch process lots of different things, or lots of dots
  // ^^we can do this by making lots of duplicates, but this will take a long time
  // we’ve currently got these single boxes – xpos and ypos – but we want these to be filing cabinet like things
  // I make a new variable ‘numb=’ (number=) these are the cabinet draws, of which I specify the number
  // ‘[]’ means float, these are floating points



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

What’s this?

You are currently reading Coding / Session 6 at Leo Patterson.


%d bloggers like this: