Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include once "fbgfx.bi"
- randomize timer
- declare sub antialias( byref src as FB.image ptr )
- const as integer scr_width = 640, scr_height = 480
- const as integer alevel = 2
- const as single pi = 3.1415926, pi2 = pi*2
- screenres scr_width,scr_height,32,,FB.GFX_NULL
- dim as fb.image ptr image = imagecreate( scr_width * alevel, scr_height * alevel, 0, 32 )
- screenres scr_width,scr_height,32,,FB.GFX_HIGH_PRIORITY' or FB.GFX_FULLSCREEN
- dim as single wobble
- dim as single iFin = pi2
- dim as single iStep = iFin/16
- do
- dim as double nTime = timer / 10
- line image, (0,0)-(scr_width*alevel, scr_height*alevel), 0, bf
- dim as single mStep = 1
- dim as integer xm = (scr_width/2)*alevel
- dim as integer ym = (scr_height/2)*alevel
- for i as single = 0 to iFin step iStep
- dim as single xs = xm, oxs = xm
- dim as single ys = ym, oys = ym
- for s as single = 0 to 50 step mStep
- oxs += s*sin((i-iStep)+wobble)
- oys += s*cos((i-iStep)+wobble)
- xs += s*sin(i+wobble)
- ys += s*cos(i+wobble)
- wobble = sin((s/10)+(nTime*12))
- dim as integer tCol = 128+127*(sin((i+wobble)*9))
- line image, ( xs, ys ) - ( xs + s*sin(i+wobble), ys + s*cos(i+wobble) ),rgb(tCol, tCol, 255 and wobble)
- line image, -( oxs + s * sin((i-iStep)+wobble), oys + s * cos((i-iStep)+wobble) ),rgb(tCol, tCol, 255 and wobble)
- next
- next
- screenlock
- antialias( image )
- screenunlock
- sleep( 1, 1 )
- loop until multikey(FB.SC_ESCAPE)
- 'basically this function iterates through every other pixel of the larger image
- 'add the color to a variable, take the average of those colors
- 'and plot the pixel in the smaller image using that averaged color
- 'the essence of downsampling, aka 'antialiasing'
- sub antialias( byref src as FB.image ptr )
- dim as uinteger ptr sptr = screenptr
- dim as uinteger ptr iptr = cast( uinteger ptr, src + 1 )
- dim as integer avgcol
- dim as integer hits
- dim as uinteger r,g,b
- dim as uinteger sw = src->width-1, sh = src->height-1
- dim as integer x = any, y = any, x2 = any, y2 = any
- dim as integer y2mul, y1mul
- const as single recip = 1/9
- for y = 1 to sh-1 step 2
- y1mul = ((y shr 1) * SCR_WIDTH)
- for x = 1 to sw-1 step 2
- avgcol = 0
- hits = 0
- r = 0
- g = 0
- b = 0
- for y2 = y - 1 to y + 1
- 'if y2>sh then continue for
- y2mul = y2*src->width
- for x2 = x - 1 to x + 1
- 'if x2>sw then continue for
- avgcol = iptr[ y2mul + x2 ]
- r+= (avgcol shr 16) and 255
- g+= (avgcol shr 8) and 255
- b+= (avgcol) and 255
- next
- next
- sptr[ y1mul + (x shr 1) ] = rgb( r * recip, g * recip, b * recip )
- next
- next
- end sub
Add Comment
Please, Sign In to add comment