Skip to content

Instantly share code, notes, and snippets.

View nst's full-sized avatar

Nicolas Seriot nst

View GitHub Profile
@nst
nst / anim.ps
Created December 10, 2024 17:49
Animated PostScript
%!PS
%%BoundingBox: 0 0 320 240
% gv -infoSilent anim.ps
/Courier findfont 12 scalefont setfont
/sleep { 100000 mul {} repeat } def
/x 100 def
@nst
nst / x.py
Last active December 8, 2024 10:25
Titou
import pygame
pygame.init()
# 1 = en haut à droite
# 2 = en bas à droite
# 3 = en bas à gauche
# 4 = en haut à gauche
l_écran = 400
import pygame as p
import random
R,r,W,H,G,N=range,random.randrange,480,320,3,5
g=[[r(W),r(H),r(W),r(H)]+[r(-9,9,2)for _ in R(4)] for _ in R(G)]
p.init()
s=p.display.set_mode((W,H))
f=lambda n,d,L:(n+(d:=d*(-1 if n+d not in R(L)else 1)),d)
while 1:
s.fill([0]*3)
for i,l in enumerate(g):
const canvas = document.getElementById('lines');
const ctx = canvas.getContext('2d');
const W = canvas.width;
const H = canvas.height;
const G = 4, N = 6;
const rand = (max, step = 1) => Math.floor(Math.random() * max / step) * step;
const next = (line, vel) => line.map((p, i) => (vel[i] *= (p + vel[i] >= 0 && p + vel[i] < (i % 2 ? H : W)) ? 1 : -1, p + vel[i]));
const drawLines = (lines, ctx) => lines.forEach(l => ctx.stroke(new Path2D(`M ${l[0]} ${l[1]} L ${l[2]} ${l[3]}`)));
import pygame as p
import random as m
R=range
r=m.randrange
S=(480,320)
def n(l,v):
for i in R(4):
v[i]*=-1+2*(l[i]+v[i]in R(S[i%2]))
return[l[i]+v[i]for i in R(4)]
V=[[r(-9,9,2)]*4for _ in R(5)]
@nst
nst / lines_no_class_short.py
Last active November 18, 2024 12:41
lines_no_class_short.py
import pygame as pg
import random as r
W, H = 800, 600
G, L = 4, 6
def next(l, v):
for i in range(4):
v[i] *= 1 if l[i] + v[i] in range(W if i % 2 == 0 else H) else -1
return [l[i] + v[i] for i in range(4)]
import pygame
import random
WIDTH = 800
HEIGHT = 600
NB_GROUPS = 5
HISTO_SIZE = 8
LINE_COLOR = (255,255,255)
BKG_COLOR = (0,0,0)
import pygame
import random
WIDTH, HEIGHT = 800, 600
NB_GROUPS, NB_LINES_PER_GROUP = 4, 6
vectors, lines = [], []
def next(l, v):
for i in range(4):
@nst
nst / lines.py
Last active November 15, 2024 14:38
Reproduce an early 90s Macintosh screensaver
# Reproduce an early 90s Macintosh screensaver
# Nicolas Seriot 2024-11-13 https://seriot.ch
# https://x.com/nst021/status/1856605627264417931
import pygameimport pygame
import random
WIDTH = 800
HEIGHT = 600
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="generator" content="Adobe GoLive 4">
<title>grands textes de linguistique slave</title>
<style>
body {
font-family: Arial, sans-serif;