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

eclipse #3

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

eclipse #3

akevalion opened this issue Dec 7, 2020 · 0 comments

Comments

@akevalion
Copy link
Owner

| xmotion ymotion objs trailMap nnx nny canvas extent width height
 perlin inc frame compute ll |
xmotion := ymotion := 0.
objs := Dictionary new.
trailMap := Dictionary new.
nnx := 500.
nny := 8.

canvas := RSCanvas new.
canvas clearBackground: false.
extent := 800@800.
width := extent x.
height := extent y.
canvas color: Color black.
perlin := NSPerlinNoise3 new octaves: 1; fallOff: 0.7.
inc := 0.
frame := 0.
ll := 400.
(0 to: nnx-1) do: [ :nx |
	| nmx |
	nmx := nx / nnx.
	(0 to: nny-1) do: [ :ny |
		| n obj nmy no ni |
		n := (nx + (ny * nnx)) asInteger.
		nmy := ny / nny.
		no := perlin noise: nmx * nmy and: 1.
		ni := inc / (nnx*nny).
		obj := { 
			"1 lx"(width / 2) + ((nmx * Float twoPi) sin * (width / 3.5)).
			"2 ly"(height / 2) + ((nmx * Float twoPi) cos * (height / 3.5)).
			"3 la"nmx * Float twoPi.
			"4 lv"1.
			"5 d"1.
			"6 no"no.
			"7 so"3.
			"8 sa"45
		 }.
		objs at: n put: obj.
		inc := inc + 1.
		canvas add: (RSEllipse new
			size: 1;
			position: (obj at: 1)@(obj at: 2);
			isFixed: true;
			noPaint;
			yourself)
		].
	].

(0 to: width * height - 1) do: [ :i |
	trailMap at: i put: 0 ].

compute := [ :nx :ny | 
	| n obj sensorOffset sensorAngle t lx ly la lv d no so sa 
	lh fh rh ail aif air s1 s2 s3 shape i b |
	n := (nx + (ny * nnx)) asInteger.
	obj := objs at: n.
	shape := canvas fixedShapes at: n +1.
	lx := obj at: 1.
	ly := obj at: 2.
	la := obj at: 3.
	lv := obj at: 4.
	d := obj at: 5.
	no := obj at: 6.

	sensorOffset := obj at: 7.
	sensorAngle := obj at: 8.
	t := la - sensorAngle.
	lh := ((t sin @ t cos) * sensorOffset) rounded.
	t := la.
	fh := ((t sin @ t cos) * sensorOffset) rounded.
	t := la + sensorAngle.
	rh := ((t sin @ t cos) * sensorOffset) rounded.
	t := lx@ ly.
	ail := (t + lh) asIntegerPoint.
	aif := (t + fh) asIntegerPoint.
	air := (t + rh) asIntegerPoint.
	
	ail := (ail x < 0 ifTrue: [ ail x + width ] ifFalse: [ ail x]) @
		(ail y < 0 ifTrue: [ ail y + height ] ifFalse: [ ail y]).
	
	aif := (aif x < 0 ifTrue: [ aif x + width ] ifFalse: [ aif x]) @
		(aif y < 0 ifTrue: [ aif y + height ] ifFalse: [ aif y]).
	
	air := (air x < 0 ifTrue: [ air x + width ] ifFalse: [ air x]) @
		(air y < 0 ifTrue: [ air y + height ] ifFalse: [ air y]).
		
	ail := (ail x % width)@ (ail y % height).
	aif := (aif x % width)@ (aif y % height).
	air := (air x % width)@ (air y % height).
	
	s1 := trailMap at: ail x + (ail y * width).
	s2 := trailMap at: aif x + (aif y * width).
	s3 := trailMap at: air x + (air y * width).
	(s2 < s1 and: [ s2 < s3 ]) ifTrue: [ "forward" ] ifFalse: [ 
		s1 < s3 ifTrue: [ 
			"left"
			obj at: 3 put: (la := la - (Float pi / 8) ).
		] ifFalse: [ 
			s3 < s1 ifTrue: [
				"right"
				obj at: 3 put: (la := la + (Float pi / 8) ).
				] ].
		 ].
	obj at: 1 put: (lx := lx + (lv * la sin)).
	obj at: 2 put: (ly := ly + (lv * la cos)).
	
	((lx between: 1 and: width-1) and: [ ly between: 1 and: height-1 ]) ifTrue: [ 
		| tlx tly xbl xbu ybl ybu xb yb sph color |
		i := (lx + (ly * width)) asInteger.
		b := (trailMap at: i) / 2.
		
		tlx := lx asInteger.
		tly := ly asInteger.
		xb := tlx - 1.
		yb := tly - 1.
		xbl := xb < 0 ifTrue: [ width -1 ] ifFalse: [ xb ].
		ybl := yb < 0 ifTrue: [ height -1 ] ifFalse: [ yb ].
		xbu := (tlx + 1)%width.
		ybu := (tly + 1)%height.
		trailMap at: xbl + (tly * width) put: b.
		trailMap at: xbu + (tly * width) put: b.
		trailMap at: xbl + (ybl * width) put: b.
		trailMap at: xbl + (ybu * width) put: b.
		trailMap at: xbu + (ybl * width) put: b.
		trailMap at: xbu + (ybu * width) put: b.
		trailMap at: tlx + (ybl * width) put: b.
		trailMap at: tlx + (ybu * width) put: b.
		
		trailMap at: i put: d.
		
		t := (perlin noise: no + (xmotion * 4) and: 0)*2*
			((1 - ((ll min: frame)/ll) ) raisedTo: 5.5 * ((0.5 + (1 - (ly / height) )/2))).
		sph := 1 - ((0.5 -(ly / width))*2 ) abs.
		color := 224 + ((perlin noise: no + (xmotion * 2) and: 0) * 32 * sph).
		shape 
			color: (Color h:0 s:0 v:color alpha: t / 3);
			position: lx @ ly.
		
	] ifFalse: [ 
		shape noPaint.
	]
].
label := RSLabel new
	text: 'DIVAN';
	fontSize: 90;
	fontName: 'Brushcrazy DEMO';
	color: (Color white alpha: 0.01);
	position: 0@20;
	yourself.
canvas add: label.
canvas newAnimation
	repeat;
	onStepDo: [ :t |
		(0 to: nnx - 1) do: [ :nx |
			(0 to: nny -1) do: [ :ny |
				compute value: nx value: ny ] ].
		(0 to: height -1) do: [ :y |
			(0 to: width -1) do: [ :x |
				| v i |
				i := x + (y * width).
				v := trailMap at: i.
				trailMap at: i put: v - 0.1.
				(trailMap at: i) < 0 ifTrue: [ 
					trailMap at: i put: 0 ]
				 ]
			 ].
		xmotion := xmotion + 0.05.
		ymotion := ymotion + 0.0002.
		frame := frame + 1.
	].

canvas open
	extent: extent.
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