Last time we have installed Android Studio and Processing software. Now it's time to start programming.(I assume you have some basic knowledge of programming )
Usually, every processing Sketch has two functions
1. Setup
This function runs once only when sketch initiated.
All things that need to be run just once can put under this function like defining the size of the screen.
2. Draw
After the sketch is initiated and Setup part is run then Draw part runs forever until the program is shut down.
Basically, it works as an infinite loop.
All the things that need to run for entire time like feedback from user need to put inside Draw function.
Example
Let's take an example of loading an image on the screen.
size : For Screen size
loadImage : Loads an image into a variable of type PImage
image : The image() function draws an image to the display window
Code:
PImage bg,bg1;
int click=0;
void setup()
{
size(displayWidth,displayHeight);
orientation(PORTRAIT);
bg = loadImage("bg.jpg");
bg1 = loadImage("bg1.jpg");
imageMode(CENTER);
textSize(height/11);
}
void draw()
{
if(click%2 == 0)
image(bg, width/2,height/2,width,height);
else
image(bg1, width/2,height/2,width,height);
}
void mousePressed()
{
click+=1;
}
Usually, every processing Sketch has two functions
1. Setup
This function runs once only when sketch initiated.
All things that need to be run just once can put under this function like defining the size of the screen.
2. Draw
After the sketch is initiated and Setup part is run then Draw part runs forever until the program is shut down.
Basically, it works as an infinite loop.
All the things that need to run for entire time like feedback from user need to put inside Draw function.
Example
Let's take an example of loading an image on the screen.
Description
PImage : Datatype for storing images.size : For Screen size
loadImage : Loads an image into a variable of type PImage
image : The image() function draws an image to the display window
Code:
PImage bg,bg1;
int click=0;
void setup()
{
size(displayWidth,displayHeight);
orientation(PORTRAIT);
bg = loadImage("bg.jpg");
bg1 = loadImage("bg1.jpg");
imageMode(CENTER);
textSize(height/11);
}
void draw()
{
if(click%2 == 0)
image(bg, width/2,height/2,width,height);
else
image(bg1, width/2,height/2,width,height);
}
void mousePressed()
{
click+=1;
}
This comment has been removed by a blog administrator.
ReplyDeleteNew video will be up tomorrow. I did all the steps on a brand new windows 7 PC.
DeleteYou can check it out, if still face any problem let me know i will try my best to resolve it.
And sorry I can't remove the video as it had helped many people.