Skip to content

Instantly share code, notes, and snippets.

View alexmaryin's full-sized avatar
🐕
Fuck the war

Alex Maryin alexmaryin

🐕
Fuck the war
View GitHub Profile
@alexmaryin
alexmaryin / hasBackground_matcher.kt
Created June 9, 2022 11:54
Semantic matcher for Jetbtains Compose matching background color and shape
/**
* Thanks for https://stackoverflow.com/a/72529233/15257426
*/
fun hasBackground(expectedColor: Color, expectedShape: Shape = RectangleShape): SemanticsMatcher = SemanticsMatcher("background color") {
it.layoutInfo.getModifierInfo().forEach {info ->
println(info.modifier.toString())
}
it.layoutInfo.getModifierInfo().any { modifierInfo ->
modifierInfo.modifier == Modifier.background(expectedColor, expectedShape)
}
program sdl_test;
uses
sdl2, SysUtils, ctypes, Math, SDL_DrawCircles;
const
Width = 1360;
Height = 760;
CENTER = SDL_WINDOWPOS_CENTERED;
STARS_COUNT = 200;
@alexmaryin
alexmaryin / starfield_pas_circle.pas
Created May 6, 2022 12:40
Starfield Pascal Circle
unit SDL_DrawCircles;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, sdl2, ctypes;
function SDL_RenderFillCircle(renderer: PSDL_Renderer; x: cint32;
@alexmaryin
alexmaryin / starfield_kt_engine.kt
Created May 6, 2022 11:28
Starfield Kotlin SDL engine
import cnames.structs.SDL_Renderer
import cnames.structs.SDL_Window
import kotlinx.cinterop.*
import platform.SDL2.*
typealias EventListener = (SDL_Event) -> Unit
class Engine(width: Int, height: Int) {
var window: CPointer<SDL_Window> private set
@alexmaryin
alexmaryin / starfield_kt_main.kt
Created May 6, 2022 08:40
Starfield Kotlin main
fun main() {
SDLEngine(Consts.WIDTH, Consts.HEIGHT) {
val fpsCounter = FPSCounter(window)
val stars = List(Consts.STARS_COUNT) { Star() }
addEventListener("starfield") { event ->
if (event.type == SDL_QUIT) stopLoop()
}
// imports ...
const int WIDTH = 1360, HEIGHT = 760;
const int H_WIDTH = WIDTH / 2;
const int H_HEIGHT = HEIGHT / 2;
const int STARS_COUNT = 200;
float speed = 0.1;
float radius_delta = 0.001;
Uint32 fps_lasttime = SDL_GetTicks();
Uint32 fps_frames = 0;
@alexmaryin
alexmaryin / starfield_cpp_init.cpp
Created May 5, 2022 12:52
starfield C++ init SDL
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *window = SDL_CreateWindow("C++ SDL window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI);
if (window == NULL)
{
std::cout << "Could not create window: " << SDL_GetError() << std::endl;
return 1;
}
struct Star
{
float x, y, z, radius, brightness, viewX, viewY;
Star() { newStar(); }
void newStar()
{
x = viewX = std::experimental::randint(0, WIDTH) - H_WIDTH;
y = viewY = std::experimental::randint(0, HEIGHT) - H_HEIGHT;
@alexmaryin
alexmaryin / starfield_python.py
Last active May 8, 2022 06:41
Starfield in Pythpon/Pygame
import random
import pygame
from pygame import gfxdraw
SX = 1360
SY = 760
num_stars = 5000
speed = 0.1
radius_delta = 0.001
@alexmaryin
alexmaryin / pascal_sieve.pas
Last active April 27, 2022 12:56
Freepascal sieve
program primes;
uses
fgl, SysUtils;
type
TIntegerList = specialize TFPGList<integer>;
function SieveEratosphen(n: integer): TIntegerList;
var