Skip to content

Rework of Fable#102

Open
leios wants to merge 1 commit into
mainfrom
from_scratch
Open

Rework of Fable#102
leios wants to merge 1 commit into
mainfrom
from_scratch

Conversation

@leios

@leios leios commented Jul 29, 2025

Copy link
Copy Markdown
Owner

This is a complete overhaul of Fable to allow users to write their own kernels:

using KernelAbstractions
using Images
include("from_scratch.jl")

function output_and_scale(pix, cam, pt, clr, x_scale; y_scale = 3)
    pt_2 = FablePoint(pt.x*x_scale, pt.y*y_scale)

    simple_output(pix, cam, pt_2, clr)
end

@kernel function generate_square(pix, cam, g)
    A = FablePoint(-0.5, 0.5)
    B = FablePoint(0.5, 0.5)
    C = FablePoint(0.5, -0.5)
    D = FablePoint(-0.5, -0.5)

    pt = FablePoint(0.0,0.0)
    clr = RGBA{Float32}(0,0,0,1)
    square_clr = RGBA{Float32}(1,0,1,1)
    square(pix, cam, 100, pt, clr, 
           A, square_clr, B, square_clr, C, square_clr, D, square_clr, g, 2; y_s
cale = 0.5)
           #pix, cam, pt, clr)
end

function main(;ArrayType = Array)
    width = 1920
    height = 1080
    pixels = ArrayType(zeros(RGBA{Float32},height, width))

    world_size_x = 4;
    ppu = width / world_size_x;
    world_size_y = height/ppu;

    world_size = FablePoint(world_size_x, world_size_y)
    world_position = FablePoint(-world_size.x * 0.5, -world_size.y*0.5)

    cam = FableSimpleCamera(ppu, world_size, world_position)

    backend = get_backend(pixels)
    kernel! = generate_square(backend, 256)
    kernel!(pixels, cam, output_and_scale; ndrange = width*height)
    return pixels
    save("check.png", Array(pixels))
end

Things still to do:

  • update docs
  • redo all examples
  • tests
  • allow for colors to also be functions for generators
  • Generally make generators nicer (more kwargs, less args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant