ChatGPT

Sure! Here are a few examples of Julia code that you can use to explore graphic creation on an ARM64 SBC:

Mandelbrot Set

The Mandelbrot set is a popular fractal that can be generated using Julia. Here's some code to generate and display a Mandelbrot set:

julia

Copy code

using Cairo, Colors

function mandelbrot(c)

z = 0.0

for i = 1:100

z = z^2 + c

if abs2(z) > 4.0

return i

end

end

return 101

end

surface = Cairo.CairoImageSurface(500, 500)

context = Cairo.CairoContext(surface)

for x = 1:500, y = 1:500

i = mandelbrot(complex((x-250)/200, (y-250)/200))

set_source_rgb(context, i/100, i/100, i/100)

rectangle(context, x, y, 1, 1)

fill(context)

end

save("mandelbrot.png", surface)

Fractal Tree

The fractal tree is another interesting graphical object that can be generated using Julia. Here's some code to generate a fractal tree:

julia

Copy code

using Cairo, Colors

function draw_branch(context, x1, y1, angle, length)

if length < 2

return

end

x2 = x1 + length * cos(angle)

y2 = y1 + length * sin(angle)

line_width(context, length/10)

set_source_rgb(context, length/100, length/100, length/100)

move_to(context, x1, y1)

line_to(context, x2, y2)

stroke(context)

draw_branch(context, x2, y2, angle + pi/4, length/2)

draw_branch(context, x2, y2, angle - pi/4, length/2)

end

surface = Cairo.CairoImageSurface(500, 500)

context = Cairo.CairoContext(surface)

set_source_rgb(context, 1, 1, 1)

rectangle(context, 0, 0, 500, 500)

fill(context)

draw_branch(context, 250, 500, -pi/2, 100)

save("fractal_tree.png", surface)

Julia Set

The Julia set is another type of fractal that can be generated using Julia. Here's some code to generate a Julia set:

julia

Copy code

using Cairo, Colors

function julia(z, c)

for i = 1:100

z = z^2 + c

if abs2(z) > 4.0

return i

end

end

return 101

end

surface = Cairo.CairoImageSurface(500, 500)

context = Cairo.CairoContext(surface)

for x = 1:500, y = 1:500

i = julia(complex((x-250)/200, (y-250)/200), -0.4+0.6im)

set_source_rgb(context, i/100, i/100, i/100)

rectangle(context, x, y, 1, 1)

fill(context)

end

save("julia_set.png", surface)

using Gtk, Graphics, Colors

const win = GtkWindow("Color Wheel", 450, 450) |> (const can = @GtkCanvas())

set_gtk_property!(can, :expand, true)

@guarded draw(can) do widget

ctx = getgc(can)

h = height(can)

w = width(can)

center = (x = w / 2, y = h / 2)

anglestep = 1/w

for θ in 0:0.1:360

rgb = RGB(HSV(θ, 1, 1))

set_source_rgb(ctx, rgb.r, rgb.g, rgb.b)

line_to(ctx, center...)

arc(ctx, center.x, center.y, w/2.2, 2π * θ / 360, anglestep)

line_to(ctx, center...)

stroke(ctx)

end

end

show(can)

const condition = Condition()

endit(w) = notify(condition)

signal_connect(endit, win, :destroy)

wait(condition)

These examples should give you a good starting point for exploring graphic creation using Julia on an ARM64 SBC!

Code: Select all

```
using Gtk, Graphics, Colors
const win = GtkWindow("Color Wheel", 1000, 1000) |> (const can = @GtkCanvas())
set_gtk_property!(can, :expand, true)
@guarded draw(can) do widget
ctx = getgc(can)
h = height(can)
w = width(can)
center = (x = w / 2, y = h / 2)
anglestep = 1/w
for θ in 0:0.1:360
rgb = RGB(HSV(θ, 1, 1))
set_source_rgb(ctx, rgb.r, rgb.g, rgb.b)
line_to(ctx, center...)
arc(ctx, center.x, center.y, w/2.2, 2π * θ / 360, anglestep)
line_to(ctx, center...)
stroke(ctx)
end
end
show(can)
const condition = Condition()
endit(w) = notify(condition)
signal_connect(endit, win, :destroy)
wait(condition)
```

Code runs about twice as fast, compared to 64 bit Debian /Kernel 6.1 , on this rPi-400 that generated the attached ColorWheel.