Commit b4368696 authored by Mathys's avatar Mathys
Browse files

merge pas trop compliqué mais voila

parents b2774148 e325e598
{
"WindowTitle": "Default",
"WindowSizeX": 800,
"WindowSizeY": 600,
"ParticleImage": "assets/particle.png",
"Debug": true,
"InitNumParticles": 3000,
"RandomSpawn": false,
"SpawnX": 400,
"SpawnY": 400,
"scaleX":1,
"scaleY":1,
"SpawnRate": 0,
"SpeedLimit": [-2, 2, -2, 2],
"Colors": [0, 1, 0, 0, 0, 1],
"Gravity": 0,
"Pictures": "",
"GravityCenter": false,
"Scaleimg": false,
"Spawnimg" : false,
"GravityPoint": false,
"Clock" : false,
"Horlogescale" : 0,
"Variation": 25000,
"Limite_affichage": [-1000,-1000,1800,1600],
"Cahos": true
}
\ No newline at end of file
{
"WindowTitle": "Default",
"WindowSizeX": 800,
"WindowSizeY": 600,
"ParticleImage": "assets/particle.png",
"Debug": true,
"InitNumParticles": 1000,
"RandomSpawn": true,
"SpawnX": 400,
"SpawnY": 400,
"scaleX":1,
"scaleY":1,
"SpawnRate": 0,
"SpeedLimit": [-2, 2, -2, 2],
"Colors": [0, 0, 0, 1, 0, 1],
"Gravity": 0,
"Pictures": "",
"GravityCenter": true,
"Scaleimg": false,
"Spawnimg" : false,
"GravityPoint": false,
"Clock" : false,
"Horlogescale" : 0,
"Variation": 1,
"Limite_affichage": [-1000,-1000,1800,1600],
"Cahos": false
}
\ No newline at end of file
......@@ -16,5 +16,6 @@
"Spawnimg" : true,
"Pictures": "assets/tetris.jpeg",
"Colors": [1,1,1,1,1,1],
"Limite_affichage": [-1000,-1000,1800,1600],
"GravityPoint": false
}
......@@ -16,6 +16,7 @@
"Spawnimg" : false,
"Pictures": "assets/creeper.jpeg",
"Colors": [1,1,1,1,1,1],
"Limite_affichage": [-1000,-1000,1800,1600],
"GravityPoint": true
}
......@@ -11,8 +11,17 @@
"SpawnRate": 0,
"SpeedLimit": [0,0,0,0],
"Colors": [1,1,1,1,1,1],
"Gravity": false,
"Gravity": 0,
"GravityCenter": false,
"NumCycle": 0,
"LifeOpt": [""]
"LifeOpt": [""],
"Pictures": "",
"Scaleimg": false,
"Spawnimg" : false,
"GravityPoint": false,
"Clock" : false,
"Horlogescale" : 2,
"Variation": 1,
"Limite_affichage": [-1000,-1000,1800,1600],
"Cahos": false
}
\ No newline at end of file
......@@ -19,5 +19,6 @@
"Spawnimg" : true,
"GravityPoint": false,
"Horlogescale" : 0,
"Limite_affichage": [-1000,-1000,1800,1600],
"Colision" : true
}
......@@ -18,6 +18,7 @@
"Scaleimg": true,
"Spawnimg" : true,
"GravityPoint": false,
"Limite_affichage": [-1000,-1000,1800,1600],
"Horlogescale" : 2
}
......@@ -10,17 +10,17 @@
"scaleY":1,
"SpawnX": 400,
"SpawnY": 400,
"SpawnRate": 0.00025,
"SpawnRate": 0.25,
"SpeedLimit": [0,0,0,0],
"Colors": [0,1,0,1,0,1],
"Gravity": false,
"Gravity": 0,
"GravityCenter": false,
"NumCycle": 300,
"Pictures": "",
"LifeOpt": ["grow","fade","Death"],
"LifeOpt": ["grow","white","fade","Death"],
"Scaleimg": false,
"Spawnimg" : false,
"GravityPoint": false,
"Limite_affichage": [-1000,-1000,1800,1600],
"Horlogescale" : 0
}
......@@ -17,15 +17,19 @@ go build
arguments with "!" are not implemented yet
+ `Default` Génére des particules blanches statiques
+ `Default` alias `d` Génére des particules blanches statiques
+ ! `Spirale` Génére des particules qui prennent la forme d'une spirale
+ ! `Gravite` Applique une gravité sur les particules
+ `LifeCycle` Donne au particule une durée de vie
+ `LifeCycle` alias `l` Donne au particule une durée de vie
+ ! `Image` Les particules spawn aléatoirement et se déplace pour former un image
+ `Pictures` alias `p1` Les particules spawn aléatoirement et se déplace pour former une image
+ `Pictures2` alias `p2` Les particules spawn pour former une image puis de déplace
+ `Clock` alias `c` Les particules formes les aiguilles d'une horloge
### Detail de config.json :
......
......@@ -13,11 +13,14 @@
"SpawnRate": 0,
"SpeedLimit": [-1,1,-1,1],
"Colors": [0,1,0,1,0,1],
"Gravity": false,
"Gravity": 0,
"Pictures": "",
"GravityCenter": false,
"Scaleimg": false,
"Spawnimg" : false,
"GravityPoint": false,
"Horlogescale" : 0
"Horlogescale" : 0,
"Variation": 1,
"Limite_affichage": [-1000,-1000,1800,1600],
"Cahos": false
}
\ No newline at end of file
......@@ -22,11 +22,15 @@ type Config struct {
Spawnimg bool //fait directement apparaitre les pixels d'une image vers leurs position d'origine
Pictures string //fait apparaitre l'image donnée en lien, elles sont au format jpeg, il est non recommandé de mettre des images trop lourdes
Colors []float64
Gravity,GravityCenter,GravityPoint bool //Active plusieurs type de gravités, GravityPoint attire les pixels d'une image vers leur position d'origine sur celle ci
GravityCenter,GravityPoint bool //Active plusieurs type de gravités, GravityPoint attire les pixels d'une image vers leur position d'origine sur celle ci
Horlogescale int //determine la taille des aiguilles, une valeur de 1 pour 250pixels est recommandé
NumCycle int
LifeOpt []string
Colision bool
Gravity, Variation float64
Cahos bool
Limite_affichage []float64
}
var General Config
......@@ -79,6 +79,22 @@ func commands() {
ExecPart("./Extension/battle_royal.json")
},
},
{
Name: "Chaos",
Aliases: []string{"ch"},
Usage: "Make a fancy particle animation",
Action: func(c *cli.Context) {
ExecPart("./Extension/Cahos.json")
},
},
{
Name: "GravityCenter",
Aliases: []string{"gc"},
Usage: "Make a fancy particle animation",
Action: func(c *cli.Context) {
ExecPart("./Extension/GravityCenter.json")
},
},
}
}
......
......@@ -37,6 +37,7 @@ func GenPart() Particle { // Crée une particule avec Px,Py comme position
SpeedY: config.General.SpeedLimit[2] + rand.Float64()*(config.General.SpeedLimit[3]-config.General.SpeedLimit[2]),
Overflow: false,
Life: config.General.NumCycle,
Variation: config.General.Variation,
}
}
......
......@@ -26,4 +26,6 @@ type Particle struct {
CibleX, CibleY float64
Overflow bool
Life int
Cahos bool
Variation float64
}
......@@ -20,6 +20,13 @@ func Nettoyage(tab []Particle) ([]Particle){
return tab
}
func too_far(p Particle) bool {
if p.PositionX < config.General.Limite_affichage[0] || p.PositionY < config.General.Limite_affichage[1] || p.PositionX > config.General.Limite_affichage[2] || p.PositionX > config.General.Limite_affichage[3] {
return true
}
return false
}
func UpdateCycle(Part Particle) (Particle) {
Part.Life = Part.Life -1
for i:=0; i < len(config.General.LifeOpt); i++ {
......@@ -27,14 +34,14 @@ func UpdateCycle(Part Particle) (Particle) {
Part.Overflow = true
}
if config.General.LifeOpt[i] == "white" {
Part.ColorRed += (1-Part.ColorRed)*(1-(float64(Part.Life) / float64(config.General.NumCycle)))
Part.ColorBlue += (1-Part.ColorBlue)*(1-(float64(Part.Life) / float64(config.General.NumCycle)))
Part.ColorGreen += (1-Part.ColorGreen)*(1-(float64(Part.Life) / float64(config.General.NumCycle)))
Part.ColorRed = float64(config.General.NumCycle) / float64(Part.Life)
Part.ColorBlue = float64(config.General.NumCycle) / float64(Part.Life)
Part.ColorGreen = float64(config.General.NumCycle) / float64(Part.Life)
}
if config.General.LifeOpt[i] == "fade" {
Part.Opacity = (float64(Part.Life)/float64(config.General.NumCycle))
}
if config.General.LifeOpt[i] == "grow" && Part.Life != 0 {
if config.General.LifeOpt[i] == "grow" && Part.Life > 0 {
Part.PositionX += -0.0125
Part.ScaleX += 0.025
Part.PositionY += -0.0125
......@@ -44,22 +51,16 @@ func UpdateCycle(Part Particle) (Particle) {
return Part
}
func gravite(p Particle) (Particle){
if p.SpeedY > 0{
p.SpeedY = p.SpeedY + (p.SpeedY * 0.03) + 0.04
}else{
p.SpeedY = p.SpeedY + ((2) * 0.03) + 0.012
}
func gravite(p Particle) Particle {
p.SpeedY = p.SpeedY + config.General.Gravity
if p.SpeedX > 0 {
p.SpeedX = p.SpeedX - (config.General.Gravity / 10)
} else {
p.SpeedX = p.SpeedX + (config.General.Gravity / 10)
}
return p
}
if p.SpeedY > 0{
p.SpeedX = p.SpeedX - p.SpeedX/500
}else{
p.SpeedX = p.SpeedX + p.SpeedX/500
}
return p
}
func gravitepoint(p Particle) (Particle){
if p.PositionX - p.CibleX < 10 {
p.PositionX = p.CibleX
......@@ -157,80 +158,132 @@ func colision(TabParticule []Particle) ([]Particle){
}
func spirale(p Particle) (Particle){
var centerX = config.General.WindowSizeX/2
var centerY = config.General.WindowSizeY/2
if p.PositionX >= float64(centerX){
if p.PositionY >= float64(centerY){
func cercle(p Particle) Particle {
var centerX = config.General.WindowSizeX / 2
var centerY = config.General.WindowSizeY / 2
p.Variation += 0.001
var distancex = math.Abs(p.PositionX - float64(centerX))
var distancey = math.Abs(p.PositionY - float64(centerY))
/*var distance = math.Sqrt((distancex*distancex) + (distancey*distancey))*/
if p.PositionX >= float64(centerX) {
if p.PositionY >= float64(centerY) {
/*X sup et Y sup
en bas à droite*/
if p.SpeedX > 0{
p.SpeedX = p.SpeedX - 0.0005
if p.SpeedX > 0 {
p.SpeedX = p.SpeedX - 0.00001*distancex*p.Variation
}
if p.SpeedY > -1{
p.SpeedY = p.SpeedY - 0.03
if p.SpeedY > -1 {
p.SpeedY = p.SpeedY - 0.00001*distancey*p.Variation
}
}else{
} else {
/*X sup et Y inf
en haut à droite*/
if p.SpeedX > -1{
p.SpeedX = p.SpeedX - 0.03
if p.SpeedX > -1 {
p.SpeedX = p.SpeedX - 0.00001*distancex*p.Variation
}
if p.SpeedY < 0{
p.SpeedY = p.SpeedY + 0.0005
if p.SpeedY < 0 {
p.SpeedY = p.SpeedY + 0.00001*distancey*p.Variation
}
}
}else if p.PositionX < float64(centerX){
if p.PositionY >= float64(centerY){
} else if p.PositionX < float64(centerX) {
if p.PositionY >= float64(centerY) {
/*X inf et Y sup
en bas à gauche*/
if p.SpeedX < 1{
p.SpeedX = p.SpeedX + 0.03
if p.SpeedX < 1 {
p.SpeedX = p.SpeedX + 0.00001*distancex*p.Variation
}
if p.SpeedY > 0{
p.SpeedY = p.SpeedY - 0.0005
if p.SpeedY > 0 {
p.SpeedY = p.SpeedY - 0.00001*distancey*p.Variation
}
}else{
} else {
/*X inf et Y inf
en haut à gauche*/
if p.SpeedX < 0{
p.SpeedX = p.SpeedX + 0.0005
if p.SpeedX < 0 {
p.SpeedX = p.SpeedX + 0.00001*distancex*p.Variation
}
if p.SpeedY < 1{
p.SpeedY = p.SpeedY + 0.03
if p.SpeedY < 1 {
p.SpeedY = p.SpeedY + 0.00001*distancey*p.Variation
}
}
}
return p
}
func cahos(p Particle) Particle {
var centerX = config.General.WindowSizeX / 2
var centerY = config.General.WindowSizeY / 2
p.Variation -= 10
if p.PositionX >= float64(centerX) {
if p.PositionY >= float64(centerY) {
/*X sup et Y sup
en bas à droite*/
if p.SpeedX > 0 {
p.SpeedX = p.SpeedX - (0.000012 * p.Variation)
}
if p.SpeedY > -1 {
p.SpeedY = p.SpeedY - (0.001 * p.Variation)
}
} else {
/*X sup et Y inf
en haut à droite*/
if p.SpeedX > -1 {
p.SpeedX = p.SpeedX - (0.001 * p.Variation)
}
if p.SpeedY < 0 {
p.SpeedY = p.SpeedY + (0.000012 * p.Variation)
}
}
} else if p.PositionX < float64(centerX) {
if p.PositionY >= float64(centerY) {
/*X inf et Y sup
en bas à gauche*/
if p.SpeedX < 1 {
p.SpeedX = p.SpeedX + (0.001 * p.Variation)
}
if p.SpeedY > 0 {
p.SpeedY = p.SpeedY - (0.000012 * p.Variation)
}
} else {
/*X inf et Y inf
en haut à gauche*/
if p.SpeedX < 0 {
p.SpeedX = p.SpeedX + (0.000012 * p.Variation)
}
if p.SpeedY < 1 {
p.SpeedY = p.SpeedY + (0.001 * p.Variation)
}
}
}
return p
}
func (s *System) Update() {
s.Content = Nettoyage(s.Content)
// s.Content = Nettoyage(s.Content)
for i:=0; i < len(s.Content); i++ {
if s.Content[i].Overflow == false {
if too_far(s.Content[i]) == false {
s.Content[i].PositionX += s.Content[i].SpeedX
s.Content[i].PositionY += s.Content[i].SpeedY
if config.General.Gravity{
if config.General.Gravity != 0 {
s.Content[i] = gravite(s.Content[i])
}
if config.General.GravityCenter{
s.Content[i] = spirale(s.Content[i])
if config.General.GravityCenter {
s.Content[i] = cercle(s.Content[i])
}
if config.General.NumCycle > 0 {
s.Content[i] = UpdateCycle(s.Content[i])
}
if config.General.Cahos {
s.Content[i] = cahos(s.Content[i])
}
if config.General.GravityPoint{
s.Content[i] = gravitepoint(s.Content[i])
}
} else {
s.Content[i].Overflow = true
}
}
if config.General.Horlogescale >0{
s.Content = ClockUpdate(s.Content)
......
......@@ -2,9 +2,8 @@ package particles
import (
"testing"
"math/rand"
"time"
"project-particles/config"
// "fmt"
)
func TestVitesseNull(t *testing.T){
......@@ -42,21 +41,125 @@ func Test_Netoyage(t *testing.T) {
config.General.WindowSizeY = 400
config.General.SpawnX = 200
config.General.SpawnY = 200
config.General.RandomSpawn = false
config.General.InitNumParticles = 10
config.General.SpeedLimit = []float64 {1,1,0,0}
p := GenPart()
Ptab := []Particle {p}
config.General.SpawnX = 397
p = GenPart()
Ptab = append(Ptab,p)
rand.Seed(time.Now().UnixNano())
for i:=0; i < 15; i++ {
if rand.Intn(1) == 1 {
config.General.SpawnX = 397
p = GenPart()
} else {
config.General.SpawnX = 200
p = GenPart()
}
Ptab = append(Ptab,p)
Sys := NewSystem()
config.General.SpawnX = 395
for i:=0; i < 10; i++ {
Sys.Content = append(Sys.Content,GenPart())
}
for i:=0; i < 10 ; i++ {
Sys.Update()
for j:=0; j < len(Sys.Content); j++ {
if Sys.Content[j].PositionX > 401 {
t.Fail()
}
}
}
}
func Test_UpdateCycle_Life(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 10
config.General.NumCycle = 5
config.General.LifeOpt = []string {""}
Sys := NewSystem()
var tmp int
for i:=0; i < 7; i++ {
for j:=0; j < len(Sys.Content); j++ {
tmp = Sys.Content[j].Life
Sys.Content[j] = UpdateCycle(Sys.Content[j])
if tmp - 1 != Sys.Content[j].Life {
t.Fail()
}
}
}
}
func Test_UpdateCycle_Death(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 10
config.General.NumCycle = 5
config.General.LifeOpt = []string {"Death"}
Sys := NewSystem()
for i:=0; i < 7; i++ {
for j:=0; j < len(Sys.Content); j++ {
Sys.Content[j] = UpdateCycle(Sys.Content[j])
if Sys.Content[j].Life < 1 && Sys.Content[j].Overflow == false {
t.Fail()
}
}
}
}
func Test_UpdateCycle_White(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 10
config.General.NumCycle = 5
config.General.LifeOpt = []string {"white"}
Sys := NewSystem()
for i:=0; i < 7; i++ {
for j:=0; j < len(Sys.Content); j++ {
Sys.Content[j] = UpdateCycle(Sys.Content[j])
if Sys.Content[j].ColorRed != 5 / float64(Sys.Content[j].Life) || Sys.Content[j].ColorBlue != 5 / float64(Sys.Content[j].Life) || Sys.Content[j].ColorGreen != 5 / float64(Sys.Content[j].Life) {
t.Fail()
}
}
}
}
func Test_UpdateCycle_Fade(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 10
config.General.NumCycle = 5
config.General.LifeOpt = []string {"fade"}
Sys := NewSystem()
for i:=0; i < 7; i++ {
for j:=0; j < len(Sys.Content); j++ {
Sys.Content[j] = UpdateCycle(Sys.Content[j])
if Sys.Content[j].Opacity != (float64(Sys.Content[j].Life)/float64(config.General.NumCycle)) {
t.Fail()
}
}
}
}
func Test_UpdateCycle_Grow(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 1
config.General.NumCycle = 5
config.General.LifeOpt = []string {"grow"}
Sys := NewSystem()
var InvalidPos,InvalidScale,Alive bool
var OldPosX,OldPosY float64
var OldScaleX,OldScaleY float64
for i:=0; i < 7; i++ {
OldPosX,OldPosY = Sys.Content[0].PositionX,Sys.Content[0].PositionY
OldScaleX,OldScaleY = Sys.Content[0].ScaleX,Sys.Content[0].ScaleY