Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -1,11 +1,11 @@
import gintro/[glib, gobject, gtk, gio, cairo]
import gtk2, glib2, gdk2, cairo
const
Width = 600
Height = 460
type
Color = array[3, float]
Color = (float, float, float)
Edge {.pure.} = enum LT, TR, RB, BL
const
@ -23,20 +23,23 @@ const
[TR, LT, LT, BL, BL, RB, RB, TR, TR, LT, LT, BL],
[TR, TR, LT, LT, BL, BL, RB, RB, TR, TR, LT, LT]]
Black: Color = [0.0, 0.0, 0.0]
Blue: Color = [0.2, 0.3, 1.0]
White: Color = [1.0, 1.0, 1.0]
Yellow: Color = [0.8, 0.8, 0.0]
Black: Color = (0.0, 0.0, 0.0)
Blue: Color = (0.2, 0.3, 1.0)
White: Color = (1.0, 1.0, 1.0)
Yellow: Color = (0.8, 0.8, 0.0)
Colors: array[Edge, array[4, Color]] = [[White, Black, Black, White],
[White, White, Black, Black],
[Black, White, White, Black],
[Black, Black, White, White]]
#---------------------------------------------------------------------------------------------------
proc draw(area: DrawingArea; context: Context) =
## Draw the pattern in the area.
template setSource(ctx: ptr Context; color: Color) =
ctx.setSourceRgb(color[0], color[1], color[2])
proc draw(context: ptr Context) =
## Draw the pattern.
func line(x1, y1, x2, y2: float; color: Color) =
context.setSource(color)
@ -62,34 +65,33 @@ proc draw(area: DrawingArea; context: Context) =
line(px + 23, py + 23, px, py + 23, carray[2])
line(px, py + 23, px, py, carray[3])
#---------------------------------------------------------------------------------------------------
proc onDraw(area: DrawingArea; context: Context; data: pointer): bool =
proc onExposeEvent(area: PDrawingArea; event: PEventExpose; data: pointer): gboolean {.cdecl.} =
## Callback to draw/redraw the drawing area contents.
area.draw(context)
let context = cairoCreate(area.window)
context.draw()
result = true
#---------------------------------------------------------------------------------------------------
proc activate(app: Application) =
## Activate the application.
proc onDestroyEvent(widget: PWidget; data: pointer): gboolean {.cdecl.} =
## Process the "destroy" event.
mainQuit()
let window = app.newApplicationWindow()
window.setSizeRequest(Width, Height)
window.setTitle("Peripheral drift illusion")
# Create the drawing area.
let area = newDrawingArea()
window.add(area)
nimInit()
let window = windowNew(WINDOW_TOPLEVEL)
window.setSizeRequest(Width, Height)
window.setTitle("Peripheral drift illusion")
# Connect the "draw" event to the callback to draw the pattern.
discard area.connect("draw", ondraw, pointer(nil))
# Create the drawing area.
let area = drawingAreaNew()
window.add area
window.showAll()
# Connect the "expose" event to the callback to draw the pattern.
discard area.signalConnect("expose-event", SIGNAL_FUNC(onExposeEvent), nil)
#———————————————————————————————————————————————————————————————————————————————————————————————————
# Quit the application if the window is closed.
discard window.signalConnect("destroy", SIGNAL_FUNC(onDestroyEvent), nil)
let app = newApplication(Application, "Rosetta.Illusion")
discard app.connect("activate", activate)
discard app.run()
window.showAll()
main()

View file

@ -0,0 +1,69 @@
function pdi_circle(cell_size = 50, numrows = 15, numcols = 15, radius = 15, offset = 5, rotx = 2, roty = 2, color1 = [0, 0, 255], color2 = [0, 255, 0])
% creates peripheral drift illusion using circles
% pdi_circle(cell_size, numrows, numcols, radius, offset, rotx, roty, color1, color2)
% pdi_circle(50, 15, 15, 15, 5, 2, 2, [0, 0, 255], [0, 255, 0])
% color dimension
colorB = uint8([0, 0, 0]);
colorW = uint8([255, 255, 255]);
color1 = uint8(color1);
color2 = uint8(color2);
% pixels per cell
centerC = cell_size * [1 1] / 2;
[cellX, cellY] = ndgrid(1:cell_size, 1:cell_size);
cell_ones = ones(cell_size, cell_size, "uint8");
% total image size
img_size = [numrows, numcols] * cell_size
final_image = zeros(img_size(1), img_size(2), 3, "uint8");
% offset steps
stepx = 2 * pi * rotx / numrows;
stepy = 2 * pi * roty / numcols;
% loop over cells
for nr = 1:numrows, for nc = 1:numcols
% find offset centers
step_phase = (nr-1) * stepx + (nc-1) * stepy;
offsetC = offset * [cos(step_phase), sin(step_phase)];
centerB = centerC + offsetC;
centerW = centerC - offsetC;
% fill background
image1 = cell_ones * color2(1);
image2 = cell_ones * color2(2);
image3 = cell_ones * color2(3);
% fill white
insideW = sqrt((cellX - centerW(1)).^2 + (cellY - centerW(2)).^2) <= radius;
image1(insideW) = colorW(1);
image2(insideW) = colorW(2);
image3(insideW) = colorW(3);
% fill black
insideB = sqrt((cellX - centerB(1)).^2 + (cellY - centerB(2)).^2) <= radius;
image1(insideB) = colorB(1);
image2(insideB) = colorB(2);
image3(insideB) = colorB(3);
% fill foreground
insideC = sqrt((cellX - centerC(1)).^2 + (cellY - centerC(2)).^2) <= radius;
image1(insideC) = color1(1);
image2(insideC) = color1(2);
image3(insideC) = color1(3);
% generate image
offset_image = cat(3, image1, image2, image3);
final_rows = (nr-1) * cell_size + [1:cell_size];
final_cols = (nc-1) * cell_size + [1:cell_size];
final_image(final_rows, final_cols, :) = offset_image;
endfor, endfor
% show and save image
imshow(final_image)
imwrite(final_image, "PeripheralDriftOctave.png")
endfunction

View file

@ -0,0 +1,56 @@
import pygame
width, height = 750, 700
RADIUS = width // 15
width += RADIUS
height += RADIUS
def calculate_angle_pos(
start: tuple[int | float, int | float], radius: int | float, angle: int | float
):
vec = pygame.math.Vector2(0, -radius).rotate((angle) % 360)
return start[0] + vec.x, start[1] + vec.y
def main():
pygame.init()
pygame.display.set_caption('Drift Illusion')
screen = pygame.display.set_mode((width, height))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((0, 125, 0))
step = 360 / 15
angle = step
for y in range(RADIUS, height, RADIUS):
for x in range(RADIUS, width, RADIUS):
rad = RADIUS // 3
comp_angle = (angle + 180) % 361
x1, y1 = calculate_angle_pos((x, y), (1/2.5) * rad, angle)
x2, y2 = calculate_angle_pos((x, y), (1/2.5) * rad, comp_angle)
pygame.draw.circle(screen, (255, 255, 255), (x1, y1), rad)
pygame.draw.circle(screen, (0, 0, 0), (x2, y2), rad)
pygame.draw.circle(screen, (0, 0, 255), (x, y), rad)
angle = (angle - step) % 361
angle = (angle - step) % 361
pygame.display.flip()
pygame.quit()
if __name__ == '__main__':
main()