Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
jmanton1992
jmanton1992's Profile
2
Posts
3
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
External Files
[3 Replies]
29-Apr-2013 02:33 AM
Forum:
General Discussion
I'm trying to display text from an external file in the background of my firework animation but it won't display at all. Does anyone know how to make it show?
I know this is bad but would anyone be able to explain this code? I've only began using Processing in college and I need to replicate this code with some understanding >.<
[6 Replies]
11-Apr-2013 06:50 AM
Forum:
General Discussion
import processing.core.PApplet;
public class Fireworks extends PApplet
{
Firework [] fs = new Firework[10];
boolean once;
PApplet parent;
public void setup(){
size(400,400);
smooth();
for (int i = 0; i < fs.length; i++){
fs[i] = new Firework();
}
}
public void draw()
{
noStroke();
fill(50,0,40,20);
rect(0,0,width,height);
for (int i = 0; i < fs.length; i++){
fs[i].draw();
}
}
public void mouseReleased(){
once = false;
for (int i = 0; i < fs.length; i++){
if((fs[i].hidden)&&(!once)){
fs[i].launch();
once = true;
}
}
}
public class Firework<color>{
float x, y, oldX,oldY, ySpeed, targetX, targetY, explodeTimer, flareWeight, flareAngle;
int flareAmount, duration;
boolean launched,exploded,hidden;
int flare;
Firework(){
launched = false;
exploded = false;
hidden = true;
}
public void draw(){
if((launched)&&(!exploded)&&(!hidden)){
launchMaths();
strokeWeight(1);
stroke(255);
line(x,y,oldX,oldY);
}
if((!launched)&&(exploded)&&(!hidden)){
explodeMaths();
noStroke();
strokeWeight(flareWeight);
stroke((Integer) flare);
for(int i = 0; i < flareAmount + 1; i++){
pushMatrix();
translate(x,y);
point(sin(radians(i*flareAngle))*explodeTimer,cos(radians(i*flareAngle))*explodeTimer);
popMatrix();
}
}
if((!launched)&&(!exploded)&&(hidden)){
//do nothing
}
}
public void launch(){
x = oldX = mouseX;
y = oldY = height;
//mouseX = left mouse button
//mouseY = right mouse button
targetX = mouseX;
targetY = mouseY;
ySpeed =2;
flare = color(random(3)*50 + 105,random(3)*50 + 105,random(3)*50 + 105);
flareAmount = ceil(random(30)) + 20;
flareWeight = ceil(random(3));
duration = ceil(random(4))*20 + 30;
//makes explosion a full circle
flareAngle = 360/flareAmount;
launched = true;
exploded = false;
hidden = false;
}
public void launchMaths(){
oldX = x;
oldY = y;
if(dist(x,y,targetX,targetY) > 6){
x += (targetX - x)/2;
y += -ySpeed;
}else{
explode();
}
}
public void explode(){
explodeTimer = 3;
launched = false;
exploded = true;
hidden = false;
}
public void explodeMaths() {
if(explodeTimer < duration){
explodeTimer+= 2;
}else
{
hide();
}
}
public void hide()
{
launched = false;
exploded = false;
hidden = true;
}
}
}
«Prev
Next »
Moderate user : jmanton1992
Forum