Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:10 03 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Fractal Images

     Page 3 of 3    
Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 07:19am 25 Oct 2015
Copy link to clipboard 
Print this post

Try removing the space between AND and &h/b.

I was trying all kind of things and there were definite improvements removing spaces!

WW
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 11:15am 25 Oct 2015
Copy link to clipboard 
Print this post

  WhiteWizzard said   Try removing the space between AND and &h/b.


For C=0 To Q:B(C)=(C And&H4)*W+(C And&H2)*U+(C And 1)*255:Next

Result: no difference!


Code so far (365127ms, uM2@48Mhz 240x320px LCD)

'JULIA.BAS - Draws Julia set fractal images
'by loki
CPU 48 ' for uM2
Dim As Integer H, V, C, W, U, Q=80 'max iterations
Dim As integer B(Q+1)

CLS

'Specify initial values
S = 1.30
T = 0.95
'------------------------------------------------*
'Set the Julia set constant [eg C = -1.2 + 0.8i]
D = -0.78
E = -0.20
'------------------------------------------------*

GAP = MM.VRes / MM.HRes
SIZE = 2.50
P = SIZE / MM.HRes
O = (SIZE * GAP) / MM.VRes
H=MM.HRes-1
V=MM.VRes-1
W=4177920
U=32640

Timer=0
For C=0 To Q:B(C)=(C And &H4)*W+(C And &H2)*U+(C And 1)*255:Next
For X=0 To H:M=X*P-S:For Y=0 To V:J=Y*O-T:R=M
For C=0 To Q:If R*R+J*J>=&H4 Then Exit For
N=R*R-J*J+D:J=&H2*R*J+E:R=N
Next
Pixel X,Y,B(C):Next:Next

Print Timer
End


Regards
Michael
causality ≠ correlation ≠ coincidence
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:44pm 25 Oct 2015
Copy link to clipboard 
Print this post

Using Michael's latest code on my MM+ @100MHz with 7inch display
1317 seconds.
That's down form the original 1979 seconds or 22 minutes compared with 33 minutes.
Time for another beer at least!

Jim
VK7JH
MMedit
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1134
Posted: 07:23am 26 Oct 2015
Copy link to clipboard 
Print this post

What, oh what, have we created?

Which of these would you rather debug? ;-)

For C=0 To Q:B(C)=(C And &H4)*W+(C And &H2)*U+(C And 1)*255:Next
For X=0 To H:M=X*P-S:For Y=0 To V:J=Y*O-T:R=M
For C=0 To Q:If R*R+J*J>=&H4 Then Exit For
N=R*R-J*J+D:J=&H2*R*J+E:R=N
Next
Pixel X,Y,B(C):Next:Next

or
For X = 0 To (MM.HRes - 1)
CX = X * Xdelta + RealOffset
For Y = 0 To (MM.VRes - 1)
CY = Y * YDelta + ImaginOffset
Zr = CX
Zi = CY
COUNT = 0
'Begin Iteration loop
Do While (( COUNT <= MAXIT ) And (( Zr * Zr + Zi * Zi ) < 4 ))
new_Zr = Zr * Zr - Zi * Zi + CRealVal
new_Zi = 2 * Zr * Zi + CImagVal
Zr = new_Zr
Zi = new_Zi
COUNT = COUNT + 1
Loop
PIXEL X, Y, (COUNT and 4) * 4177920 + (COUNT and 2) * 32640 + (COUNT and 1) * 255)
Next Y
Next X

Visit Vegipete's *Mite Library for cool programs.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 07:42am 26 Oct 2015
Copy link to clipboard 
Print this post

  vegipete said   What, oh what, have we created?


A monster!
(The sleep of reason produces monsters)

And this proves also that not only C programmers can produce cryptic code!


... I hope newbies (in Basic programming) will not take this as a good example!

Michael
causality ≠ correlation ≠ coincidence
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:59am 26 Oct 2015
Copy link to clipboard 
Print this post

When speed is the goal then everything is allowed.

How much time is spend in the PIXEL routine?
Maybe just make a dummy subroutine to measure it.
[code]
SUB DUMMYPIXEL(x,y,c)
END SUB
[/code]


Microblocks. Build with logic.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 09:22am 26 Oct 2015
Copy link to clipboard 
Print this post

  MicroBlocks said   When speed is the goal then everything is allowed.

How much time is spend in the PIXEL routine?
Maybe just make a dummy subroutine to measure it.
[code]
SUB DUMMYPIXEL(x,y,c)
END SUB
[/code]


Hi MB,

I replaced the Pixel routine with a sub called "Dixel X,Y,B(C)". Result 390161 (instead of 365127). This is confusing and means a empty routine takes longer than the original routine.

When I delete the Pixel routine:
Timer=0
For C=0 To Q:B(C)=(C And &H4)*W+(C And &H2)*U+(C And 1)*255:Next
For X=0 To H:M=X*P-S:For Y=0 To V:J=Y*O-T:R=M
For C=0 To Q:If R*R+J*J>=&H4 Then Exit For
N=R*R-J*J+D:J=&H2*R*J+E:R=N
Next
Next:Next

Print Timer

I get 350784 (instead of 365127) =-14343ms. A 240x320 LCD has 76800 pixel.
14343/76800=0,187ms per pixel (using "Pixel X,Y,B(C)").

Regards
Michael

EDIT:
This allows you to confirm the above result:
3852 ticks=0.160375ms
CPU 48
Dim integer x=1,y=2,b=8
Dim integer empty=2957
Dim float tick_time=1/(48000000/2) 'for CPU 48, 1 Tick = 2 CPU cycles

x=StartCT()
Pixel X,Y,B(C)
x=ReadCT()
Print "Execution time:" x-empty " ticks ="; Int(tick_time*(x-empty)*1000000);"us (Pixel X,Y,B(C) )"

End


C source (very simple, quick & dirty and NOT generally applicable)
long long StartCT(void)
{
unsigned int zero=0;
asm volatile("mtc0 %0, $9": "+r"(zero));
return 0;
}

long long ReadCT(void)
{
unsigned int current_ticks;
asm volatile("mfc0 %0, $9": "=r"(current_ticks));
return current_ticks;
}


EDIT2:
Obviously X,Y should be integers and this takes again 3 sec less (362091ms):
'JULIA.BAS - Draws Julia set fractal images
'by loki
CPU 48 ' for uM2
Dim As Integer H, V, C, W, U, Q=80 'max iterations
Dim As integer B(Q+1),X,Y

CLS

'Specify initial values
S = 1.30
T = 0.95
'------------------------------------------------*
'Set the Julia set constant [eg C = -1.2 + 0.8i]
D = -0.78
E = -0.20
'------------------------------------------------*

GAP = MM.VRes / MM.HRes
SIZE = 2.50
P = SIZE / MM.HRes
O = (SIZE * GAP) / MM.VRes
H=MM.HRes-1
V=MM.VRes-1
W=4177920
U=32640

Timer=0
For C=0 To Q:B(C)=(C And &H4)*W+(C And &H2)*U+(C And 1)*255:Next
For X=0 To H:M=X*P-S:For Y=0 To V:J=Y*O-T:R=M
For C=0 To Q:If R*R+J*J>=&H4 Then Exit For
N=R*R-J*J+D:J=&H2*R*J+E:R=N
Next
Pixel X,Y,B(C):Next:Next
Print Timer
End
Edited by twofingers 2015-11-09
causality ≠ correlation ≠ coincidence
 
     Page 3 of 3    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025