Skip to content

How to use drawImage? #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
noughtmare opened this issue Nov 5, 2019 · 6 comments
Closed

How to use drawImage? #13

noughtmare opened this issue Nov 5, 2019 · 6 comments
Assignees
Labels
bug Something isn't working documentation Related to documentation enhancement New feature or request

Comments

@noughtmare
Copy link

noughtmare commented Nov 5, 2019

Your documentation contains an example:

>>> drawImage window ('constant' \@'Int' 1) ('Cell' 10 10 "test" 'ColorMapSpectrum')

I adapted it to:

main = do
  w <- createWindow 512 512 "Test"
  drawImage w (constant @Int [512,512] 1) (Cell 10 10 "test" ColorMapSpectrum)

That gives the error:

AFException {afExceptionType = TypeError, afExceptionCode = 204, afExceptionMsg = "Function does not support this data type"}
@dmjio
Copy link
Member

dmjio commented Nov 5, 2019

@noughtmare I'd try using the loadImage function, if that still gives you problems I can look into it tonight. The example I have might be outdated.

@noughtmare
Copy link
Author

noughtmare commented Nov 5, 2019

@dmjio loadImage loads an image from disk, I want to generate an image programmatically (and then show it in a window).

@dmjio
Copy link
Member

dmjio commented Nov 5, 2019

@noughtmare I think the type needs to be CBool (b8). Can confirm soon.

@noughtmare
Copy link
Author

@dmjio If I use CBool then I get the error:

free(): invalid size
Aborted

@dmjio dmjio added bug Something isn't working documentation Related to documentation enhancement New feature or request labels Nov 10, 2019
@dmjio dmjio self-assigned this Nov 10, 2019
@dmjio
Copy link
Member

dmjio commented Nov 11, 2019

@noughtmare there's been some fixes (related to double free'ing of pointers) that are now in HEAD, am working on the Graphics module now with success. drawSurface in particular.

As I inspect more with what the C++ is doing before it sends it to the C, we'll have better working visualization code, and examples !

main :: IO ()                                                                                                                                                                                                   
main = do                                                                                                                                                                                                       
  window <- createWindow 800 600 "hey"                                                                                                                                                                          
  let x = iota [60,1] [1,60] / 29                                                                                                                                                                               
      y = iota [1,60] [60,1] / 29                                                                                                                                                                               
  go window (0 :: Array Float) x y                                                                                                                                                                              
    where                                                                                                                                                                                                       
      go window t x y = do                                                                                                                                                                                      
        let z = 10*x*(-abs(y)) * cos(x*x*(y+t))+sin(y*(x+t))-1.5                                                                                                                                                
        drawSurface window x y z (Cell (-1) (-1) "there" ColorMapDefault)                                                                                                                                       
        closed <- isWindowClosed window                                                                                                                                                                         
        unless closed $ go window (t + 0.07) x y  

image

@dmjio
Copy link
Member

dmjio commented Nov 11, 2019

@noughtmare, for drawImage, try something like this:

main :: IO ()                                                                                                                                                                                                   
main = render =<< createWindow 800 600 "hey"                                                                                                                                                                          
    where                                                                                                                                                                                                       
      render window = do                                                                                                                                                                                            
        let x = iota [1,60] [60,1] / (30 :: Array Float)                                                                                                                                                        
            cell = Cell (-1) (-1) "" ColorMapDefault                                                                                                                                                        
        drawImage window x cell                                                                                                                                                                                 
        closed <- isWindowClosed window                                                                                                                                                                         
        unless closed (render window)

image

I'll update the documentation to reflect this.

@dmjio dmjio closed this as completed Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Related to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants