Logo by mauxuam - 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: Did you know ? you can use LaTex inside Postings on fractalforums.com!
 
*
Welcome, Guest. Please login or register. January 13, 2026, 04:10:23 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: Ultra Fractal Class question  (Read 2205 times)
Description: How to use arrays in a class?
0 Members and 1 Guest are viewing this topic.
hsmyers
Navigator
*****
Posts: 62


Making Mandelbrots from Newtons for years


hugh.myers.75 hughsmyers
WWW
« on: August 05, 2013, 11:08:22 PM »

I'm writing a utility class for a group of formulas with similar needs. One 'need' is to return a selected float parameter from an array of values. At the moment the only way I've been able to do this is to embed the array in the utility function itself. At guess there must be a better way? Ideally I'd like the equivalent of static const or even what I might get from declaring it in the global: section of the formula. Can this be done? Not knowing just how UF instantiates the class I suppose there is a chance that this is not needed, but I don't know. BTW whenever I attempt to move it out of the function I get a parser error about expecting a field---what's up with that?

In sum I'd like:

  • declaration exterior to the utility function
  • instantiated once, not repeatedly

Actually I suppose I'd like a real manual about class coding for UF, but I'll take any help I can get smiley

--hsm
Logged

Without tradition, art is a flock of sheep without a shepherd. Without innovation, it is a corpse. --- W. Churchill
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #1 on: August 05, 2013, 11:22:01 PM »

so, can you be more specific about your array !?
is it different for different needs, is it created "on the fly"?
depending on what you do, various approaches might fit,
i am not perfect at coding uf, bot most of the stuff works somehow,
and the class system in general is just perfect for different formulas
and recombining them

so, if all classes shall have access to the same array, hmm, a memory
consumption approach would be to instanciate a class defining the array
in each of the classes ...

one approach to propagate the data to sub-property-classes might be
to define a base class for distributing an array to work with, and
the accessing functions for the array in the same base class
so that you could choose the array in a "root" formula, and in the
init part of your function you propagate the data to the lower classes
something like this:

in a base function
var theArrayClass
setData(arrayclass)
getDataFromArray(anydimensionalindex)

and then in the root class you let the user define the
array to work with, and in the init class you
call the setData function, which then propagates
the array to sub classes

clearly, any class using arrays should define the sub-classes
in an array like manner as well for accessing possible sub classes
to propagate the array to sad

Logged

---

divide and conquer - iterate and rule - chaos is No random!
hsmyers
Navigator
*****
Posts: 62


Making Mandelbrots from Newtons for years


hugh.myers.75 hughsmyers
WWW
« Reply #2 on: August 06, 2013, 12:25:00 AM »

Here is a shortened version of what works, not what I'd like  angry:

Code:
Class Util {

  static float func GetConstant(int e)
    ;
    ; Mathematical constants
    ;
    float fConstant[5] ;real version is size of 25
    ; Pi
    fConstant[0] = 3.1415926535897932384626433832795028841971693993751
    ; Degree
    fConstant[1] = 0.017453292519943295769236907684886127134428718885417
    ; Base of the natural logarithm
    fConstant[2] = 2.7182818284590452353602874713526624977572470937
    ; Golden ratio
    fConstant[3] = 1.6180339887498948482045868343656381177203091798058
    ; Euler’s Constant
    fConstant[4] = 0.57721566490153286060651209008240243104215933593992

    return fConstant[e]
  endfunc
}

Calling is essentially:
Code:
  float A = Util.GetConstant(@enumparam_A)
  float B = Util.GetConstant(@enumparam_B)
BTW, the implication from the manual is that static functions shouldn't need the 'Util.' portions, yet that errors out. I'm guessing that what was meant was that I don't have instantiate the class with 'new'?

I am not yet ready to do a tiered class system for the formulas---I'm still learning UF5 class code so I'm hoping to ease into things.

--hsm
Logged

Without tradition, art is a flock of sheep without a shepherd. Without innovation, it is a corpse. --- W. Churchill
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #3 on: August 06, 2013, 05:29:08 PM »

First of all note that pi is accessed as #pi (to working resolution even if arbitrary) and so is exp(1) as #e - also using #pi/360.0 or similar in the code will pre-calculate at compile time.

As for writing formulas/colourings etc:

Rule 1: If you don't really need class-based formulas *use the old style* - class-based formulas are more generic and therefore *considerably* slower to execute because of the overheads required.

In the old style to do what you require simply add:

global:
  static float f[5]
  f[0]=1
  f[1]=2
  f[2]=3
  f[3]=4
  f[4]=5 ; or whatever constants are required

Before the init: section and in the code simply return a constant index i as f[ i ]

If you wish to use this in class-based formulas/colourings then the best way is have your own derived main formula base class and/or derived colouring formula base classes for divergent/convergent/both - simply put the code from the global section above in your derived base's init section - but with "static float f[5]" in the base's global variables section (protected/public etc.as you wish).
« Last Edit: August 06, 2013, 05:35:01 PM by David Makin » Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
hsmyers
Navigator
*****
Posts: 62


Making Mandelbrots from Newtons for years


hugh.myers.75 hughsmyers
WWW
« Reply #4 on: August 06, 2013, 11:14:50 PM »

Much thanks! I'll give it a try.

Regarding built ins, yes I'm aware of that. That said this is a port of software written in the 80's and I'm pretty sure the other 23 constants are not conveniently lying around  smiley I've been at this since the Scientific American article and started writing fractal formulas and software at the same time as the stone soup gang, so there is a slim chance I'm not as un-aware as you might think. I'm new to UF5, not fractals. Thanks again!

--hsm
p.s. I could almost swear that I tried global: but perhaps not with static?
p.s.s. Clearly I don't understand as my translation of your suggestion:

Code:
Class Util {

init: ;errors out at this line

global:

    ;
    ; Mathematical constants
    ;
    static float fConstant[25]

doesn't work either  sad
p.s.s.s. Use larger hammer, I'm thick headed!
Logged

Without tradition, art is a flock of sheep without a shepherd. Without innovation, it is a corpse. --- W. Churchill
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Ultra Fractal ... Images Showcase (Rate My Fractal) GFWorld 0 2466 Last post November 21, 2006, 07:16:15 PM
by GFWorld
Ultra Fractal ... Images Showcase (Rate My Fractal) GFWorld 7 4143 Last post December 19, 2006, 07:36:17 PM
by motyka
The Fractal Class Composition Programming Nahee_Enterprises 2 3595 Last post June 01, 2007, 08:41:31 AM
by Nahee_Enterprises
Ultra Fractal ... Images Showcase (Rate My Fractal) GFWorld 0 1677 Last post January 30, 2009, 07:13:36 PM
by GFWorld
Fractal Fish found in Ultra Fractal Images Showcase (Rate My Fractal) thom 0 3191 Last post April 23, 2012, 04:29:41 AM
by thom

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.274 seconds with 24 queries. (Pretty URLs adds 0.011s, 2q)