Skip to content

Commit

Permalink
lez9
Browse files Browse the repository at this point in the history
  • Loading branch information
belligerentcrow committed Nov 4, 2022
1 parent 75f3859 commit d92bb65
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 0 deletions.
171 changes: 171 additions & 0 deletions 9_InterazLAB_03-11-22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# **IeM -- 9**

-> mapping

map(); // ha 5 parametri

map(cosa[l'input], startInput, EndInput, StartOutput, EndOutput);

es su un dado (random da 0.00 a 1.00)
map(r(1), 0.0, 1.0, 1, 6);

es mouse e colore
map(mouseX, 0, width, 0, 255); <-- una proporzione


// LERP
* calcolare dei valori intermedi tra i valori dati

//funzione text(); <-- 3 parametri
text("Stringa da scrivere", posizione1, posizione2);

//esiste anche una versione a 5 parametri che fa scegliere anche il secondo punto per controllare l'area
// utilizza come 0 il punto in basso a sinistra

textSize(); <-- per cambiare la grandezza

textAlign(); <-- allineamento

//http track software

//cambiare font
1. createFont
* PFont f; all'inizio
* f = createFont("Calibri", );
* Come primo parametro il nome della famiglia del font
* println(PFont.list()); //per listare quelli disponibili
2. loadFont
loadFont permette di allegare un file vlw al progetto
prima fare CreateFont con il tool
poi ad esempio f=loadFont("CourierNewPS-BoldMT-48.vlw", 54);


----> controllare materiale teams
----> TEXT BASED RPG

## **ROTAZIONE**

```processing
int l =50;
int a = 0;
void setup(){
size(500, 500);
rectMode(CENTER);
noStroke();
}
void draw(){
background(0);
//fill(0,5);
//rect(0, 0, width, height);
translate(width/2, height/2);
rotate(radians(a));
fill(255);
rect(0, 0, l, l);
a+=5;
}
```

```processing
int l = 100;
int a = 0;
void setup(){
size(500, 500);
noStroke();
rectMode(CENTER);
}
void draw(){
background(0);
pushMatrix();
translate(width/2-100, height/2);
rotate(radians(a)); //posso usare millis()/qualcosa per dare tempo
fill(255);
rect(0, 0, l, l);
popMatrix();
pushMatrix();
translate(width/2+100, height/2);
rotate(radians(-a));
rect(0, 0, l, l);
popMatrix();
a+=5;
}
```

//scale();
//shear();
//quad(); <-- shape() ma quadrangolare

* Lo scale è come uno zoom; ingrandisce anche lo stroke
* all'esame NON utilizzare SCALE --> modificare le coordinate

## **OOP**

* un file per ogni classe -> come nome il nome della classe
* struttura dati a metà tra array e lista
* ArrayList (Java)
* ArrayList<Ball> <--- oggetti appartenenti a questa classe e tutto ciò che eredita
* Impropriamente si può fare ArrayList<Object> perché Object è una superclasse di tutti gli oggetti
* v4 di processing ignora la denominazione private e rende tutto protected
* super al posto di this per richiamare elementi della superclasse

```processing
class Ball{
float posX, posY, size;
float sx, sy;
Ball(float x, float y, float s, float sx, float sy){
posX = x;
posY = y;
size = s;
this.sx=sx; //per i casi di omonimia usare this
this.sy=sy;
};
Ball(float x, float y, float s){
posX = x;
posY = y;
size = s;
this.sx=0;
this.sy=0;
//OPPURE: this(x, y, s, 0, 0); per richiamare il costruttore precedente
}
void display(){
fill(255, 255,0);
noStroke();
ellipse(this.posX, this.posY, this.size, this.size);
};
void move(){
this.posX+=this.sx;
this.posY+=this.sy;
};
void bounce(){
if(posY<size/2||posY>height-size/2){ //aggiungo il raggio
this.sy = -this.sy;
}
if(posX<size/2||posX>width-size/2){ //aggiungo il raggio
this.sx = -this.sx;
}
};
void gravity(){
sy +=0.2;
};
void run(){
gravity();
bounce();
move();
display();
};
};
```

for(Ball b : bs) //per ogni oggetto in bs, specifico ball
54 changes: 54 additions & 0 deletions LAB/Esercizi a lezione/Classssssi/Ball.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class Ball{

float posX, posY, size;
float sx, sy;

Ball(float x, float y, float s, float sx, float sy){
posX = x;
posY = y;
size = s;
this.sx=sx; //per i casi di omonimia usare this
this.sy=sy;
};
Ball(float x, float y, float s){
posX = x;
posY = y;
size = s;
this.sx=0;
this.sy=0;

//OPPURE: this(x, y, s, 0, 0); per richiamare il costruttore precedente
}

void display(){
fill(random(0, 255),random(0, 255),random(0, 255));
noStroke();
ellipse(this.posX, this.posY, this.size, this.size);
};

void move(){
this.posX+=this.sx;
this.posY+=this.sy;
};

void bounce(){
if(posY<size/2||posY>height-size/2){ //aggiungo il raggio
this.sy = -this.sy;
}
if(posX<size/2||posX>width-size/2){ //aggiungo il raggio
this.sx = -this.sx;
}
};

void gravity(){
sy +=0.2;
};

void run(){
gravity();
bounce();
move();
display();
};

};
47 changes: 47 additions & 0 deletions LAB/Esercizi a lezione/Classssssi/Classssssi.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ArrayList<Ball> bs = new ArrayList<Ball>();

int d = 60;

void setup(){
size(800, 800);
background(0);
};

void draw(){
fill(0,20);
noStroke();
rect(0,0, width,height);
for(Ball b:bs){
b.run();
}
};

void keyPressed(){
if(key=='b' || key =='B'){
bs.add(new Ball(random(d/2, width-d/2),random(d/2, height-d/2), random(5, d), random(1,10), random(1,10)));
}

if(key == 'g' || key=='G'){
bs.add(new GreenBall(random(d/2, width-d/2),random(d/2, height-d/2), random(5, d), random(10,15), random(10,15)));

}

switch(key){
case 'p':{
noLoop();
break;
}
case 'v':{
loop();
break;
}
case 'r':{
setup();
break;
}
case 'c':{
bs.remove(bs.size()-1);
}
default:{};
}
};
12 changes: 12 additions & 0 deletions LAB/Esercizi a lezione/Classssssi/GreenBall.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class GreenBall extends Ball{
GreenBall(float x, float y, float s, float sx, float sy){
super(x, y, s, sx, sy);
}

void display(){
fill(0, 255, 0);
stroke(255, 0, 255);
strokeWeight(5);
ellipse(posX, posY, size, size);
}
}
30 changes: 30 additions & 0 deletions LAB/Esercizi a lezione/Fonts/Fonts.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PFont f;
String [] s = {"DKJSKFSD", "FSJKSFJK", "JSKDHKDF", "FKDFJKJJJJFJJJFJJJFJJ"};
int i =0;
String input= "";
void setup(){
size(500,500);
background(0);
fill(255, 255, 0);
//textSize(32);
f=createFont("Book Antiqua", 32);
textFont(f);
text("helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", 0, 50, width, 300);
}

void draw(){
background(0);
text(s[i], 0, 50, width, 300);
}

void mousePressed(){
if(mouseButton==LEFT&& i<3){
i++;
}
}

void keyPressed(){
if(key ==' '&&i>0){
i--;
}
}
Binary file not shown.
1 change: 1 addition & 0 deletions LAB/Esercizi a lezione/Fonts/fonts2.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

34 changes: 34 additions & 0 deletions LAB/Esercizi a lezione/rotation/rotation.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
int l = 100;
int a = 0;
int y = 0;
float v = 0;
float g = 0.1;
void setup(){
size(500, 500);
noStroke();
rectMode(CENTER);
}

void draw(){
background(0);
pushMatrix();
translate(width/2-100, height/2);
rotate(radians(a)); //posso usare millis()/qualcosa per dare tempo
fill(255);
rect(0, 0, l, l);
popMatrix();
pushMatrix();
translate(width/2+100, height/2);
rotate(radians(-a));
fill(0, 255, 0);
rect(0, 0, l, l);
popMatrix();
rect(width/2, y, 20, 20);
y+=v;
v+=g;
if(y>=height){
v = v *-0.70;
}
a+=5;

}
Empty file added MY_PROJ/TetrisMain/Blue_J.pde
Empty file.
3 changes: 3 additions & 0 deletions MY_PROJ/TetrisMain/Green_S.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Green_S extends Piece_super{

};
Loading

0 comments on commit d92bb65

Please sign in to comment.