Pentacles

General FreeBASIC programming questions.
Post Reply
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Pentacles

Post by badidea »

2017 was not the first time that he got 'hacked', also in 2011. It seems that the 'Irish Mafia' was not a suspect back then.
Most likely, he just installed too much bad software:
"I've messed up my hard drive with 100 gigabytes of downloads of so many languages and compilers ..."
He is most likely a person with with autism in a world that he does not understand.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Pentacles

Post by dodicat »

Albert should be the one who replies to this stuff of course, but I believe he is on a type of community network which serves certain blocks of flats and is governed by a controller.
The whole lot were prone to attack at one stage and the controller blocked off some websites to try and stop it, mediafire was one example.
So, no, I don't think Albert is paranoid about anything.
Switching to Linux is a move thousands of people do to to lessen internet attacks.
Probably going back to Win 98 fat system would have the same effect.
Albert is just a guy with the American dream of making some money out of software, and goodness knows, he is not the only one.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: Pentacles

Post by angros47 »

He was complaining about stuff disappearing from his own computer. This is not related to the kind of network one could have, this looks more like he thought he wrote something and he didn't, or he forgot he deleted it.

Usually malware attacks encrypt or delete whole data, they don't delete random files at random intervals.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

Code: Select all

' Dark Planet, Hairy sphere.

Const As Integer n = 600    ' set number of hairs

Const As Double Pi = 4 * Atn( 1 )
Const As Double TwoPi = 8 * Atn( 1 )
Const As Double angle = Pi * ( 3 - Sqr( 5 ) )


Type geographic
    As Double lat, lon, hgt
End Type

Dim Shared As geographic a( 1 To n )


' precompute points
Randomize
Dim As Integer i
For i = 1 To n
    With a( i )
        .lat = Asin( 2 * i / ( n + 1 ) - 1 )
        .lon = i * angle
        .hgt = 0.1 + 0.2 * Rnd  ' hair length
    End With
Next i


' setup a graphics screen
Dim As Integer sx, sy, sz
Screeninfo sx, sy, sz
sx -= 64
sy -= 32
sz = 4      ' 4 bits = 16 colours
Screenres sx, sy, sz

Dim As Double hi = 1.4, lo = -hi, rhs = hi * sx / sy, lhs = -rhs
Window( lhs, lo )-( rhs, hi )


' display the rotating sphere
Dim As Double beta, x, y, z, xh, yh, zh, t, r = 1
Dim As Integer k = 7
Do
    For beta As Double = 0 To 2 * Pi Step 0.003 ' rotation angle
        
        Screenlock
        Cls
        
        For i = 1 To n
            With a( i )
                
                x = r * Cos( .lat ) * Cos( .lon + beta )
                ' y = r * Cos( .lat ) * Sin( .lon + beta )
                z = r * Sin( .lat )
                
                xh = x * ( r + .hgt )
                ' yh = y * ( r + .hgt )
                zh = z * ( r + .hgt )
                
                If Sin( .lon + beta ) < 0 Then  ' on this side
                    Circle( x, z ), 0.007, k
                    Line( x, z )-( xh, zh ), k
                Else
                    t = Sqr( xh*xh + zh*zh )
                    If t > r Then   ' hair is above horizon
                        Line( xh/t, zh/t )-( xh, zh ), k
                    End If
                End If
                
            End With
        Next i
        
        Screenunlock
        Sleep 10
        If Len( Inkey ) Then Exit Do
        
    Next beta
    
Loop

' Sleep
UEZ
Posts: 973
Joined: May 05, 2017 19:59
Location: Germany

Re: Pentacles

Post by UEZ »

@Richard: looks very nice. :-)
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: Pentacles

Post by jdebord »

Nice demo :)

It seems that the variable k is not used.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

@jdebord. Well found.
K was used for the colour in the plotting commands. It seems k got replaced with a constant 7 during a major edit, while I was changing colours to debug the 3D math.

Have you tried adjusting the; angle = Pi * ( 3 - Sqr( 5 ) ) ?

I wanted the simplest possible test bed for a few ideas.
I like the two? starfish patterns that appear for n = 10,000 and above.
I can see a black sphere against the black background, but only because of the hair.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Pentacles

Post by srvaldez »

Hi Richard
I like angle = Pi * ( 3 - Sqr( 1.5 ) )
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

angle = Pi * ( 3 + Sqr( 1.5 ) ) looks like it is coming up in the world.
bfuller
Posts: 362
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Re: Pentacles

Post by bfuller »

Fascinating. How do you come up with stuff like this? ----not need to answer LOL!
Basics
Posts: 4
Joined: Feb 21, 2019 14:27

Re: Pentacles

Post by Basics »

To me, it is trivial algebra, in need of rationalization.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

Basics wrote:To me, it is trivial algebra, in need of rationalization.
OK, so how could you rationalise it ?
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Pentacles

Post by badidea »

For fun, some color added to the neural network thing I am working on:

Code: Select all

'sick of typing integer
#define i8 byte
#define u8 ubyte
#define i16 short
#define u16 ushort
#define i32 long
#define u32 ulong
#define i64 longint
#define u64 ulongint
#define f32 single
#define f64 double

#define rnd_range(low, high)_
	(rnd(1) * (high - low) + low)

#define max(v1, v2)_
	(iif(v1 > v2, v1, v2))

#define min(v1, v2)_
	(iif(v1 < v2, v1, v2))

'value range: -1...+1
function smart_color(value as f32) as u32
	if value > 0 then
		return rgb(255 - min(value * 256, 255), 255, 0)
	else
		return rgb(255, 255 - min(-value * 256, 255), 0)
	end if
end function

type layer_type
	dim as i32 num_cells
	dim as f32 cell(any)
	dim as f32 link(any, any) 'N input <-> M output
end type

type nn_type
	dim as i32 num_layers
	dim as layer_type layer(any)
	declare constructor(num_cells() as i32)
	declare destructor()
	declare sub show_summary()
	declare sub visualise(w as i32, h as i32)
end type

'build and initialise the neural network
constructor nn_type(num_cells() as i32)
	dim as i32 ub = ubound(num_cells)
	num_layers = ub + 1
	redim layer(0 to ub)
	for i as i32 = 0 to ub
		layer(i).num_cells = num_cells(i)
		redim (layer(i).cell)(num_cells(i)) 'crazy syntax, who needs pointers anyway?
		'fill cells with initial values
		for j as i32 = 0 to num_cells(i) - 1
			layer(i).cell(j) = rnd_range(-1, +1)
		next
		'allocate memory for the links
		if i <> ub then 'skip final layer, no further links
			redim (layer(i).link)(num_cells(i), num_cells(i + 1)) 'more crazy business!
			'fill links with initial values
			for j as i32 = 0 to num_cells(i) - 1
				for k as i32 = 0 to num_cells(i + 1) - 1
					layer(i).link(j, k) = rnd_range(-1, +1)
				next
			next
		end if
	next
	print "constructor nn_type() - done"
end constructor

'let do some clean-up
destructor nn_type()
	for i as i32 = 0 to ubound(layer)
		erase layer(i).link
		erase layer(i).cell
	next
	erase layer
	print "destructor nn_type() - done"
end destructor

sub nn_type.show_summary()
	print "num_layers: "; num_layers
	for i as i32 = 0 to num_layers - 1
		print "layer(" & i & ").num_cells: "; layer(i).num_cells
	next
end sub

'graphics screen needed, w = width, h = height
sub nn_type.visualise (w as i32, h as i32)
	dim as i32 cell_radius = 10
	dim as u32 cell_color = &hff00ff00 'green
	dim as u32 link_color = &hff0077ff 'blueish
	dim as i32 w_dist = w / num_layers
	'line(0, 0)-(w-1, h-1), &hff777777, bf
	for i as i32 = 0 to num_layers - 1
		dim as i32 num_cells = ubound(layer(i).cell)
		dim as i32 h_dist = h / num_cells
		for j as i32 = 0 to num_cells - 1
			cell_color = smart_color(layer(i).cell(j))
			dim as i32 x = w_dist * (i + 0.5)
			dim as i32 y = h_dist * (j + 0.5)
			circle (x, y), cell_radius, cell_color
			draw string(16 + x, y - 8), str(layer(i).cell(j))
		next
		if i <> num_layers - 1 then 'skip last layer
			dim as i32 num_cells_next = ubound(layer(i + 1).cell)
			dim as i32 h_dist_next = h / num_cells_next
			for j as i32 = 0 to num_cells - 1
				for k as i32 = 0 to num_cells_next - 1
					link_color = smart_color(layer(i).link(j, k))
					dim as i32 x1 = w_dist * (i + 0.5)
					dim as i32 y1 = h_dist * (j + 0.5)
					dim as i32 x2 = w_dist * (i + 1.5)
					dim as i32 y2 = h_dist_next * (k + 0.5)
					line(x1, y1)-(x2, y2), link_color
				next
			next
		end if
	next
end sub

const as i32 SW = 800, SH = 600
screenres SW, SH, 32
width SW \ 8, SH \ 16

'the size of the neural network is define by the user/caller
dim as i32 nn_size_def(...) = {2, 8, 5, 3}
dim as nn_type nn = nn_type(nn_size_def())
nn.show_summary()
nn.visualise(SW, SH)

getkey()
screen 0 'close graphics screen, for destructor printout
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

Basics wrote:To me, it is trivial algebra, in need of rationalization.
It is difficult to rationalise the equation; angle = Pi * ( m + √n ); because that equation contains two irrational numbers. Any numerical constant would destroy the meaning.

Each point on the sphere is placed at a longitude that is rotated from the previous point by a fixed angle. Pi in radians represents 180°. The m is a multiple of 180° and the √n is an irrational number. Like Pi, the roots of the 'non-perfect-square' integers are all irrational.
( 1 + √5 ) / 2 is the golden ratio = 1.61803398875; that is related to sunflower patterns. That is what the; angle = Pi * ( m + √n ); equation is doing. It is interlacing points around the sphere, in a way that keeps them apart. It generates what is called a Fibonacci sphere.

Only values of m=0, or m=±1, are needed, since it cycles for odd and even integers > ±1.

Ideally, n will take a value of 5, but for this problem 2, 3, 6, 7, 8, and 10 can also work. Obviously √4 and √9 result in integer multiples of 180°, which collapse to form a North-South straight line of points.

If any irrational square root is written as a continued fraction it always recurs. For example; √5 = 2 + 1 / ( 4 + 1 / ( 4 + 1 / ( 4 + … ) ) ); The blocks of roots are separated by the perfect squares. Which is a bit like the periodic table of the elements, where the rows are separated by the noble gases.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

badidea wrote:For fun, some color added to the neural network thing I am working on:
I do like the colours, but what would you suggest I use the NN for?
Post Reply