Skip to content

sound finale  #7

@akevalion

Description

@akevalion
c := RSCanvas new.
c color: Color black.
colors := NSScale category20c.
width := 720.
height := 720.
extent := width@ height.
minRadius := 25.
maxRadius := (width min: height) * 0.4.
r := Random new.
angleSP := 0.01.
radiusSP := 2.
tau := 6.2831855.
frame := 0.
eased := [ :x | 
	x < 0.5 
		ifTrue: [ 0.5 * (2 * x raisedTo: 3) ]
		ifFalse: [ 0.5 * (2* (x-1) raisedTo: 3)+1 ]
	 ].
arcs := (1 to: 75) collect: [ :i | 
	| isMovingAngle radius angle angleV radiusV randomV 
	cycle line rotateAngle rotateAngleTarget ratio frameOffset 
	points comp |
	isMovingAngle := false.
	radius := r rsNext: minRadius and: maxRadius.
	angle := r next * Float twoPi. 
	angleV := 0.
	radiusV := 0.
	randomV := [ 
		angleV := r next > 0.5 
			ifTrue: [ r rsNext: angleSP * -1 and: angleSP * -0.1 ]
			ifFalse: [ r rsNext: angleSP and: angleSP * 0.1 ].
		radiusV := radius > maxRadius 
			ifTrue: [ r rsNext: radiusSP * -1 and: radiusSP * -0.1 ]
			ifFalse: [ r next > 0.5 
				ifTrue: [ r rsNext: radiusSP * 0.1 and: radiusSP ]
				ifFalse: [ r rsNext: radiusSP * -1 and: radiusSP * -0.1 ] ]
		 ].
	randomV value.
	cycle := (r rsNext: 200 and: 300) asInteger.
	rotateAngle := r next * tau.
	rotateAngleTarget := rotateAngle + (r rsNext: -1 and: 1).
	ratio := 0.
	frameOffset := (r next * cycle) asInteger.
	points := OrderedCollection new.
	
	line := RSPolyline new
		width: (r rsNext: 1 and: 2.5);
		color: (colors scale: i);
		yourself.
	comp := RSComposite new
		add: line;
		yourself.
	comp propertyAt: #update put: [ 
		| cur count cycleRatio cycleRatioMult cycleRatioEased ang 
		vertRatio |
		cur := (angle cos @ angle sin) * radius.
		points addLast: cur.
		points size > 120 ifTrue: [ points removeFirst ].
		isMovingAngle ifTrue: [ 
			angle := angle + angleV 
		] ifFalse: [ 
			(radius < minRadius and: [ radiusV < 0 ])
				ifTrue: [ radius := radius + 0 ]
				ifFalse: [ radius := radius + (radiusV * (1 + (radius * 0.005) )) ] ].
		
		r next > 0.9 ifTrue: [ 
			isMovingAngle := isMovingAngle not.
			randomV value. ].
		count := frame + frameOffset.
		cycleRatio := (count % cycle) / cycle.
		cycleRatioMult := 1 min: cycleRatio * 4.
		cycleRatioEased := eased value: cycleRatioMult.
		ratio := cycleRatioEased.
		(count % cycle) isZero ifTrue: [ 
			rotateAngle := rotateAngleTarget.
			rotateAngleTarget := rotateAngle + (r rsNext: -1 and: 1).
			 ].
		
		ang := rotateAngle interpolateTo: rotateAngleTarget at: ratio.
		vertRatio := (ratio * tau) sin * 0.01+1.
		line controlPoints: (points * vertRatio).
		comp matrix
			loadIdentity;
			rotateByRadians: ang.
		].
	comp
	].

c addAll: arcs.
c newAnimation
	repeat;
	onStepDo: [ :t |
		arcs do: [ :arc | 
			(arc propertyAt: #update) value.	
		].
		c signalUpdate.
		frame := frame + 0.5.
	].
sound := SampledSound fromWaveFileNamed: '/Users/azazael/Downloads/levan.wav'.
sound := sound sounds first.
scale := NSScale pow
	domain: #(0 1);
	range: #(1 1.1).
c newAnimation
	duration: sound duration asSeconds;
	onStepDo: [ :t | 
		| index value |
		index := t * sound samples size + 1.
		value := (sound samples at: index) abs / 32768.
		c camera scale: (scale scale: value)
		].

c videoExporter
	p720;
	duration: sound duration asSeconds;
	export 

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