Coding / Session 5

October 30, 2013 § Leave a comment

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

“The challenge is to make the second point move in the same way as the first to draw more complex shapes…”

Unfortunately I was unable to make it to this session as I had a medical appointment, I did however still attempt this, and got by rather well, the annotated code below explains it.

float ypos;
float xpos;

float yinc;
float xinc;

float xpos2;
float ypos2;

float yinc2;
float xinc2;
  // The above two lines of code allows for me to create a speed on the x and y axis for the second point. Where the code sets a random position for the second point, we can add values to the new variables below this so that it moves as shown below:

void setup(){

size(1024,768);
background(0,0,0);
stroke(255,255,255,100);
fill(255,255,255,100);

// Below (4 lines) – set random position for the first point
xpos=random(1024);
ypos=random(768);

yinc=5;
xinc=3;

// Set a random position for the second point
xpos2=random(1024);
ypos2=random(768);
//set a fixed speed for the second point
yinc2=5;
xinc2=3;

smooth();
}

void draw(){

line(xpos,ypos,xpos2,ypos2);

xpos=xpos+xinc;
ypos=ypos+yinc;
xpos2=xpos2+xinc2;
ypos2=ypos2+yinc2;

if(ypos>768) yinc=-5;
if(ypos<0) yinc=5;

if(xpos>1024) xinc=-50;
if(xpos<0) xinc=50;

if(ypos2>768) yinc2=-5;
if(ypos2<0) yinc2=5;

if(xpos2>1024) xinc2=-50;
if(xpos2<0) xinc2=50;
   // The above 8 lines of code are the parameters of which the line can bounce within, if I alter one of these the line will become stray and won’t give the desired effect

line(xpos2,ypos2,xpos,ypos);
}

 

Altering the figures in red determines the speed of the line at different angles, I played around with these numbers to gain these results (with the numbers next to them). I wish I could see all the number combinations and their results!

if(ypos>768) yinc=-5;
if(ypos<0) yinc=5;

if(xpos>1024) xinc=-3;
if(xpos<0) xinc=3;

if(ypos2>768) yinc2=-5;
if(ypos2<0) yinc2=5;

if(xpos2>1024) xinc2=-3;
if(xpos2<0) xinc2=3;

The original (with above numbers):

screenshot

-51; / 55; / -38; / 75; / -36; / 23; / -89; / 67;

screenshot2

-20; / 20; / -20; / 20; / -20; / 20; / -20; / 20;

screenshot3

-8; / 10; / -10; / 8; / -8; / 10; / -10; / 8;screenshot4

 

-5; / 5; / -50; / 50; / -5; / 5; / -50; / 50;

screenshot5

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

What’s this?

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

meta

%d bloggers like this: