Creating an image one pixel at a time

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Creating an image one pixel at a time

Post by JRL » Thu Dec 22, 2011 5:40 am

I wanted to see how long it would take to draw an image one pixel at a time. Turns out that by using this particular code it takes a while. I'll be looking for a faster method. But in the mean time I thought this looked festive and so thought I would share it. As written this requires version 12 or greater because of the dialog but it could be re-written to work in anything above version 9.

Happy holidays.
Dick

Code: Select all

Dialog>TitleBarSizeCalculation
Top=0
Left=0
Button=1,0,0,75,25,0
EndDialog>TitleBarSizeCalculation
Let>WIN_USEHANDLE=1
GetWindowPos>TitleBarSizeCalculation.msButton1.handle,OffSetX,OffSetY
Let>WIN_USEHANDLE=0

Dialog>Dialog1
object Dialog1: TForm
  BorderIcons = [biSystemMenu]
  Caption = 'Draw_Me'
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,Quit

Let>OffSetY={%OffSetX%+%OffSetY%+512}
Let>OffsetX={%OffSetX%+%OffSetX%+512}

ResizeWindow>Draw_Me,OffSetX,OffSetY
MoveWindow>Draw_Me,10,0

Show>dialog1
Let>Ystart=-1
Random>254,col
Let>color={(256*256*%col%)-1}
Let>Xpos=-1
Let>Ypos=YStart
Label>Loop
  Repeat>Xpos
    Add>Xpos,1
    GoSub>DrawLine,Dialog1.handle,1,0,Xpos,{%Ypos%+1},Xpos,{%Ystart%+256}
    Repeat>Ypos
      Add>Ypos,1
      Let>Xnext=Xpos+1
      Let>Ynext=Ypos+1
      Add>color,1
      GoSub>DrawLine,Dialog1.handle,1,Color,Xpos,Ypos,Xnext,Ynext
      SetDialogProperty>Dialog1,,Caption,Color number = %color%   X position = %Xpos%   65536 block = %col%
    Until>Ypos={%Ystart%+256}
    Let>Ypos=YStart
    If>Xpos=255
      Random>254,col
      Let>color={(256*256*%col%)-1}
    EndIf
  Until>Xpos=511
  Add>Ystart,256
  If>Ystart>500
    Let>Ystart=-1
  EndIf
  Let>Ypos=YStart
  Let>Xpos=-1
  Random>254,col
  Let>color={(256*256*%col%)-1}
Goto>Loop

//DrawLine Usage:
//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd

SRT>DrawLine
  LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
  LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
  LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
  Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
  LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
  LibFunc>gdi32,DeleteObject,DOres,Penres
  LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

SRT>Quit
  Exit>0
END>Quit

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts