“luciolesTravelling” by Gweltaz Duval-Guennoc
https://openprocessing.org/sketch/446198
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
luciolesTravelling
Duval-Guennoc
xxxxxxxxxx
/*
** Scene with travelling
**
** Author: Gweltaz Duval-Guennoc
** Date: 06-09-2017 (Résidence à Bourg-Blanc)
**
** Art: Anna Duval-Guennoc (annaduvalguennoc.blogspot.fr)
*/
/* @pjs preload="p1.png";
preload="p2.png";
preload="p3.png";
preload="p4.png";
preload="p5.png"; */
ArrayList<Luciole> lucioles1;
ArrayList<Luciole> lucioles2;
ArrayList<Luciole> lucioles3;
ArrayList<Luciole> lucioles4;
PImage plan1;
PImage plan2;
PImage plan3;
PImage plan4;
PImage plan5;
// Travelling parameters
int p1_roff = 300; // right corner offset
int p2_roff = 200;
int p3_roff = 110;
int p4_roff = 100;
int n_frames = 120;
int frame;
float mX, mY;
void setup() {
size(580, 340);
noStroke();
colorMode(HSB);
plan1 = loadImage("p1.png");
plan1 = scaleImage(plan1, 4);
plan2 = loadImage("p2.png");
plan2 = scaleImage(plan2, 4);
plan3 = loadImage("p3.png");
plan3 = scaleImage(plan3, 4);
plan4 = loadImage("p4.png");
plan4 = scaleImage(plan4, 4);
plan5 = loadImage("p5.png");
plan5 = scaleImage(plan5, 4);
lucioles1 = genLucioles(3, 1.0);
lucioles2 = genLucioles(10, 3.0);
lucioles3 = genLucioles(100, 4.0);
lucioles4 = genLucioles(300, 8.0);
int frame = 0;
}
void draw() {
background(#5F3FAD);
frame = constrain(frameCount, 0, n_frames);
mX = (mouseX/float(width)) - 0.5;
mY = (mouseY/float(height)) - 0.5;
pushMatrix();
translate(width-plan5.width+p4_roff-frame*p4_roff/n_frames, 0);
image(plan5, 0, 0);
image(plan4, 0, 0);
for (int i=0; i<lucioles4.size(); i++) {
lucioles4.get(i).update();
lucioles4.get(i).draw(0);
}
popMatrix();
pushMatrix();
translate(width-plan3.width+p3_roff-frame*p3_roff/n_frames, 0);
image(plan3, 0, 0);
for (int i=0; i<lucioles3.size(); i++) {
lucioles3.get(i).update();
lucioles3.get(i).draw(0);
}
popMatrix();
pushMatrix();
translate(width-plan2.width+p2_roff-frame*p2_roff/n_frames, 0);
image(plan2, 0, 0);
for (int i=0; i<lucioles2.size(); i++) {
lucioles2.get(i).update();
lucioles2.get(i).draw(1);
}
popMatrix();
pushMatrix();
translate(width-plan1.width+p1_roff-frame*p1_roff/n_frames, 0);
image(plan1, 0, 0);
popMatrix();
pushMatrix();
translate(p1_roff-frame*p1_roff/n_frames, 0);
for (int i=0; i<lucioles1.size(); i++) {
lucioles1.get(i).update();
lucioles1.get(i).draw(1);
}
popMatrix();
}
class Luciole {
int x, y;
float dist;
float b;
int x_o, y_o;
int v_amp;
int h_amp;
int b_amp;
float h_ang;
float v_ang;
float b_ang;
float h_v_ang; // Angular speed 1
float v_v_ang; // Angular speed 2
float b_v_ang;
Luciole(int _x, int _y, int _h_amp, int _v_amp, float _v_h, float _v_v, float _v_b, float _dist) {
// x, y
// horizontal amplitude
// vertical amplitude
// horizontal angular speed
// vertical angular speed
// brightness angular speed
x_o = _x;
y_o = _y;
dist = _dist;
h_amp = _h_amp;
v_amp = _v_amp;
h_v_ang = _v_h;
v_v_ang = _v_v;
b_v_ang = _v_b;
h_ang = random(0, TWO_PI);
v_ang = random(0, TWO_PI);
b_ang = random(0, TWO_PI);
}
void update() {
h_ang += h_v_ang;
if (h_ang>= TWO_PI)
h_ang -= TWO_PI;
v_ang += v_v_ang;
if (v_ang >= TWO_PI)
v_ang -= TWO_PI;
b_ang += b_v_ang;
if (b_ang >= TWO_PI)
b_ang -= TWO_PI;
x = x_o + round(h_amp/dist * cos(h_ang));
y = y_o + round(v_amp/dist * cos(v_ang));
b = cos(b_ang) + 0.5;
}
void draw(int mode) {
if (mode == 0) { // mode pulsing circle
fill(70, 125-10*b, 240+10*b, 150+b*50);
ellipse(x, y, 1+ceil((6+b*4)/dist), 1+ceil((6+b*4)/dist));
}
if (mode == 1) { // mode pixel art
int rad = int((10+4*b)/dist);
fill(70, 110-10*b, 240+10*b, 220+int(30*b/dist)); // with alpha
rect(x, y, rad, rad);
fill(70, 125-10*b, 240+10*b, 40+int(50*b/dist)); // with alpha
rect(x-rad, y, rad, rad);
rect(x, y-rad, rad, rad);
rect(x+rad, y, rad, rad);
rect(x, y+rad, rad, rad);
}
}
}
PImage scaleImage(PImage image_o, int n) {
// L'algorithme de scaleImage parcours l'image du coin bas-droite au coin haut-gauche
// ce qui le permet (en théorie) de pouvoir opérer en-place sur l'image originale
int w = image_o.width;
int h = image_o.height;
PImage result = createImage(w*n, h*n, ARGB);
image_o.loadPixels();
result.loadPixels();
for (int y=h-1; y>=0; y--) {
for (int x=w-1; x>=0; x--) {
color c = image_o.pixels[w*y+x];
for (int j=0; j<n; j++) {
for (int i=0; i<n; i++) {
result.pixels[w*y*n*n + w*j*n + x*n + i] = c;
}
}
}
}
return result;
}
ArrayList<Luciole> genLucioles(int n, float dist) {
ArrayList<Luciole> lucioles = new ArrayList<Luciole>();
for (int i=0; i<n; i++) {
int x = int(random(-p1_roff, plan1.width));
int y = int(random(height));
int h_amp = int(random(40));
int v_amp = int(random(40));
float h_v = random(0.01, 0.06);
float v_v = random(0.01, 0.06);
float b_v = random(0.01, 0.04);
lucioles.add(new Luciole(x, y, h_amp, v_amp, h_v, v_v, b_v, dist));
}
return lucioles;
}
See More Shortcuts