Aliens Among Us
#4
I better not build it up too much. I saw it here, 55 secs to 1:15 secs, https://www.youtube.com/watch?v=o1eLKODSCqw

I checked to see if done anywhere else, ie in code, no but I found this too,  
https://www.reddit.com/r/visualizedmath/...in_binary/

And here is code that draws out the "aliens":
Code: (Select All)
_Title "Pascal Triangle Aliens Among Us" '2022-10-10 bplus

_Define A-Z As _INTEGER64
Screen _NewImage(500, 500, 32)
_ScreenMove 350, 100

For row = 0 To 20 ' level on pyramind 0 is 1, 1 is 1,1  2 is 1,2,1...
    Print "Row"; row
    For col = 0 To row
        b$ = Dec2Bin$(binom(row, col))
        'Print b$; ",";
        h = (1 + Len(b$)) * 20
        For y = 1 To Len(b$)
            If Mid$(b$, y, 1) = "1" Then Line (250 - 10 * row + col * 20, 500 - h + y * 20)-Step(20, 20), _RGB32(0, 180, 0), BF
        Next
    Next
    Sleep
    Cls
Next

Function binom (n, m)
    binom = fac(n) / (fac(m) * fac((n - m)))
End Function

Function fac (n)
    f = 1
    For i = 1 To n
        f = f * i
    Next
    fac = f
End Function

Function Dec2Bin$ (integerBase10 As _Integer64) 'no more &B because easier to add than to remove
    Dim j As Integer, b$
    If integerBase10 = 0 Then Dec2Bin$ = "0": Exit Function
    While 2 ^ j <= integerBase10
        If (integerBase10 And 2 ^ j) > 0 Then b$ = "1" + b$ Else b$ = "0" + b$
        j = j + 1
    Wend
    Dec2Bin$ = b$
End Function

The coefficients are converted from decimal to binary and 1's draw green square, 0's stay black and squares stacked from highest power of 2 to 2^0 times 1 or 0 each column is a coefficient on the given row ie (a + b) ^ row

Marvin, Headphones, Janus, L-afant, and Humph!


Attached Files Image(s)
                   
b = b + ...
Reply


Messages In This Thread
Aliens Among Us - by bplus - 10-10-2022, 05:20 PM
RE: Aliens Among Us - by bplus - 10-10-2022, 09:42 PM
RE: Aliens Among Us - by James D Jarvis - 10-10-2022, 09:44 PM
RE: Aliens Among Us - by bplus - 10-10-2022, 11:10 PM
RE: Aliens Among Us - by Pete - 10-17-2022, 10:13 PM



Users browsing this thread: 2 Guest(s)