Is there a 2D object scattering plugin?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Suleymanov

There are scattering plugins for 3D like Proton Scatter, but is there any for 2D scenes? What I need is to populate area with 2D images (trees) randomly for position, rotation and scale. And I also need a negative scatter to keep some areas clean.

:bust_in_silhouette: Reply From: SnapCracklins

You could just build an if loop with a variable that puts the trees in random positions and some other random variables to change the other stuff, make some constants for limits so they don’t get too kooky.

    extends AnimationPlayer

export var _treeCount = 30 ## here's how many trees you want
var _rng = ## here's your rng

## limits to color and size modulation to avoid wackiness
export var _sizeRangeMin : float = 0.0
export var _sizeRangeMax : float = 0.5
export var _redRangeMin : float = 0.0
export var _redRangeMax : float = 0.5

## hard limits for position (you don't want to draw offscreen)
const _VECTOR2_MIN = Vector2(0,0)
const _VECTOR2_MAX = Vector2(576,1062) ## insert your window max here, maybe
## a bit higher so it goes offscreeen for continuity

export var _treeSource = preload("") ## the file you preload

func _process(_delta):
	if _treeCount > 0: ## while tree container not empty, trees populate each frame
		_treeCount-=1 ## reduce count each instance
		var _tree = ## instance sprite
		_tree.texture = _treeSource ## instance texture
		randomize() ## lots of rng with the ranges we specify
		var _sizeRoll = _rng.randf_range(_sizeRangeMin,_sizeRangeMax)
		var _redRoll = _rng.randf_range(_redRangeMin,_redRangeMax)
		var _positionX = _rng.randi_range(_VECTOR2_MIN.x,_VECTOR2_MAX.x)
		var _positionY = _rng.randi_range(_VECTOR2_MIN.y,_VECTOR2_MAX.y)
		## then modulate with that math accordingly
		_tree.scale = Vector2(_tree.scale.x+_sizeRoll,_tree.scale.y+_sizeRoll)
		_tree.modulate = Color((1-_redRoll),1,1,1)
		_tree.global_position = Vector2(0+_positionX,0+_positionY)
		## then resolve at end