Difference between revisions of "Processing Introduction"
Jump to navigation
Jump to search
Line 51: | Line 51: | ||
'''Sketch --> Tweak''' | '''Sketch --> Tweak''' | ||
− | '''Sketch --> | + | '''Sketch --> Present''' |
+ | |||
+ | |||
+ | '''Full screen!''' | ||
+ | |||
+ | <syntaxhighlight lang="java" line='line'> | ||
+ | |||
+ | void setup(){ | ||
+ | //size(400,400); | ||
+ | //println("hello!Nan"); | ||
+ | fullScreen(); | ||
+ | background(30,50,80); | ||
+ | |||
+ | } | ||
+ | void draw(){ | ||
+ | //println("welcome to nteraction station!"); | ||
+ | //RGB Value | ||
+ | stroke(30,150,140); | ||
+ | line(width/2, height/2, mouseX, mouseY); | ||
+ | } | ||
+ | |||
+ | |||
+ | </syntaxhighlight> | ||
==draw== | ==draw== |
Revision as of 15:08, 11 April 2021
Processing
Say Hello
setup()
only run once.
draw()
will continuously repeat the action inside of the {}
1void setup(){
2size(400,400);
3println("Hello!Nan");
4
5}
6void draw(){
7println("welcome to interaction station!");
8}
copy-paste the code above and observe the message from the console.
Now, let's try to draw something
1void setup(){
2size(400,400);
3//println("hello!Nan");
4background(30,50,80);
5
6}
7void draw(){
8//println("welcome to nteraction station!");
9//RGB Value
10stroke(30,150,140);
11line(width/2, height/2, mouseX, mouseY);
12}
Sketch --> Run
Sketch --> Tweak
Sketch --> Present
Full screen!
1void setup(){
2//size(400,400);
3//println("hello!Nan");
4fullScreen();
5background(30,50,80);
6
7}
8void draw(){
9//println("welcome to nteraction station!");
10//RGB Value
11stroke(30,150,140);
12line(width/2, height/2, mouseX, mouseY);
13}
draw
Communication with Arduino
draw a image
Image sequence:
1int numImages = 115; // total number of images
2int startNumImage = 1; // first number in sequence
3
4PImage[] images = new PImage[numImages]; // the images will be stored in this list
5
6// setup is executed once, when the program started
7void setup() {
8
9 // size of the window
10 //size(400,400);// use size "(displayWidth, displayHeight)" for fullscreen
11 size(displayWidth, displayHeight);
12
13 // load the image sequence
14 loadImageSequence();
15}
16
17// draw is repeatedly executed, as fast as possible, or according to frameRate setting
18void draw() {
19 background(0); // draw a black background
20
21 // map x position to an image in the sequence
22 int imgInSeq = (int)map(mouseX, 0, width, 0, numImages - 1); // map center of mass to image in sequence
23
24
25 // draw the image scaled and stretched to the window size
26 image(images[imgInSeq], 0, 0, width, height);
27}
28
29// load the image sequence
30void loadImageSequence() {
31 String filename = "";
32
33 for (int i = 0; i < numImages; i++) {
34 // STUDENT: adjust how the filename is being generated to fit the naming of your files
35 filename = "headtrack/img__" +nf(startNumImage + i, 3) + ".jpg";
36 images[i] = loadImage(filename);
37 }
38}