Author Topic: MandelBlue Abstracta  (Read 2415 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
MandelBlue Abstracta
« on: June 05, 2013, 09:42:43 AM »
Deleted
« Last Edit: April 25, 2015, 04:11:28 AM by Peter »

JRS

  • Guest
Re: MandelBlue Abstracta
« Reply #1 on: June 05, 2013, 10:08:04 AM »
Just a slight mod to see the big picture.

BTW: You defined int zoomLevel and then use it as a single. (fixed and scaled image to 1.25)



Code: [Select]
#include "sw.inc"
window 600,500,1

int maxiteration=16
single xStart=-2.5, yStart=-2, zoomLevel = 1.25

Function grayRamp(int value,range) as int
  if range=0 then range=1
  int distance = (value*255) / range
  Return RGB(distance,distance,distance)
End Function  

Function colorRamp(int part,whole) as int
  int pixelDistanceAlongPath = (part * 1792) / whole
  int red, green, blue
  if pixelDistanceAlongPath <256
     red=0
     green=0
     blue=pixelDistanceAlongPath
  else if pixelDistanceAlongPath <512
     red =0
     green=pixelDistanceAlongPath-256
     blue=255
  else if pixelDistanceAlongPath <768
     red =0
     green=255
     blue =255-(pixelDistanceAlongPath-512)
  else if pixelDistanceAlongPath <1024
     red= pixelDistanceAlongPath-768
     green =255
     blue  =0
  else if pixelDistanceAlongPath <1280
     red  =255
     green=255-(pixelDistanceAlongPath-1024)
     blue =0
  else if pixelDistanceAlongPath <1536
     red =255
     green=0
     blue=pixelDistanceAlongPath -1280
  else
     red  =255
     green=pixelDistanceAlongPath-1536
     blue =255
  end if    
  Return RGB(red, green, blue)
End Function

Sub renderPix(int iX, iY, single X, Y, zoom)
    single xC=(xstart)+(single(iX)+.5)/100/zoom)
    single yC=(ystart)+(single(iY)-.5)/100/zoom)
    single x0=(xstart)+(single(iX)+.5)/100/zoom)
    single y0=(ystart)+(single(iY)-.5)/100/zoom)
    single x2 = xC*xC
    single y2 = yC*yC
    int iteration =0
    while (x2 + y2) < (2*2) && iteration < maxiteration  
yC = 2*xC*yC + y0
xC = x2 - y2 + x0
        x2 = xC*xC
y2 = yC*yC
        iteration +=1
    wend
    if iteration = maxiteration
       SetPixel iX, iY, 0
    else
       SetPixel iX, iY, colorRamp(iteration, maxiteration)
    end if
End Sub    

For i=0 to 600
   For j=0 to 500
     renderPix(i,j,xstart,ystart,zoomLevel)
   Next
 Next

 WaitKey
 CloseWindow

« Last Edit: June 05, 2013, 12:09:41 PM by JRS »

Aurel

  • Guest
Re: MandelBlue Abstracta
« Reply #2 on: July 03, 2013, 02:09:26 PM »
I know that this example is old but I use this one for test double buffering.
This example is part of EB directX examples translated to oxygen.
Code: [Select]
$ filename "MandelBlue.exe"
include "rtl32.inc"
include "awinh.inc"
#lookahead
INT win,c,r
INT w,h
dim i,y,px as INT
dim Z_re2 as FLOAT
dim Z_im2 as FLOAT
dim Z_re as FLOAT
dim Z_im as FLOAT
dim c_re as FLOAT
dim c_im as FLOAT


INT hdc, hdcMem, hbmMem,   oldBmp, oldBrush, oldPen, oldFont, fColor
INT textX,textY,hBrush

INT ImageWidth=640
INT ImageHeight=480

MinRe = -2.0f
MaxRe = 1.0f
MinIm = -1.25f
MaxIm = MinIm+(MaxRe-MinRe)*ImageHeight/ImageWidth
Re_factor = (MaxRe-MinRe)/(ImageWidth-1)
Im_factor = (MaxIm-MinIm)/(ImageHeight-1)
'window
win = SetWindow("Mandel Blue",0,0,ImageWidth,ImageHeight,0,WS_SYSMENU)

InitDrawing()
'---------------------------------------------------------------------
for y = 0 to ImageHeight-1
c_im = MaxIm - y*Im_factor
for px=0 to ImageWidth-1
c_re=MinRe+px*Re_factor
Z_re=c_re
Z_im=c_im
for i = 1 to 50
Z_re2=Z_re*Z_re
Z_im2=Z_im*Z_im
if (Z_re2+Z_im2) > 4
'Pix (win, px, y, 255-(i+5),i*5, i) 'draw to back buffer is faster
                   Setpixel hdcMem, px, y,RGB(i,i*5,155 -(i+5))
exit for
end if
Z_im=2*Z_re*Z_im+c_im
Z_re=Z_re2-Z_im2+c_re
next i

next px
next y



'----------------------------------------------------------------
Wait()

Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback

Select wmsg

CASE WM_CLOSE
DestroyWindow win
CleanUp()
PostQuitMessage 0

CASE WM_SIZE
'GetSize(win,0,0,w,h)

CASE WM_PAINT
BitBlt(hDC, 0, 0, w, h, hdcMem, 0, 0, SRCCOPY)

End Select

Return DEFAULT

End Function

SUB InitDrawing
''get current size of window
GetSize(win,0,0,w,h)
'get window DC
hdc=GetDC(win)
hdcMem = CreateCompatibleDC(0)
hbmMem = CreateCompatibleBitmap(hdc, w, h)
oldBmp = SelectObject( hdcMem, hbmMem )
oldBrush = SelectObject(hdcMem, CreateSolidBrush( RGB(231,223,231)) )
oldPen = SelectObject(hdcMem, CreatePen(PS_SOLID,1,RGB(231,223,231)))
'fill rectangle memDC with brush color
FillRect ( hdcMem,rc, oldBrush)
SetTextColor( hDC,RGB(0,0,0))
SetBkColor( hDC, RGB(231,223,231))
'blit to memDC
BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)
ReleaseDC( win, hdc)
End SUB

SUB CleanUp
DeleteDC(hdcMem)
DeleteObject(SelectObject(hdcMem, oldBrush))
DeleteObject(SelectObject(hdcMem, oldPen))
DeleteObject(SelectObject(hdcMem, oldBmp))
END SUB

Sub Pix(wnd as int,sys x, y, r, g, b)
 hdc=GetDC(wnd)
    sys pcolor = RGB(r,g,b)
    Setpixel hdc, x, y,pcolor
BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)
 ReleaseDC(wnd, hdc)
End Sub

X
« Last Edit: July 03, 2013, 08:45:06 PM by Aurel »

Aurel

  • Guest
Re: MandelBlue Abstracta
« Reply #3 on: July 04, 2013, 05:59:49 AM »
Quote
Hi,

you have not understood the technique of double buffer.
createcompatiblebitmap and bitblit-transfer is no double buffer.

double buffer is page flipping, you have to program the registers of the graphic card with Mnemo-code (in) and (out),  read and write the port addesses.
your shown method is only a copy-transfer from  hdcmem to hdc. it is not faster as you told.

Peter i agree with you that i don't understand double buffering in your way ,
BUT exactly same method is used in Creative Basic (VC++ code) to create persistent image on window
and as you can see all fliping of window DC is under WM_PAINT using ordinary bitBlt() func.
I can agree with you that this method is not the fastest.
BUT in many C/C++ examples is used similar or almost same way- do you can agree with this?

Aurel

  • Guest
Re: MandelBlue Abstracta
« Reply #4 on: July 05, 2013, 09:25:04 AM »
Uffff...
I am not hungry ;D


Hey Peter....
do you know for this site?:
http://www.philvaz.com/games/
I have found some interesting stuff...

Aurel

  • Guest
Re: MandelBlue Abstracta
« Reply #5 on: July 05, 2013, 01:03:49 PM »
Quote
No,  isn't interesting.

Oups ...i forget about your high-standards ::)