Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miracle #4

Open
akevalion opened this issue Dec 8, 2020 · 0 comments
Open

miracle #4

akevalion opened this issue Dec 8, 2020 · 0 comments

Comments

@akevalion
Copy link
Owner

| canvas n r s1 particles s2 s3 |

canvas := RSCanvas new.
canvas clearBackground: false.
canvas color: Color black.
n := 600.
r := 75.
s1 := NSScale linear
	domain: { 0. n };
	range: { Float pi negated. Float pi }.
s2 := NSScale linear
	domain: { r * 2. 0 };
	range: {Float twoPi. Float pi}.
s3 := NSScale linear
	domain: { r * 2. 0 };
	range: { Float pi. Float twoPi }.
	
particles := OrderedCollection new.
(0 to: n-1) do: [ :i |
	| theta p out alpha shape |
	theta := s1 scale: i.
	p := (theta cos @ theta sin) * r.
	
	out := false.
	shape := RSEllipse new
		position: p;
		size: 2.1;
		color: (Color h: i/6 * 360 / 100 s: 1 v: i % 100 / 100);
		yourself.
	shape propertyAt: #update put: [ 
		| d angle v |
		d := p distanceTo: 0@0.
		angle := p angle + (out 
			ifTrue: [ s2 scale: d ]
			ifFalse: [ s3 scale: d ]).
		v := angle cos @ angle sin .
		p := p + v.
		
		d > (r * 3 - 1) 
			ifTrue: [ out := false ]
			ifFalse: [ d < (r +1) ifTrue: [ out := true ] ].
		
		"shape color: (shape color alpha: alpha)."
		shape position: p.
		"alpha := 1."
		 ].
	particles add: shape.
	 ].
canvas addAll: particles.

canvas newAnimation
	repeat;
	onStepDo: [ :t |
		particles do: [ :p |
			(p propertyAt: #update) value ].
		 ].
canvas videoExporter
	p480;
	duration: 12 seconds;
	export

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant