Perlin Noise

rob1221

  • *
  • Posts: 9473
I created a perlin noise extension that you can use to modify images with noise, and then you can convert the noise into a list that can be used for procedural generation.  Try it out and if you have suggestions for new blocks to add, post them here.

"Perlin Noise Test.stencyl" is a sample game showing how perlin noise can be used for procedural map generation with tiles.  Make sure the extension is installed before opening the sample game.

The extension requires Stencyl 3.3 or higher.  The sample game has been updated to the 4.0 format and might not work properly in earlier versions.

« Last Edit: January 30, 2019, 04:24:20 pm by rob1221 »

zawrot13

  • Posts: 783
Thanks. I've just enabled the extension and try to play with. Is it possible to use these blocks to grab the screen/scene pixels creating new bimap from everything what is onscreen like in screen captures soft? I'm looking for such solutions and Perlin Noise can do a lot with the bitmap but how to grab the ingame scene as one bitmap?

rob1221

  • *
  • Posts: 9473
I'm not sure how to do that, but what is the purpose of getting a screenshot?

zawrot13

  • Posts: 783
Well, Because the zoom out have the problem with tiles, I'm trying to find the solution to show the scene map in game.

rob1221

  • *
  • Posts: 9473
That's unrelated to this extension which wasn't intended to be a full Bitmap/BitmapData extension.

zawrot13

  • Posts: 783
Ok, thanks, I will start different topic.

rob1221

  • *
  • Posts: 9473
I thought this was updated for OpenFL but I guess I only checked Flash.  Actually the extension is fine, but I had to redo a change in OpenFL that I made to the perlin noise function in NME.  For the public version of 3.1 (nightly build has this fix), replace plaf/haxe/lib/openfl-native/1,1,4/flash/display/BitmapData.hx with the attached file.
This change should no longer be needed with the newest extension update.

Also, with the changes made to 3.1, you can put an image attribute into the perlin noise block, so you don't need to use the other blocks.

« Last Edit: June 10, 2014, 01:58:31 pm by rob1221 »

Spardaboy

  • Posts: 7
Hi Rob1221,

I have to admit I am an amateur when it comes to programming and even less experienced when it comes to Stencyl.

I have your extension installed and I can see the blocks under Extensions tab but I have no idea how to generate the bitmap data and then read it out either as an array or even an image. I have researched for hours but still no closer to figuring this out.

Are you able to shed some light on this for me and maybe point me in the right direction?

Any help would be greatly appreciated.

rob1221

  • *
  • Posts: 9473
You can use the image API to make an image that can fit inside the perlin noise block.

Spardaboy

  • Posts: 7
Ok sweet, thanks for the quick response.

I read the information about images but I didn't have any luck yet. I will have a play around with it a bit more. I'm sure I will get it eventually.

It makes sense and seems simple enough but like I said I am very new to this.

Thanks again :)

Spardaboy

  • Posts: 7
Hi again Rob1221,

Well, it looks like it wasn't as simple as I hoped.

I tried implementing the Image API method as you previously suggested but no matter what I try I keep getting an error message when testing the scene. I even tried running the scene with just the Perlin Noise block but same deal. I have attached a screenshot of my block setup.

I have a brand new project with a single scene and one scene behaviour. I attach the behaviour to the scene and test but I get the following error message.

An ActionScript error occurred:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at PerlinNoise$/runPerlinNoise()[/Users/spardaboy/stencylworks/engine-extensions/perlin-noise/PerlinNoise.hx:29]
   at scripts::Design_1_1_PerlinBehaviour/init()[Source/scripts/Design_1_1_PerlinBehaviour.hx:87]
   at com.stencyl.behavior::Behavior/initScript()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/com/stencyl/behavior/Behavior.hx:93]
   at com.stencyl.behavior::BehaviorManager/initScripts()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/com/stencyl/behavior/BehaviorManager.hx:97]
   at com.stencyl::Engine$/initBehaviors()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:1092]
   at com.stencyl::Engine/loadScene()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:899]
   at com.stencyl::Engine/begin()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:756]
   at com.stencyl::Engine()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/com/stencyl/Engine.hx:500]
   at Universal/init()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/Universal.hx:57]
   at Universal/onAdded()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/Universal.hx:35]
   at flash.display::DisplayObjectContainer/addChild()
   at Universal$/main()[/Applications/Stencyl-full/plaf/haxe/lib/stencyl/1,00/Universal.hx:684]
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at Function/<anonymous>()
   at Reflect$/callMethod()[/Applications/Stencyl-full/plaf/haxe/std/flash/_std/Reflect.hx:56]
   at ApplicationMain$/begin()[Export/flash/haxe/ApplicationMain.hx:56]
   at ApplicationMain$/preloader_onComplete()[Export/flash/haxe/ApplicationMain.hx:83]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at scripts::StencylPreloader/onLoaded()[Source/scripts/StencylPreloader.hx:316]
   at ApplicationMain$/onEnter()[Export/flash/haxe/ApplicationMain.hx:75]

I have tried completely reinstalling Stencyl with the latest build along with the Perlin Noise extension. I have even updated flash to no avail.

Any thoughts? I feel it is something wrong with my block layout.

Cheers.

rob1221

  • *
  • Posts: 9473
You use an image for that block, not an image instance.

Spardaboy

  • Posts: 7
Sorry to be a pain but are you able to elaborate a little more for me? Maybe provide an example I could test.

I have changed it to an image but I still get that error when I try to draw it to the screen.

Please forgive my ignorance. I am starting to get really frustrated at this because I know it should be really simple but I'm just not getting it :(


Spardaboy

  • Posts: 7
Oooh I see now where I went wrong!
I was using the "when created" event as a behaviour of the scene not as an actual scene event. Duh!
Thank you so much for your help and patience.
I owe you a drink for that one :)