Based on your post I tried various versions. All failed, so I'm still not 
getting it. Here's the full scene:
    
    
    # nim c -d:ThreadPoolSize=8 -d:FixedChanSize=16 renderfunc.nim
    
    import std/[math, monotimes]
    import pixie
    import malebolgia
    
    const
      Width = 800
      Height = 400
    
    
    proc lerp(t, minin, maxin, minout, maxout: float):float {.inline.}=
      result = ((t - minin) / (maxin - minin)) * (maxout - minout) + minout
    
    
    proc shuheiKawachi (x: float, y: float, funcVA: varargs[float]): Color = 
#or ColorRGBX
      let val = (((cos(x) * cos(y) + cos(( sqrt(funcVA[0]) * x - y) / 
funcVA[1]) *
      cos((x + sqrt(funcVA[0]) * y) / funcVA[1]) + cos(( sqrt(funcVA[0]) * x + 
y) / funcVA[1]) *
      cos((x - sqrt(funcVA[0]) * y) / funcVA[1])) / 3 ) + 1) #division by 3 to 
bring it in the [-1,1] range
      return color(val, val, val) #color(val,val,val)..asRgbx()
    
    
    proc renderXYFunc2(
      image: var Image,
      function: proc,
      funcVA: varargs[float],
      viewPort: (Vec2, Vec2),
      scale: float
    ): void=
      var m = createMaster()
      
      proc assign(i:int, j:int, x:float, y:float, function:proc, 
funcVA:varargs[float]):Image =
      #proc assign(i:int, j:int, x:float, y:float):Image =
        image[i,j] = function(x, y, funcVA)
      
      m.awaitAll:
        for j in 0..<image.height:
          let y = lerp(j.float, 0.0, image.height.float, viewPort[0].y, 
viewPort[1].y) * scale
          for i in 0..<image.width:
            let x = lerp(i.float, 0.0, image.width.float, viewPort[0].x, 
viewPort[1].x) * scale
            #m.spawn function(x, y, funcVA) -> image[i,j]
            m.spawn assign(i, j, x, y, function, funcVA) #Error: 'toTask' takes 
a GC safe call expression
            #m.spawn assign(i, j, x, y) #Error: closure call is not allowed
            
            #change the output of the function used to ColorRGBX type
            #m.spawn function(x, y, funcVA) -> image.unsafe[i,j] 
#renderfunc.nim(50, 17) Error: illegal capture 'function' because 'function' 
has the calling convention: <nimcall>
    
    var image = newImage(Width, Height)
    
    let t0 = getMonoTime()
    renderXYFunc2(
      image,
      shuheiKawachi,
      [TAU, 1.5],
      (vec2(0.0, 0.0), vec2(TAU, PI)),
      6.0
    )
    let t1 = getMonoTime() - t0
    echo t1
    
    writeFile(image, "kawachi.png")
    
    
    Run

Reply via email to