Skip to content

Instantly share code, notes, and snippets.

@sebnozzi
sebnozzi / game.ms
Created May 4, 2024 14:20
Coin Collector Game for the Mini Micro
// Fox
foxImg = file.loadImage("fox.png")
fox = new Sprite
fox.image = foxImg
fox.localBounds = new Bounds
fox.localBounds.width = foxImg.width
fox.localBounds.height = foxImg.height
@sebnozzi
sebnozzi / animation.ms
Last active March 18, 2023 00:11
Snake movement
// Animation class
// It can animate a Sprite from its current position to
// a target position in the desired amount of time, in a
// series of steps.
//
// This last point is important, since it means other things
// can happen at the same time while animating (e.g. processing
// user input, animating other sprites, etc.)
@sebnozzi
sebnozzi / halved_randoms.ms
Last active October 8, 2022 20:53
Benchmark - Sum from halved random numbers
st = time
result = 0
counter = 0
while counter < 3000000
result = (result + rnd) / 2
counter = counter + 1
end while
print result
@sebnozzi
sebnozzi / scrollingTextDemo.ms
Last active March 25, 2022 19:53
Demo of wrapped scrolling text for the Mini Micro
import "stringUtil"
// Renders the given text on the given display in the
// given text size ("small"/"normal"/"large") starting
// at x=left, y=top up to a maximum of "maxWidth" pixels,
// wrapping to a next line if necessary
TextRenderer = {}
TextRenderer.display = null
TextRenderer.left = -1
TextRenderer.top = -1
@sebnozzi
sebnozzi / plasma.ms
Last active March 6, 2023 17:03
Plasma Effect - Mini Micro
canvasWidth = 50
canvasHeight = 50
scale = 10
speed = 0.2
colorToRgb = function(value)
return color.rgb(255,
255 * cos(value * pi),
255 * sin(value * pi))
end function
@sebnozzi
sebnozzi / memory.ms
Last active November 5, 2021 22:41
Memory game for the Mini Micro
// We need this for list.any, list.contains, list.remove ...
import "listUtil"
countRows=4
countCols=5
// How long can you look at cards before hiding them again
// In seconds
SECONDS_TO_PEEK=1
val jsonStrToSend = ""
val serverUrl = ""
def handleAjaxError(jqXHR: JQueryXHR, textStatus: String, errorThrow: String): Unit = {
println("Error while performing AJAX POST")
}
def handleAjaxSuccess(data: js.Any, textStatus: String, jqXHR: JQueryXHR): Unit = {
val jsonFromServer = jqXHR.responseText
println(s"Got from server: $jsonFromServer")
@sebnozzi
sebnozzi / callback-demo.dart
Created November 13, 2015 21:23
Dart Callback
class Event {
}
class SomeComponent {
// Q: How to express the type of _callback?
var _callback = (Event e) { /* dummy implementation */};
import scala.util.Random
/**
* @author Sebastian Nozzi
*/
object RaffleApp extends App with HelperMethods {
lazy val numberCandidates: Set[Int] = {
val allNumbers = (1 to 17).toSet
val numbersThatWonSomething = Set[Int]()
package org.scalavienna.refactoringdojo.gameoflife
case class Pos(col: Int, row: Int) {
def +(other: Pos): Pos = Pos(col + other.col, row + other.row)
}
case class Board(liveCells: Seq[Pos], size: Int) {
def isLiveCell(p: Pos) = liveCells.contains(p)
def nextIteration = BoardCalculator.nextIteration(this)