Ajout d'exemple de boucing ball et d'export en SVG
This commit is contained in:
parent
27565541bc
commit
890dc30f56
41
bouncing_ball_with_vector/boucing_ball_with_vector.pde
Normal file
41
bouncing_ball_with_vector/boucing_ball_with_vector.pde
Normal file
@ -0,0 +1,41 @@
|
||||
class PVector {
|
||||
float x, y;
|
||||
|
||||
PVector(float x_, float y_) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
}
|
||||
|
||||
void add(PVector other) {
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
}
|
||||
}
|
||||
|
||||
PVector location;
|
||||
PVector velocity;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(255);
|
||||
location = new PVector(100, 100);
|
||||
velocity = new PVector(1, 3.3);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
|
||||
location.add(velocity);
|
||||
|
||||
if ((location.x > width) || (location.x <= 0)) {
|
||||
velocity.x *= -1;
|
||||
}
|
||||
if ((location.y > height) || (location.y <= 0)) {
|
||||
velocity.y *= -1;
|
||||
}
|
||||
|
||||
stroke(0);
|
||||
fill(175);
|
||||
ellipse(location.x, location.y, 16, 16);
|
||||
|
||||
}
|
22
test_export_svg/test_export_svg.pde
Normal file
22
test_export_svg/test_export_svg.pde
Normal file
@ -0,0 +1,22 @@
|
||||
import processing.svg.*;
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
size(400, 400);
|
||||
noLoop();
|
||||
background(220, 220, 220);
|
||||
beginRecord(SVG, "/home/yaf/filename.svg");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
int rouge = int(random(250)) % 255;
|
||||
int vert = int(random(230)) % 255;
|
||||
int bleu = int(random(250)) % 255;
|
||||
color couleur_du_moment = color(rouge, vert, bleu);
|
||||
fill(couleur_du_moment);
|
||||
quad(int(random(width)), int(random(height)), int(random(width)), int(random(height)), int(random(130)), int(random(163)), int(random(180)), int(random(176)));
|
||||
}
|
||||
endRecord();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user