Skip to content

Commit

Permalink
Merge pull request #46 from matejsemancik/feature/tunnel
Browse files Browse the repository at this point in the history
Hegaxon tunnel
  • Loading branch information
matejsemancik authored Nov 15, 2019
2 parents 069da3b + d8f3969 commit 54ae6d1
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/dev/matsem/astral/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.matsem.astral
object Config {

object Sketch {
const val DEFAULT_SELECTOR = 'g'
const val DEFAULT_SELECTOR = 't'
}

object Color {
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/dev/matsem/astral/di/koin_modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dev.matsem.astral.sketches.gameoflife.GameOfLifeSketch
import dev.matsem.astral.sketches.oldskool.OldSkoolSketch
import dev.matsem.astral.sketches.patterns.PatternsSketch
import dev.matsem.astral.sketches.polygonal.PolygonalSketch
import dev.matsem.astral.sketches.radialwaves.TunnelSketch
import dev.matsem.astral.sketches.spikes.SpikesSketch
import dev.matsem.astral.sketches.starglitch.StarGlitchSketch
import dev.matsem.astral.sketches.terrain.TerrainSketch
Expand Down Expand Up @@ -92,4 +93,5 @@ val appModule = module {
factory { GalaxySketch() }
factory { GameOfLifeSketch() }
factory { OldSkoolSketch() }
factory { TunnelSketch() }
}
11 changes: 8 additions & 3 deletions src/main/kotlin/dev/matsem/astral/sketches/SketchLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dev.matsem.astral.sketches.gameoflife.GameOfLifeSketch
import dev.matsem.astral.sketches.oldskool.OldSkoolSketch
import dev.matsem.astral.sketches.patterns.PatternsSketch
import dev.matsem.astral.sketches.polygonal.PolygonalSketch
import dev.matsem.astral.sketches.radialwaves.TunnelSketch
import dev.matsem.astral.sketches.spikes.SpikesSketch
import dev.matsem.astral.sketches.starglitch.StarGlitchSketch
import dev.matsem.astral.sketches.terrain.TerrainSketch
Expand Down Expand Up @@ -63,8 +64,8 @@ class SketchLoader : PApplet(), KoinComponent {
private lateinit var colorResetButton: PushButton

private val bgColor = PVector(0f, 0f, 10f)
private val fgColor = PVector(150f, 0f, 100f)
private val accentColor = PVector(0f, 0f, 0f)
private val fgColor = PVector(150f, 100f, 100f)
private val accentColor = PVector(0f, 0f, 10f)

lateinit var bgHuePot: Pot
lateinit var bgSatPot: Pot
Expand Down Expand Up @@ -120,6 +121,7 @@ class SketchLoader : PApplet(), KoinComponent {
private val galaxySketch: GalaxySketch by inject()
private val gameOfLifeSketch: GameOfLifeSketch by inject()
private val oldSkoolSketch: OldSkoolSketch by inject()
private val tunnelSketch: TunnelSketch by inject()

// endregion

Expand All @@ -129,7 +131,8 @@ class SketchLoader : PApplet(), KoinComponent {
override fun settings() {
size(1280, 720, PConstants.P3D)
// fullScreen(P3D, 2) - use in live environment (projector extends desktop)
noSmooth()
// noSmooth()
smooth()
}

override fun setup() {
Expand Down Expand Up @@ -213,6 +216,7 @@ class SketchLoader : PApplet(), KoinComponent {
put('s', galaxySketch)
put('g', gameOfLifeSketch)
put('o', oldSkoolSketch)
put('t', tunnelSketch)
}

sketches.forEach { key, sketch ->
Expand All @@ -234,6 +238,7 @@ class SketchLoader : PApplet(), KoinComponent {
galaxy.createPushButton(15, 11) { switchSketch('s') }
galaxy.createPushButton(15, 12) { switchSketch('g') }
galaxy.createPushButton(15, 13) { switchSketch('o') }
galaxy.createPushButton(15, 14) { switchSketch('t') }

if (Config.VideoExport.IS_IN_RENDER_MODE) {
frameRate(1000f)
Expand Down
130 changes: 130 additions & 0 deletions src/main/kotlin/dev/matsem/astral/sketches/radialwaves/TunnelSketch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package dev.matsem.astral.sketches.radialwaves

import dev.matsem.astral.sketches.BaseSketch
import dev.matsem.astral.sketches.SketchLoader
import dev.matsem.astral.tools.audio.AudioProcessor
import dev.matsem.astral.tools.automator.MidiAutomator
import dev.matsem.astral.tools.extensions.*
import dev.matsem.astral.tools.galaxy.Galaxy
import org.koin.core.inject
import processing.core.PApplet.*
import processing.core.PConstants.CLOSE
import processing.core.PConstants.TWO_PI

class TunnelSketch : BaseSketch() {

override val sketch: SketchLoader by inject()
private val audioProcessor: AudioProcessor by inject()
private val ex: extruder.extruder by inject()
private val automator: MidiAutomator by inject()
private val galaxy: Galaxy by inject()

private val slider1 = galaxy.createPot(channel = 13, cc = 4)
private val slider2 = galaxy.createPot(channel = 13, cc = 5)
private val slider3 = galaxy.createPot(channel = 13, cc = 6)
private val slider4 = galaxy.createPot(channel = 13, cc = 7)
private val slider5 = galaxy.createPot(channel = 13, cc = 8)
private val slider6 = galaxy.createPot(channel = 13, cc = 9)
private val slider7 = galaxy.createPot(channel = 13, cc = 10)
private val slider8 = galaxy.createPot(channel = 13, cc = 11)

private val hexagon = with(sketch) {
ex.extrude(
createShape().apply {
val radius = shorterDimension() / 2f
val angle = TWO_PI / 6

beginShape()
var a = 0f
while (a < TWO_PI) {
val sx = cos(a) * radius
val sy = sin(a) * radius
vertex(sx, sy)
a += angle
}
endShape(CLOSE)
},
50,
"box"
)
}

override fun onBecameActive() = Unit

override fun setup() = with(sketch) {
automator.setupWithGalaxy(
channel = 13,
recordButtonCC = 0,
playButtonCC = 1,
loopButtonCC = 2,
clearButtonCC = 3,
channelFilter = null
)
}

private var speed: Float = 0f
private var stroke = 0f
private var amplitude = 0f

override fun draw() = with(sketch) {
automator.update()

amplitude += audioProcessor.getRange(100f..500f)
amplitude *= 0.5f

val targetStroke = slider1.rawValue.midiRange(1f, 10f)
val targetSpeed = slider2.rawValue.midiRange(1 / 10f, 4f)
val stepAplitudeMultiplier = slider6.rawValue.midiRange(0f, 1f)
val step = slider3.rawValue.midiRange(100f, 400f).toInt() +
amplitude.remap(0f, 100f, stepAplitudeMultiplier * -50f, stepAplitudeMultiplier * 50f).toInt()
val flickerThresh = slider4.rawValue.midiRange(0f, 1f)
val kickStrokeMultiplier = slider5.rawValue.midiRange(0f, 4f)

if (audioProcessor.beatDetect.isKick) {
stroke = targetStroke * kickStrokeMultiplier
}

stroke = lerp(stroke, targetStroke, 0.1f)
speed = lerp(speed, targetSpeed, 0.1f)

background(bgColor)
noFill()
stroke(fgColor)
strokeWeight(stroke)
translateCenter()

polygon(amplitude, 6)

for (z in 200 downTo -2200 step step) {
val stroke = z.remap(0f, -2000f, stroke, stroke / 4f)
val realZ = z + saw(speed).mapp(0f, step.toFloat())
if (random(0f, 1f) > flickerThresh) {
strokeWeight(stroke)
pushMatrix()
translate(0f, 0f, realZ)
drawHexagon()
popMatrix()
}
}
}

private fun drawHexagon() = with(sketch) {
hexagon.forEachIndexed { index, shape ->
shape.disableStyle()
shape(shape)
}
}

private fun polygon(radius: Float, nPoints: Int) = with(sketch) {
val angle = TWO_PI / nPoints
beginShape()
var a = 0f
while (a < TWO_PI) {
val sx = cos(a) * radius
val sy = sin(a) * radius
vertex(sx, sy)
a += angle
}
endShape(CLOSE)
}
}
Binary file modified touchosc/Astral.touchosc
Binary file not shown.

0 comments on commit 54ae6d1

Please sign in to comment.