Dráždič mysle na dnes dva

Dráždič mysle na dnes dva

vidím to ako n^2-n-1=n^2-5, prečo? veď si v mysli doplň obrys okolo zelených na štvorec a koľko zelených získaš? no 4^2-4malé-1veľký == 11 A prečo tá ľavá strana? 2 po sebe idúce čísla mínus obrys? prečo n(n-1)? vieš si predstaviť aj trojuholník? vieš upraviť na štvorce hrán trj?

trojuholnik obdlznik

using Pkg
Pkg.add("Luxor")
Pkg.add("Colors")
using Luxor
using Colors

# =====================================
# Nastavenia
# =====================================
n = 14
cell = 36
fps = 30
seconds = 6

outfile = "smooth_square.gif"

W = n * cell + 40
H = n * cell + 40

frames = fps * seconds

# =====================================
# Pomocné funkcie
# =====================================
function ease(t)
    # smoothstep
    return t * t * (3 - 2t)
end

function square_progress(index, totalframes)
    # kedy sa objaví konkrétny štvorec
    start = (index - 1) / (n^2)
    stop  = index / (n^2)

    p = clamp((totalframes - start) / (stop - start), 0, 1)
    return ease(p)
end

# =====================================
# Kreslenie
# =====================================
function draw_frame(scene, frame)

    background("white")
    origin()
    translate(-W/2, -H/2)

    t = frame / frames

    idx = 0

    for i in 1:n
        for j in 1:n
            idx += 1

            prog = square_progress(idx, t)

            if prog > 0.001

                x = 20 + (j-1)*cell + cell/2
                y = 20 + (i-1)*cell + cell/2

                s = (cell - 3) * prog

                if i > j
                    sethue(RGB(0.15,0.45,1.0))   # modrá
                elseif i < j
                    sethue(RGB(1.0,0.2,0.2))     # červená
                else
                    sethue("gray80")
                end

                box(Point(x,y), s, s, :fill)

                sethue("black")
                box(Point(x,y), s, s, :stroke)
            end
        end
    end

    # Text dole
    sethue("black")
    fontsize(18)
    text("n² = $(n^2)", Point(W/2 - 90, H - 10))
end

# =====================================
# Export GIF
# =====================================
movie = Movie(W, H, outfile)

animate(movie,
[
    Scene(movie, draw_frame, 1:frames)
],
creategif = true,
pathname = "."*outfile,
framerate = fps
)

println()
println("GIF vytvorený:")
println(joinpath(pwd(), outfile))
println()
println("Stlač Enter...")
readline()


Author: AarNoma

The first Slovak cyborg 1 system

Comments “Dráždič mysle na dnes dva”