Skip to content

Instantly share code, notes, and snippets.

View gzoritchak's full-sized avatar

Gaetan Zoritchak gzoritchak

View GitHub Profile
package io.data2viz.examples.thomas
import io.data2viz.color.Colors
import io.data2viz.geom.Size
import io.data2viz.scale.Scales
import io.data2viz.viz.JFxVizRenderer
import io.data2viz.viz.Viz
import io.data2viz.viz.viz
import javafx.application.Application
@gzoritchak
gzoritchak / JavaFxAnimationTest.kt
Created July 5, 2017 21:32
Just a test of JavaFx animation.
package io.data2viz.svg
import javafx.animation.AnimationTimer
import javafx.application.Application
import javafx.scene.Group
import javafx.scene.Scene
import javafx.scene.paint.Color
import javafx.scene.shape.Circle
import javafx.scene.shape.Rectangle
import javafx.stage.Stage
@gzoritchak
gzoritchak / HTMLColors.kt
Created June 28, 2017 12:05
Html colors in a subpackage.
package io.data2viz.color.htmlColors
import io.data2viz.color.colors.col
val aliceblue by lazy { 0xf0f8ff.col }
val aqua by lazy { 0x00ffff.col }
val aquamarine by lazy { 0x7fffd4.col }
val azure by lazy { 0xf0ffff.col }
val beige by lazy { 0xf5f5dc.col }
val bisque by lazy { 0xffe4c4.col }
// runs the code in the background thread pool
fun asyncOverlay() = async(CommonPool) {
// start two async operations
val original = asyncLoadImage("original")
val overlay = asyncLoadImage("overlay")
// and then apply overlay to both results
applyOverlay(original.await(), overlay.await())
}
// launches new coroutine in UI context
package jug.dsl
val kotlinSurveyDef = createNewSurveyDef("Évaluation du kotlin user group") {
introduction = "Merci de prendre 20 secondes pour répondre à quelques questions."
val appreciation = intQuestion("Quelle est votre appréciation de la dernière session ?"){
min = 1
max = 5
}
package org.gzk.marslander
import java.io.StringReader
import java.util.*
fun main(args: Array<String>) {
val bestChimp = findBestChimp(::createMarsLander1FromGenome, ::marsLander1Fitness)
println(
bestChimp.result.trajectory.drop(1).joinToString (transform = { state -> "${state.angle}, ${state.power}" })
)
package org.gzk.marslander
import java.lang.Math.random
val log = true
val elitism = true
val generationsCount = 10
val populationSize = 20
val genomeSize = 1200
package org.gzk.marslander
data class Time(val sec:Double)
val Double.sec: Time
get() = Time(this)
/**
* Speed is internally using a vector, allowing to compose it. speed12 = speed1 + speed2
*/
package org.gzk.marslander
import java.lang.Math.*
/**
* A point in a 2 dimensions cartesian system.
* Point + Vector -> Point
* Point - Point -> Vector
*/
data class Point(val x:Double, val y: Double) {
@gzoritchak
gzoritchak / Lander.kt
Last active June 8, 2016 14:14
A Genetic Algorithm implementation of CodingGame MarsLander1 puzzle.
package org.gzk.marslander
val GRAVITY = acceleration(0.0, -3.711)
val maxX = 6999
val minX = 0
/**
* power : 0, 1, 2, 3, 4
* angle : -90, -75, ... , 0, +15, +30, ..., +75, +90
*/