I'm tryng to draw an image pixel by pixel, but I don't know how to do it :whistle:
This is my ugly code
// --------------------------------- //
// Project: pic_pixelTopixel
// Start: Sunday, July 20, 2008
// IDE Version: 5.322
SETSCREEN 640, 480, 0 // MODO GRAFICO
LIMITFPS 60
SCREEN_PIXEL("d:/test.png", 640, 480)
FUNCTION SCREEN_PIXEL:image$, zwidth, zheight
LOCAL gx, gy, pixel, INCR, c, graphseg = 0;
LOADSPRITE image$, 1
CREATESCREEN 0, 13, zwidth, zheight
USESCREEN 0
DRAWSPRITE 1,0,0
FOR gy = 0 TO zheight - 1
FOR gx = 0 TO zwidth - 1
USESCREEN 0
pixel= GETPIXEL(gx, gy)
USESCREEN -1
USEASBMP
SETPIXEL gx, gy, pixel
SHOWSCREEN
NEXT
NEXT
ENDFUNCTION
Thank you in advance
There's no such thing as a stupid question (but there are stupid answers, usually given by me :D)
The easiest way to do this is using the POLYVECTOR command, where you can display part of an image - saves all the messy screen bits.
Hope that helps ....
=D Thank you PeeJay, I'll see POLYVECTOR command.
I need to convert pixels to black&white before to put in the screen
I have now this code, but while it is putting pixels, the screen is degradated
// this code will put an image pixel by pixel
// but the image is being degradated while pixels is putting in screen
SETSCREEN 640, 480, 0 // MODO GRAFICO
LIMITFPS 60
ZX_SCREEN("d:/test.png", 640, 480, 0,0, 2)
MOUSEWAIT
FUNCTION ZX_SCREEN:grafico$, zwidth, zheight, x, y, velocidad
LOCAL gx, gy, pixel
BLACKSCREEN
GRABSPRITE 2, 0,0, zwidth, zheight // create a black sprite
LOADSPRITE grafico$, 1
FOR gy = 0 TO zheight - 1
FOR gx = 0 TO zwidth - 1
DRAWSPRITE 1, 0,0 // draw original image
pixel = GETPIXEL(gx, gy)
IF pixel > RGB(255,255,255)/2
pixel = RGB(255,255,255) // white
ELSE
pixel = RGB(0,0,0) // black
ENDIF
DRAWSPRITE 2, 0,0
SETPIXEL gx, gy, pixel
GRABSPRITE 2, 0,0, zwidth, zheight // update black sprite
SHOWSCREEN
NEXT
NEXT
ENDFUNCTION
Sorry for my bad english :D
IF pixel > RGB(255,255,255)/2
You can't simply compare it this way.
Check, if the "green" component is bigger than 128:
IF bAND(pixel, 0x00ff00) > 0x008000 ...
If you need it deadly accurate, you will need to compare red, green, and blue components of course, which you could do like this:-
pixel = GETPIXEL (x,y)
red = bAND(pixel,255)
green = bAND(pixel/256,255)
blue = bAND(pixel/65536,255)
mono = INTEGER(((red+green+blue)/3)/128)
Where mono would then by 0 for a black pixel, or 1 for a white pixel.
However, be aware that pixel by pixel operations are slow, since it is not really what the language was designed for ;)
Nice! thank you to both. I'll post my code this night :D
To make it gray like in TV, use 30% of the red value, 59% of the green value, and 11% of the blue value mixed up. Our eye is more sensual to green and less to blue.
gray = (red*.3+green*.59+blue*.11)
mono = INTEGER(gray/128)
IN 5-6 hours you can see what I'm tryng to do ;) (retrogaming :D)
I think I already know what you're trying to do, which is recreate a speccy loading screen from the finished image. How are my guessing skills? ;)
:good: I did it in FENIX/DIV, and now I have it in GLBasic =)
And I discover my real(nick) name.
I already remaked Mad Mix Game (or Pepsi Challenge), Solomon's Key and Go Bear Go and now I'm working in a new project to learn GLBasic
Ooh! Solomon's Key. I love that game. Download link please :)
Quote from: Ian Price on 2008-Jul-22
Ooh! Solomon's Key. I love that game. Download link please :)
Yeees, It's my favourite 'bar game' (with Tiger Heli)
http://zikitrake.com/ (http://zikitrake.com/) (in FREEWARE-REMAKES zone)
And this is my solution ;/
Please modify it to make a better version :nw:
http://zikitrake.com/tmp/ZX_LOAD.RAR (http://zikitrake.com/tmp/ZX_LOAD.RAR)
Regards
GETPIXEL and USEASBMP in a loop.. well, it looks really really "real", so I hope you're not hoping for a speedup?
Very nice effect.
;/ this is faster than the speed generation of a ZX loading screen :D (I need the current speed because I don't want bored players :bed:)
See a sample: http://youtube.com/watch?v=FdfJhTle8fg (http://youtube.com/watch?v=FdfJhTle8fg)