Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- By @pixelchipcode
- Flow Field Particle System (GML)
- Creates a particle system that moves according to a dynamic flow field. Each particle is influenced by perlin-like 3D noise, creating swirling, organic patterns. Here's a breakdown of what each part does:
- Create Event:
- Initializes particle_count particles with randomized properties like position, speed, direction, color, and size.
- Sets up a flow field grid that influences particle movement.
- Uses a custom simple_noise_3d function for dynamic noise to simulate complex flow patterns.
- Step Event:
- Updates the flow field with changing noise over time, making the movement dynamic and ever-changing.
- Updates each particle's direction based on the flow field and smoothly transitions to new positions.
- Gradually changes each particle's hue over time for a continuous, colorful effect.
- Draw Event:
- Draws all particles onto a surface with a semi-transparent black rectangle to create a fading trail effect.
- The result is a glowing, dynamic flow of particles that are influenced by a constantly shifting flow field.
- Feel free to tweak the particle_count, flow_field_resolution, and color properties to see how different settings change the visuals. This setup is great for learning about flow fields, noise, and creating visually engaging effects.
- = = = = =
- /// Create Event
- function simple_noise_3d(x, y, z) {
- return (sin(x * 10 + noise_seed) * sin(y * 10 + noise_seed) * sin(z * 10 + noise_seed)) * 0.5 + 0.5;
- }
- particle_count = 10000;
- particles = array_create(particle_count);
- flow_field_resolution = 22;
- flow_field_width = ceil(room_width / flow_field_resolution);
- flow_field_height = ceil(room_height / flow_field_resolution);
- flow_field = array_create(flow_field_width * flow_field_height);
- for (var i = 0; i < particle_count; i++) {
- particles[i] = {
- x: random(room_width),
- y: random(room_height),
- speed: random_range(0.5, 2),
- direction: random(360),
- color: make_color_hsv(255, 200, 255),
- size: random_range(0.3, 1)
- };
- }
- time = 0;
- time_speed = 0.002;
- surface = -1;
- noise_seed = random(10000);
- = = = = =
- /// Step Event
- time += time_speed;
- // Update flow field
- for (var i = 0; i < array_length(flow_field); i++) {
- flow_field[i] = simple_noise_3d((i % flow_field_width) * 0.1, (i div flow_field_width) * 0.1, time) * 360;
- }
- // Update particles
- for (var i = 0; i < particle_count; i++) {
- var p = particles[i];
- var index = floor(p.x / flow_field_resolution) + floor(p.y / flow_field_resolution) * flow_field_width;
- // Update particle direction and position
- p.direction = lerp(p.direction, flow_field[index], 0.1);
- p.x = (p.x + lengthdir_x(p.speed, p.direction) + room_width) % room_width;
- p.y = (p.y + lengthdir_y(p.speed, p.direction) + room_height) % room_height;
- // Slowly change particle color over time
- var hue = color_get_hue(p.color);
- hue = (hue + 0.1) % 255;
- p.color = make_color_hsv(hue, 200, 255);
- }
- = = = = =
- /// Draw Event
- if (!surface_exists(surface)) {
- surface = surface_create(room_width, room_height);
- }
- surface_set_target(surface);
- // Draw a semi-transparent black rectangle to create trail effect
- draw_set_alpha(0.1);
- draw_rectangle_color(0, 0, room_width, room_height, c_black, c_black, c_black, c_black, false);
- draw_set_alpha(1);
- gpu_set_blendmode(bm_add);
- for (var i = 0; i < particle_count; i++) {
- var p = particles[i];
- draw_circle_color(p.x, p.y, p.size, p.color, p.color, false);
- }
- gpu_set_blendmode(bm_normal);
- surface_reset_target();
- draw_surface(surface, 0, 0);
Advertisement
Add Comment
Please, Sign In to add comment