View Full Version : particle engine
NiñoScript
January 12th, 2006, 05:40 PM
its not yet finished so im not revealing the code (i think it will be finished by tomorrow morning :P
there are some things that i still have to randomize and optimize, but its looking very near as i wanted it to be :bandit:
edit: i forgot to tell you, this is my first attemp with a particle generator engine :) ... hope you like it
NiñoScript
January 12th, 2006, 09:24 PM
bump :bounce:
c'mon... at least tell me what you think about it :(
icio
January 12th, 2006, 10:09 PM
Looks good.
NiñoScript
January 12th, 2006, 10:33 PM
Thankyou :)
Pasquale
January 12th, 2006, 10:43 PM
make em smaller and it will look hot :P
NiñoScript
January 12th, 2006, 11:57 PM
New features:
Now comes with the code
It has different Blue colours
Reacts to the Mouse position
Lines are smaller
Code is about 10 lines shorter (that was the main reason why i didn't want to put the code in first :P)
Im very proud of it, being my first attempt at a particle engine, i think it rox :lol:
_ymouse = affects the angle in which "water drops" are thrown
_xmouse = adjusts the pression of the water
CODE: if there's a line i didnt count plz tell me :)
_global.vars_and_stuff = {num_of_lines:40, gravity:.4, friction:.98, starting_y:100};
//1
function drawLine(line) {
_root.moveTo(line.p1.x, line.p1.y);
//2
_root.lineTo(line.p2.x, line.p2.y);
//3
}
function moveLine(line) {
movePoint(line.p1, line, 0);
//4
movePoint(line.p2, line, .2);
//5
}
function movePoint(point, vars, special) {
point.x += (vars.xSpeed *= _global.vars_and_stuff.friction);
//6
point.y += (vars.ySpeed += _global.vars_and_stuff.gravity)+special+special*2* ((Stage.width-_xmouse)/Stage.width);
//7
}
function randomLine() {
return {p1:{x:-(random(4)+8), y:4*((Stage.width-_xmouse)/Stage.width)+12*((Stage.height-_ymouse)/Stage.height)+_global.vars_and_stuff.starting_y}, p2:{x:-2, y:_global.vars_and_stuff.starting_y}, xSpeed:random(7)+4+10*(_xmouse/Stage.width), ySpeed:-(random(3)*3)+3-10*((Stage.height-_ymouse)/Stage.height)};
//8
}
var lineArray:Array = new Array(randomLine());
//9
onEnterFrame = function () {
if (lineArray.length<_global.vars_and_stuff.num_of_lines) {
//10
lineArray.push(randomLine());
//11
}
_root.clear();
//12
for (var i = 0; i<lineArray.length; i++) {
//13
_root.lineStyle(2, random(0xbb)+0x22);
//14
moveLine(lineArray[i]);
//15
drawLine(lineArray[i]);
//16
if (lineArray[i].p1.x>Stage.width or lineArray[i].p1.y>Stage.height) {
//17
lineArray[i] = randomLine();
//18
}
}
};
J
January 13th, 2006, 02:14 AM
Good One
McGiver
January 15th, 2006, 06:45 AM
I like the blue one
hybrid101
January 15th, 2006, 07:12 AM
reminds me somewhat of a hose aimed upwards...sweet effect!
FlashTECHY
January 15th, 2006, 08:59 AM
Good ONe!!:A+:
This is my first post and posting for good script written..
Thanks!!
Joppe
January 15th, 2006, 08:59 AM
cool :thumb: but you had some lines over, you could atleast added an no scale fscommand ..
NiñoScript
January 15th, 2006, 10:11 AM
add it yourself :fight:
j/k :P
i'll work on a third version now :)
NiñoScript
January 28th, 2006, 05:19 PM
omg... Processing (http://www.processing.org/) rox :!:
take a look at this, i made the same engine, in processing, but instead of of moving 40 at about 24 fps, it moves 1024 at 80 fps!!! :P
(and it's rendered with openGL)
if anybody wants to see it, email me, or ask me by msn (its 1.2 mb becouse of the openGL libraries :P)
or if u downloaded Processing (which is about 6 mb), heres the code:
//declaracion de variables globales:
int maxLines = 1024;
Pline[] plineArray = new Pline[maxLines];
int currentLine = 0;
import processing.opengl.*;
//declaracion de funciones principales (setup y draw):
void setup() {
/*funcion setup, corre al principio de todo, una sola vez
se asemeja a un _root.onLoad()*/
size(800, 600, OPENGL);
framerate(120);
}
void draw() {
/*funcion draw, empieza despues que setup, siempre esta corriendo
se asemeja a un _root.onEnterFrame(),
corre siempre y cuando noLoop() no se haya llamado, si se ha echo
empieza de nuevo cuando se llame loop()*/
background(100);
//if(mousePressed && mouseY != pmouseY && mouseX != pmouseX){
if(currentLine<maxLines){
plineArray[currentLine] = new Pline(-100, height/3+random(5), mouseX/float(width)*20+random(4)+10, mouseY/float(height)*10-10+random(4));
currentLine++;
}
//}
for(int i=0; i<currentLine; i++){
plineArray[i].update();
}
}
class Pline {
float xSpeed, ySpeed, xPos, yPos;
Pline (float x, float y, float xs, float ys){
this.xSpeed = xs;
this.ySpeed = ys;
this.xPos = x;
this.yPos = y;
}
void restart(float x, float y, float xs, float ys){
this.xSpeed = xs;
this.ySpeed = ys;
this.xPos = x;
this.yPos = y;
}
void update() {
/*if (this.xPos>width){
this.xPos=0;
}*/
if(this.yPos>height){
this.ySpeed*=-.5;
if(abs(this.ySpeed)<1){
this.restart(-100, height/3+random(5), mouseX/float(width)*20+random(4)+10, mouseY/float(height)*10-10+random(4));
}
}
this.xSpeed*=.98;
this.ySpeed+=.5;
this.xPos += this.xSpeed;
this.yPos += this.ySpeed;
line(this.xPos-this.xSpeed, this.yPos-this.ySpeed, this.xPos, this.yPos);
}
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.