Skip to content

illusion #5

@akevalion

Description

@akevalion
canvas := RSCanvas new.
canvas color: Color lightGray.
positions := {-115@ 0. 115@0}.
colors := NSScale ordinal
	rangeFrom: { 'fac12d'. '183ab4'}.
n := 4.
c := (1 / n)* 360.
pies := positions collect: [ :p | 
	slices := (1 to: n) collect: [ :i |
		| a b d |
		a := (i / n) * 360.
		b := a + c.
		d := i odd ifTrue: [ 0 ] ifFalse: [ 0.5 ].
		RSPieSlice new
			innerRadius: 60+d;
			externalRadius: 90-d;
			alphaAngle: a;
			betaAngle: b;
			border: (RSBorder new color: 'fac12d'; width: d*2);
			color: (colors scale: i);
			yourself
		 ] as: RSGroup.
	
	slices asShape
		translateTo: p;
		yourself
	 ].

arrows := positions collect: [ :p | 
	arrow := RSPolygon new
		points: {
			0@0.
			50@50.
			15@50.
			15@100.
			-15@100.
			-15@50.
			-50@50};
		color: Color black;
		yourself.
	arrow extent: 30@50.
	arrow position: p.
	arrow
	].

rots := {  
	{ 90. 180. 270. 360. }. { -90. 0. 90. 180. }. }.

cross := [:deltaA :dist | 
	| group |
	group := (1 to: 4) collect: [ :i | 
		| copy angle |
		copy := arrows first copy.
		copy extent: 15@20.
		angle := (i / 4) * Float twoPi.
		copy matrix
			loadIdentity;
			rotateByRadians: angle + deltaA ;
			translation:( angle cos @ angle sin) * dist.
		copy resetBBox.
		copy ] as: RSGroup.
	group asShape ].
icross := [ 
	cross value: Float halfPi value: 15
	 ].
ocross := [ cross value: Float halfPi negated value: 12 ].
arrows with: rots do: [ :arrow :rotations | 
	| seqAnimation crossA crossB |
	arrow propertyAt: #angle put: rotations first.
	arrow matrix rotateByDegrees: rotations first.
	crossA := icross value.
	crossB := ocross value.
	crossA position: arrow position.
	crossB position: arrow position.
	arrow = arrows second ifTrue: [ | temp |
		temp := crossA.
		crossA := crossB.
		crossB := temp ].
	
	seqAnimation := (canvas animationFrom: (rotations allButFirst collect: [ :newAngle |
		canvas transitionAnimation
			delay: 2 seconds;
			duration: 1000 milliSeconds;
			onStepDo: [ :t |
				| a p|
				a := arrow propertyAt: #angle.
				p := arrow position.
				arrow matrix
					loadIdentity;
					translation: p;
					rotateByDegrees: (a interpolateTo: newAngle at: t).
				];
			when: RSAnimationEndEvent do: [ arrow propertyAt: #angle put: newAngle ]
			
		])).
	
	seqAnimation add: (canvas transitionAnimation
		delay: 2 seconds;
		duration: 1 second;
		onStepDo: [:t | 
			arrow remove.
			canvas add: crossA.
			canvas signalUpdate ]).
	seqAnimation add: (canvas transitionAnimation
		delay: 2 seconds;
		duration: 3 second;
		onStepDo: [:t | 
			crossA remove.
			canvas add: crossB.
			canvas signalUpdate ];
		when: RSAnimationEndEvent do: [ 
			crossB remove.
			canvas add: arrow.
			arrow propertyAt: #angle put: rotations first.
		
			arrow matrix 
				loadIdentity;
				translation: crossA position;
				rotateByDegrees: rotations first.
			canvas signalUpdate. ]).
	seqAnimation repeat.
].

canvas newAnimation
	repeat;
	duration: 750 milliSeconds;
	from: 0;
	to: Float twoPi;
	onStepDo: [ :t | 
		pies do: [:pie |
			| p |
			p := pie position.
			pie matrix
				loadIdentity;
				translateBy: p;
				rotateByRadians: t.
		].
		canvas signalUpdate.
	] .
canvas when: RSMouseClick do: [ canvas animations do: #toggle ].
canvas addAll: pies.
canvas addAll: arrows.
canvas zoomToFit.
canvas open.

https://statics.memondo.com/p/s1/gifs/2021/01/GIF_1102934_6465ab724c7b4079b874018691bb9e18_una_de_las_mejores_ilusiones_opticas_que_he_visto_nunca.webm

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions