Comutare navigație
pbInfo.ro
Probleme
Probleme - clasa a IX-a
Probleme - clasa a X-a
Probleme - clasa a XI-a
Probleme din concursuri
Căutare problemă
Exerciții
Programează cu Blockly
Desenează cu Processing
Exersează SQL
Soluţii
Resurse
Resurse pentru clasa a IX-a
Resurse pentru clasa a X-a
Resurse pentru clasa a XI-a
Subiecte bacalaureat
Ajutor
Autentificare
Înregistrare
×
Autentificare
Utilizator sau email
Parola
Acest site foloseşte cookies. Navigând în continuare, vă exprimaţi acordul asupra folosirii cookie-urilor.
Îti place pbInfo? Atunci acceptă-l cu totul! Dezactivează modulul de blocare a reclamelor!
×
Lista scripturi
Script Nou
Ajutor
"artificii/fireworks" - Processing
ID
Autor
Duplicat din
Ultima modificare
#1415
Slanina Simon (Simon271207)
-
Duminica, 11 iun 2017, 16:01
function Firework() { this.hu = random(255); this.firework = new Particle(random(width), height, this.hu, true); this.exploded = false; this.particles = []; this.done = function() { if (this.exploded && this.particles.length === 0) { return true; } else { return false; } } this.update = function() { if (!this.exploded) { this.firework.applyForce(gravity); this.firework.update(); if (this.firework.vel.y >= 0) { this.exploded = true; this.explode(); } } for (var i = this.particles.length - 1; i >= 0; i--) { this.particles[i].applyForce(gravity); this.particles[i].update(); if (this.particles[i].done()) { this.particles.splice(i, 1); } } } this.explode = function() { for (var i = 0; i < 100; i++) { var p = new Particle(this.firework.pos.x, this.firework.pos.y, this.hu, false); this.particles.push(p); } } this.show = function() { if (!this.exploded) { this.firework.show(); } for (var i = 0; i < this.particles.length; i++) { this.particles[i].show(); } } } function Particle(x, y, hu, firework) { this.pos = createVector(x, y); this.firework = firework; this.lifespan = 255; this.hu = hu; this.acc = createVector(0, 0); if (this.firework) { this.vel = createVector(0, random(-12, -8)); } else { this.vel = p5.Vector.random2D(); this.vel.mult(random(2, 10)); } this.applyForce = function(force) { this.acc.add(force); } this.update = function() { if (!this.firework) { this.vel.mult(0.9); this.lifespan -= 4; } this.vel.add(this.acc); this.pos.add(this.vel); this.acc.mult(0); } this.done = function() { if (this.lifespan < 0) { return true; } else { return false; } } this.show = function() { colorMode(HSB); if (!this.firework) { strokeWeight(2); stroke(hu, 255, 255, this.lifespan); } else { strokeWeight(4); stroke(hu, 255, 255); } point(this.pos.x, this.pos.y); } } var fireworks = []; var gravity; function setup() { createCanvas(400, 400); colorMode(HSB); gravity = createVector(0, 0.2); stroke(255); strokeWeight(4); background(0); } function draw() { colorMode(RGB); background(0, 0, 0, 25); if (random(1) < 0.03) { fireworks.push(new Firework()); } for (var i = fireworks.length - 1; i >= 0; i--) { fireworks[i].update(); fireworks[i].show(); if (fireworks[i].done()) { fireworks.splice(i, 1); } } }
Duplicare
Executare
Cod
×
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=1415" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
×
Duplicare script
Denumirea noului script
Du-te sus!