Forum Replies Created
-
AuthorPosts
-
Had a quick go at speeding this via render-to-pixmap and it’s not bad – was going 22FPS-ish, now does 60 if the mouse is at the edges!
A bit of hackery involved – it draws directly to a pixel ‘ptr’ instead of SetPixel( x,y ) so it’s not recalculating pixel address all the time.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141''' Julia Set example by abakobo'' a monkey 2 example-learning exercise' next steps/points of interest is to optimise: -the drawpoint speed' -the choice for globals, fields, locals'' Of course the use of the imagearray should finally be skipped for better perfomances'#Import "<std>"#Import "<mojo>"Using std..Using mojo..Global w_width:=800 'window sizeGlobal w_height:=600Global MaxIt:=32 'Julia's calculation precisionGlobal Threshold:=2 'Julia's escape ThresholdGlobal zoom:=2.7 'inverted zoom factorGlobal Palette:UInt[]Class Julia Extends WindowField pixmap:=New Pixmap( w_width,w_height )Field image:=New Image( w_width,w_height,TextureFlags.Dynamic )Method New( title:String,width:Int,height:Int,flags:WindowFlags=WindowFlags.Resizable )Super.New( title,width,height,WindowFlags.Center )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()'' local vars declaration'Local Cr:Float, Ci:Float, Zr:Float, Zi:Float ' the complex number parts (should probably use struct...)Local ta:Int,tb:Int,tj:Int 'the timer varsLocal x:Int,y:Int 'coord iterators'' get the mouse coord and transform it to the complex constant used in Julia set'Cr=1+(App.MouseLocation.x-w_width)/(w_width/2.0)Ci=1+(App.MouseLocation.y-w_height)/(w_height/2.0)'' Calculates Julia in indexed colors (iterations up to MaxIt-1 due to array starting at 0)' and copy it to the imagearray array'ta=Millisecs()For y=0 Until w_heightLocal p:=Cast<UInt Ptr>( pixmap.PixelPtr( 0,y ) )Zi=(y-(w_height/2.0))*(zoom/w_height)For x=0 Until w_widthZr=(x-(w_width/2.0))*(zoom/w_width)Local t:=NbIter( Zr,Zi,MaxIt,Threshold,Cr,Ci )p[x]=Palette[t]NextNexttb=Millisecs()tj=tb-ta 'Records the time it took to calculate Julia and copy it to the arrayimage.Texture.PastePixmap( pixmap,0,0 )canvas.DrawImage( image,0,0 )' Prints timers and FPS'canvas.Color=Color.Blackcanvas.DrawText("Move mouse arroud to see various Julia sets",0,0)canvas.DrawText("Julia to array time: "+tj,0,15)canvas.DrawText("array to canvas time: "+tb,0,30)canvas.DrawText("FPS:"+App.FPS,0,45)EndEnd'' squared complex+const series (Julia)'Function NbIter:Int(Zr:Float,Zi:Float,max_iter:Int,exit_radius:Float,Cr:Float,Ci:Float)Local i:=0Local Zr2:Float, Zi2:Float, er2:Floater2=exit_radius*exit_radiusZr2=Zr*ZrZi2=Zi*ZiWhile i<max_iter-1 And Zr2+Zi2<er2Zi=2*Zr*Zi + CiZr=Zr2-Zi2 +CrZr2=Zr*ZrZi2=Zi*Zii+=1WendReturn iEndFunction ColorToBGRA:UInt( color:Color )Return UInt(color.a*255) Shl 24 | UInt(color.b*255) Shl 16 | UInt(color.g*255) Shl 8 | UInt(color.r*255)End'' Create the indexed color Palette'Function CreateGlobalPalette:Void()Palette=New UInt[MaxIt] 'Palette is Global, declared at topFor Local i:=0 Until MaxIt-1Palette[i]=ColorToBGRA( New Color(Abs(Sin(2.0*Pi*i/MaxIt)),Abs(Sin(1.2*Pi*i/MaxIt)),0.6-(i/(MaxIt*1.0))*0.3) )NextPalette[MaxIt-1]=ColorToBGRA( Color.Black )EndFunction Main()CreateGlobalPalette()New AppInstanceNew Julia( "Julia",w_width,w_height )App.Run()End> What I would really like to see is some kind of direct access to the audio buffer in mojo.
There is actually limited/experimental support for this in now – see my blog update, but note there are issues with doing realtime stuff like audio in a single threaded app.
There’s a little demo in the vsynth bananas folder called vsynth_mojo.monkey2. It basically does the same thing as vsynth – ie: realtime audio generation – only through a single openal audio channel, so you can mix it with stuff playing through other audio channels easily. I have no idea how well it runs on other machines though!
Mojo uses the GLES20 API exclusively.
However, Windows builds use ‘angle’ to convert GLES20 to D3D9/11 calls.
You could theoretically switch to using native GLES20 on Windows, but I don’t think you’d gain much, if any, performance, and you’d lose a lot of compatiblity.
Thanks, will fix, but please post bugs in the ‘issues’ thing at github in future, or I may miss them.
This turned out ot be a ‘spaces in filename’ build issue, but was kind of fun to find.
The main problem was that mx2cc wasn’t recognizing a file had changed so wasn’t rebuilding it.
But each time I tried to add something to the monkey module to do some testing, this was enough to trigger a rebuild! So I ended up having to add a new foobar field after each modules update – I ended up with about 5 foobars before it clicked what was happening…
For a while it seemed like the ultimate heisenbug – each time I tried to measure it, it very predictably disappeared!
Nope sorry.
I no longer even have a CD of Windows 7, although I guess I’m gonna need one sooner or later if there are problems with mx2 apps not running on it.
And to be honest, I am not really keen on supporting Windows 7 as a dev platform. It’s officially reached ‘end of mainstream support’ and more and more stuff is just gonna break on it over time.
There’s also the time factor for me – I’m already supporting 3 (soon to be 5) dev platforms and I just don’t like the idea of having to support another.
Yeah, it sucks if you don’t like Windows 10, but that’s just the way it is if you’re a developer. I’m kind of lucky – I hate all versions of Windows equally so changing up has never been a big deal.
Of course, if anyone can come up with fixes for Windows 7 that don’t break Windows 8/10 I’m happy to implement them – I could sure do with the help!
Monkey2 currently only implements GLES2.0, which means you need to create shaders and so on before you can draw anything.
Also, you can’t yet render directly to OpenGL in mojo – coming soon though.
Looking forward to next screenshot!
As for lines (ie. DrawLine) they don’t appear affected by this change for glowy line style drawing.
I think they are – the intersections between the bright and dark blue lines appear to be slighty brighter.
But that may be an optical illusion! Another thing to remember is that blending results are clamped to [0,1] so adding Color( 0,0,1 ) to Color( 0,0,.5 ) will still give you Color( 0,0,1 ).
I just hacked in a LineWidth too, now up at github, although it’s not very clever. It basically just draws a rotated rect if LineWidth>1 and, unless blendmode is Opaque, attempts to ‘smooth’ it. The ends of the line are ‘hard clipped’ so it looks more like a cylinder if LineWidth is too big, but it’s not bad for a quick hack IMO.
I really want to wait until shaders are going before getting too carried away with this stuff, but this should give people something to play with until that happens.
What error do you get?
How do I reproduce the error?
Also, there’s a version of Deque coming to std soon..
July 13, 2016 at 9:45 pm in reply to: Is there a limit to number of source files / command line length? #2104Ok, possible fix is now up at github.
Copy from console is indeed a little broken. Try ‘copy’ from the edit menu instead of ‘ctrl-c’, works here.
July 13, 2016 at 8:53 pm in reply to: Is there a limit to number of source files / command line length? #2102Can you post the error?
I’m guessing it’s the 8K command line character limit, will fix ASAP.
I should perhaps clarify a bit…
What I’d really like to add instead of #define is ‘StaticIf’.
This would be a bit like a normal If, except it can appear *anywhere* in a program, not just in a block of statements.
StaticIf expressions must be constant, but they can also include type comparisons which makes StaticIf also useful for kludging up generic code when necessary.
The big issue with #define is that (the way it’s implemented in bmx and mx1 anyway) it happens during parsing, so is sensitive to ‘order of imports’ issues, eg:
Monkey123456#If TEST#Print "YES"#EndIf#TEST=1…will not print “YES” on bmx (I think) or mx1.
It’s obvious in this case, but when you have a #define in one file and a dependant #if in another (and potential cyclic file dependancies) it can all get a bit hairy.
‘StaticIf’ solves this because it happens on the semant phase, after parsing, so this:
Monkey12345StaticIf Test#Print "YES" 'hypothetical #Print used here..EndIfConst Test:=True…will actually print “YES”.
Another thing I like about StaticIf is that code that is not generated because the StaticIf fails is still actually parsed, whereas #If just skips the code altogether, even if it’s full of garbage.
Once StaticIf is in, the current __TARGET__, __HOSTOS__ etc symbols could also be implemented as simple Consts inside, say, a monkey.build namespace. This way, you’d be able to use them for both conditional compilation and directly in code.
Not sure when this’ll happen though – and if anyone can come up with a better name than StaticIf…
You can’t yet…
Try BlendMode.Additive.
-
AuthorPosts