Hi Albert I'll have a fiddle around later.
But, as you know, during all these years of bigint, I have kept to string[48] to string[57] only.
Yourself and Richard have been using ulong steps, so I kept mine strictly to my own.
So, I have always have the headache of speed.
Maybe I'll branch out.
In the meantime, in the spirit of squares:
Code: Select all
Type Point
As single x,y 'need floats for smoothness when moving or rotating points
Declare sub rotate(As Point,As Single,As Single)' As Point
End Type
sub point.rotate(pivot As Point,a As Single,d As Single)' As Point
dim as point t=type(d*(Cos(a*.0174533)*(x-pivot.x)-Sin(a*.0174533)*(y-pivot.y)) +pivot.x,_
d*(Sin(a*.0174533)*(x-pivot.x)+Cos(a*.0174533)*(y-pivot.y)) +pivot.y)
this=t
End sub
Type Rectangle field=1
As Ushort wide
As Ushort high
As Single aspect
As Byte pflag 'fill or not
As Ulong clr 'colour
Declare Constructor(As Point=type(0,0),As Ushort=0,As Ushort=0,As Single =0,As Ulong=0,As Byte=0)
As Point v(1 To 4) 'extra points for vertices/centroid
As Point centroid
Declare Sub Draw()
End Type
Constructor rectangle(c As Point,w As Ushort,h As Ushort,a As Single,col As Ulong,pf As Byte)
v(1)=type(c.x-w/2,c.y-h/2)
v(2)=type(c.x-w/2,c.y+h/2)
v(3)=type(c.x+w/2,c.y+h/2)
v(4)=type(c.x+w/2,c.y-h/2)
For n As Long=1 To 4
v(n).rotate(c,a,1)
Next
pflag=pf
clr=col
aspect=a
wide=w
high=h
centroid=c
End Constructor
Sub fill(a() As Point,c As Ulong,min As Long,max As Long)
'translation of a c snippet
static As Long i,j,k,dy,dx, x,y,temp
Static As Long NewX (1 To Ubound(a))
Static As Single Grad(1 To Ubound(a))
For i=1 To Ubound(a) - 1
dy=a(i+1).y-a(i).y
dx=a(i+1).x-a(i).x
If(dy=0) Then Grad(i)=1
If(dx=0) Then Grad(i)=0
If ((dy <> 0) And (dx <> 0)) Then
Grad(i) = dx/dy
End If
Next i
For y=min To max
k = 1
For i=1 To Ubound(a) - 1
If( ((a(i).y<=y) Andalso (a(i+1).y>y)) Or ((a(i).y>y) _
Andalso (a(i+1).y<=y))) Then
NewX(k)= Int(a(i).x+ Grad(i)*(y-a(i).y))
k +=1
End If
Next i
For j = 1 To k-2
For i = 1 To k-2
If NewX(i) > NewX(i+1) Then
temp = NewX(i)
NewX(i) = NewX(i+1)
NewX(i+1) = temp
End If
Next i
Next j
For i = 1 To k - 2 Step 2
Line (NewX(i),y)-(NewX(i+1)+1,y), c
Next i
Next y
End Sub
Sub rectangle.draw()
Static As Single miny=1e6,maxy=-1e6
Static As Point V1(1 To Ubound(v)+1)
For n as long =1 To Ubound(v)
If pflag=0 Then If n<Ubound(v) Then Line(v(n).x,v(n).y)-(v(n+1).x,v(n+1).y),clr
If miny>v(n).y Then miny=v(n).y
If maxy<v(n).y Then maxy=v(n).y
V1(n)=v(n)
Next
If pflag=0 Then Line -(v(1).x,v(1).y),clr
v1(Ubound(v1))=v(Lbound(v))
If pflag Then fill(v1(),clr,miny,maxy)
End Sub
Function Regulate(Byval MyFps As long,Byref fps As long) As Integer
Static As Double timervalue,lastsleeptime,t3,frames
Var t=Timer
frames+=1
If (t-t3)>=1 Then t3=t:fps=frames:frames=0
Var sleeptime=lastsleeptime+((1/myfps)-T+timervalue)*1000
If sleeptime<1 Then sleeptime=1
lastsleeptime=sleeptime
timervalue=T
Return sleeptime
End Function
'=================================== demo ===================
Randomize
Screen 19,32,,64
Dim As rectangle r(1 To 100)
dim as long fps
'initial setup
For n As Long=1 To ubound(r)
dim as point middle=type(Rnd*850-Rnd*50,Rnd*650-Rnd*50) 'centroid of rectangle
r(n)=rectangle(middle,5+Rnd*100,5+Rnd*100,Rnd*360-Rnd*360,Rgba(50+Rnd*205,50+Rnd*205,50+Rnd*205,150*Rnd*105),1)
' width height aspect colour fill
Next
Dim As Single k=1
Dim As Byte endflag
Do
If endflag Then k-=.005
Screenlock
Cls
draw string (20,20),"Fps " &fps
'change aspects and centroid positions
For n As Long=1 To ubound(r)
r(n).centroid.rotate(type(400,300),.5,k)
r(n).aspect+=Sgn(r(n).aspect)
'refresh via constructor
r(n)=rectangle(r(n).centroid,r(n).wide,r(n).high,r(n).aspect,r(n).clr,r(n).pflag)
r(n).draw
Next
Screenunlock
Sleep regulate(60,fps),1
If Len(inkey) Then endflag=1
Loop Until k<.4
sleep 1500