Skip to content

Instantly share code, notes, and snippets.

View nst's full-sized avatar

Nicolas Seriot nst

View GitHub Profile
@nst
nst / PostScript_nst021.sss
Created February 24, 2025 15:06
SubEthaEdit style for PostScript language
/* see https://seriot.ch/projects/programming_in_postscript.html#2 */
/* Comments */
/*
comment.block
comment.block.documentation.tag
comment.line
comment.line.double-dash
comment.line.double-slash
comment.line.number-sign
@nst
nst / cpc2.ps
Last active January 19, 2025 20:27
Amstrad CPC Color Palette in PostScript, take 2
%!PS
%%Title: cpc2.ps
%%Creator: Nicolas Seriot
% January 2025
% Amstrad CPC Color Palette
% https://www.cpcwiki.eu/index.php/CPC_Palette
% https://seriot.ch/projects/drawing_with_computers.html
% https://bsky.app/profile/nst021.bsky.social/post/3leytevn6ck25
@nst
nst / cpc.ps
Last active January 19, 2025 20:27
Amstrad CPC Color Palette in PostScript, take 1
%!PS
%%Title: cpc.ps
%%Creator: Nicolas Seriot
% January 2025
% Amstrad CPC Color Palette
% https://www.cpcwiki.eu/index.php/CPC_Palette
% https://seriot.ch/projects/drawing_with_computers.html
% https://bsky.app/profile/nst021.bsky.social/post/3leytevn6ck25
@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)