-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tension.cpp
67 lines (52 loc) · 1.46 KB
/
Tension.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Simulation.h"
#include "helpers.h"
#include "rand.h"
class Tension : public Simulation
{
std::string title() override {return "Tension";}
float elongate(float side)
{
return 8/side;
}
template<int inputmin, int inputmax, int outputmin, int outputmax>
struct linear_scale
{
float operator()(float input)
{
const float input_range = inputmax - inputmin;
const float output_range = outputmax - outputmin;
return (((input - inputmin)/input_range)*output_range)+outputmin;
}
};
void initialize() override
{
setAllEdges(false);
world().SetGravity(b2Vec2_zero);
b2Vec2 center(0, 80);
const auto dimensions = physicsDimensions();
maxProgress(50);
linear_scale<0, 75, 3, 1> size_scale;
linear_scale<0, 10000, 0, 180> angle_scale;
for(int i = 0; i < 50; ++i)
{
polygonDef def;
def.bodyDef.position = random_margin(dimensions, 3);
def.bodyDef.type = b2_dynamicBody;
def.fixtureDef.friction = 0;
def.fixtureDef.density = 1;
def.fixtureDef.isSensor = true;
float distance = (def.bodyDef.position - center).Length();
float side1 = size_scale(distance);
float side2 = elongate(side1);
def.shape.SetAsBox(side1, side2);
def.bodyDef.angle = to_radians(randcentered(0, angle_scale(pow(distance, 2))));
make_shape(world(), def);
addProgress(1);
}
}
void render() override
{
drawWorld(world(), &noTransform, sf::Color::Black, sf::Color::White, -1);
}
};
REGISTER_SIMULATION(Tension, "tension");