![]() |
Forum Index : Microcontroller and PC projects : Fractal Images
![]() ![]() |
|||||
Author | Message | ||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
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: GermanyPosts: 1593 |
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: AustraliaPosts: 6283 |
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: CanadaPosts: 1134 |
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: GermanyPosts: 1593 |
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: ThailandPosts: 2209 |
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: GermanyPosts: 1593 |
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 causality ≠ correlation ≠ coincidence |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |