Logo by stereoman - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. March 28, 2024, 10:47:30 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Generating all the rules via javascript  (Read 3659 times)
0 Members and 1 Guest are viewing this topic.
barcud
Navigator
*****
Posts: 69


« on: February 07, 2016, 05:16:56 PM »

A new era in Structure Synth (at least for me) - generating all the rules via javascript!!!!
I knew you could use javascript but I never went further than to use it for some animations - bad mistake!!

Turns out you can write complete rule sets using javascript and you have access to math functions and variables this way.

I have written a short tutorial http://kronpano.deviantart.com/art/Sinwave-Sculpture-with-JS-StructureSynth-tutorial-589304395 over at DA which should be accessible by the public



* sinwave_sculpture1small.jpg (94.09 KB, 800x656 - viewed 584 times.)
Logged
ciric50
Forums Freshman
**
Posts: 19


« Reply #1 on: April 06, 2016, 04:44:55 AM »

Interesting! I like structure-synth as it is, but being able to use javascript opens up a whole new set of possibilities.

I wonder if there might be a way to run batches of generated Eisenscript programs, with some type of intelligence attached that would help weed out uninteresting results? It would be cool to have a program that would generate hundreds or even thousands of scripts and run them. You wouldn't want to run and evaluate them by hand, though. Some type of automated process would be required to figure out which ones were "interesting". I've done this with chaotic orbits in my own studies, but I think it would be a lot more difficult with structure-synth constructions. I'm not sure how you would determine what is an "interesting" result programmatically.
Logged
barcud
Navigator
*****
Posts: 69


« Reply #2 on: April 11, 2016, 12:19:30 PM »

Some programs like JWildfire or now even Mandelbulb3D have something called a MutaGen - a mutation generator which applies more or less random mutations to parameters of formulas but in both programs the results are presented as is and it is up to the user to decide which mutation might be useful.

EDIT

I was just told that it is not just random mutations - there are internal processes which try to make a decision on what works in both JWF and MB3D.
Using some sort of "quality" measure like edge detection, contrast, colour distribution ..... those MutaGens try to weed out the uninteresting ones and present only those passing certain criteria.

END EDIT


I would have no idea how you could programmatically make that decision.

EDIT

OK, now I have an idea but first of all I would still not be able to implement any of them and secondly I think Structure Synth is different from "normal" fractals and flames.
I actually like to be the "random" generator - to come up with some idea and then find out that it doesn't work  sad

END EDIT

I am using the javascript side of things mainly to create curves (using sin/cos) or structures which I want to in/decrease in a loop fashion (like a triangular tiled roof - start at the top with one, next row two.....).
Still struggling though with using it properly in a mixed way - generating several rules in javascript and calling them in an eisen script - but hey, perhaps at some point  cheesy
« Last Edit: April 15, 2016, 10:22:49 AM by barcud, Reason: Got new info » Logged
barcud
Navigator
*****
Posts: 69


« Reply #3 on: April 11, 2016, 12:36:10 PM »

Here is another sin wave based structure build using
Code:
#javascript

Builder.load("sinwaveSculpture4c4_es.es");
max =880;

Builder.append("rule sinwave{")

for (i = 0; i <=  max; i+=1) {
trig_val=i*3.1415*2/max
sin_x=48*i/max
sin_y=8*Math.sin(trig_val)-Math.sin(trig_val)
rot_z=88*Math.cos(trig_val)
sin_updown=Math.sin(trig_val*2)
wsx="{ y "+ sin_y + " x " +sin_x +" rz "+ rot_z +" ry "+ (70-sin_updown*260) +" rz "+ 80*sin_updown +" y -3 s 0.2 "+ (4.2+sin_updown*4) +" "+ (1.5+sin_updown*1.3)+" color orange b 0.5 sat 0.8 h "+ (160+sin_updown*79)+"} box"
Builder.append(wsx)
}

Builder.append("}")
Builder.build();

and the follwing saved as "sinwaveSculpture4c4_es.es"

Code:
mysin

rule mysin md 8{
{rx 0} sinwave
{rx 45} mysin
}

As you can see the real Structure Synth part is just the rotation.
I am trying to get to the point where I create several ambigous rules in java script and then use them properly in Structure synth - by that I mean more in a l-system style.


* sinwaveSculpture4c4small.jpg (184.44 KB, 1400x746 - viewed 518 times.)
Logged
SCORPION
Conqueror
*******
Posts: 104


« Reply #4 on: April 12, 2016, 04:24:59 PM »

Very interesting!
But the objects created in this way can not be exported.
This is very bad.


* 000.JPG (67.43 KB, 707x709 - viewed 506 times.)
Logged
barcud
Navigator
*****
Posts: 69


« Reply #5 on: April 12, 2016, 08:23:10 PM »

Well they can using for example a site like jsfiddle or a local javascript environment.
If you look for example at this https://jsfiddle.net/of40gmf6/4/ and run it you will get all the "proper" Structure Synth commands in the output window which can then be taken and pasted into structure synth.

The fiddle has the following javascript which just creates a wavy tower:

Code:
max = 80;
height = 0.2


function out() {
  var args = Array.prototype.slice.call(arguments, 0);
  document.getElementById('output').innerHTML += args.join(" ") + "\n";
}


out("rule sinTower5{")
for (y = 1; y < max; y += 1) {
  trig_val = y * 3.1415 / max / 0.2
  trig_val2 = y * 3.1415 / max * 2
  cos_size = Math.cos(trig_val) * 0.5 + 1.3
  sin_size = Math.sin(trig_val2) / 2.5
  mult = 2
  asd = "{z " + (y * height - height * 3) + " y " + sin_size + " x " + sin_size + " rz " + -y * 7 * sin_size + " s  " + mult * cos_size + " " + mult * cos_size + "  " + height + "  }box"
  out(asd)

}
out("}")

All the builder.append have been replaced by the out function which needs to be defined once.

I know - not the most straight forward way but it works.
The image is the object created in Structure Synth, exported and opened in 3DBuilder.


* 3DBuilder.jpg (125.58 KB, 1202x933 - viewed 529 times.)
Logged
SCORPION
Conqueror
*******
Posts: 104


« Reply #6 on: April 13, 2016, 12:00:14 AM »

I can not understand now how it is run in the Structure Synth.
Logged
barcud
Navigator
*****
Posts: 69


« Reply #7 on: April 13, 2016, 03:41:53 PM »

It is a sort of 3 stage process if you want to create an object from a javascript.

  • 1: Develop the javascript and eisen script in Structure Synth as you did before. Then you notice the object export throws the error.
  • 2: To work around the error I used the jsfiddle website to 'execute' the javascript. As stated in the previous post I take the javascript part - substitute the Builder.append statements and run it in jsfiddle. This will produce pure Structure Synth output
  • 3: Copy this output back into Structure Synth and you can create your object


If you open the jsfiddle link I posted before or this one https://jsfiddle.net/of40gmf6/4/ you can see (should be able to - I think sharing works OK) on the right hand side the output which is pure Sturcture synth rules. These can be copied and pasted into a Structure Synth tab and when you run it you can also export the object.

This method will only work if you create the complete rule in javascript - not if you want to modify existing rules.

Any clearer?
I am not saying this is how it has to be done but I found it works.
It is probably a bug in Structure Synth that the object export does not invoke the javascript interpreter (?? or something like that) because it wan't really intended for generating complete rules but to make animations possible.

Logged
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Javascript Mandelbox Explorer Announcements & News joeytwiddle 0 4207 Last post June 29, 2011, 11:46:23 PM
by joeytwiddle
Generating RGB values from mu Programming blastoff 5 4838 Last post August 17, 2012, 03:42:42 PM
by Adam Majewski
Mandelbrot / Julia explorer, JavaScript / Canvas Programming asimes 4 3000 Last post August 18, 2013, 10:26:21 PM
by asimes
Buddhabrot renderer, JavaScript / Canvas Programming asimes 3 3452 Last post January 29, 2014, 03:47:15 PM
by asimes
New JavaScript fractal generator Introduction to Fractals and Related Links a_sewer_rat 1 3737 Last post December 06, 2014, 11:16:01 PM
by a_sewer_rat

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.381 seconds with 25 queries. (Pretty URLs adds 0.014s, 2q)