colafrysen Posted May 16, 2009 Share Posted May 16, 2009 (edited) Hi i am making a script to create a Sirpenski triangle by using the chaos method. i got as far a creating the triangle (i know its upside down, but it seems the graphic control has its origo in the top left corner) but it is very black&White and thus boring. i would like to make it hippie-neon-color-style by colouring each pixel depending on its X and Y coordinates. so is there a way to colour each pixel individually? expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $HEIGHT = @DesktopHeight $WIDTH = @DesktopWidth $QUALITY= InputBox ("Quality","This equals the tries made to create a point" & @CRLF & "The higher the number the better the picture" & @CRLF & "It is recomended to use a value of at least 10000." & @CRLF & "For best result on large screen use a value of 50000",10000,"",400,200) If @error <> 0 then Exit $GUI = GUICreate("Sierpins Fractal", $WIDTH, $HEIGHT, 0, 0, BitOR($WS_BORDER, $WS_POPUP), $WS_EX_WINDOWEDGE) $GRAPH = GUICtrlCreateGraphic(0, 0, $WIDTH, $HEIGHT);BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) GUICtrlSetBkColor(-1, 0xffffff) GUICtrlSetColor(-1, 0) _GO() While 1 $Gui_action = GUIGetMsg() Switch $Gui_action Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _GO() GUICtrlSetColor(-1, 0) $Y = Random(0,1) $X = Random(0,1) For $k=0 To $QUALITY Step 1 $N = Random(0,1) If $N<=1/3 Then $x *= 0.5 $y *= 0.5 EndIf If 1/3<$N and $N<=2/3 Then $X = 0.5*(0.5+$X) $y = 0.5*(1+$Y) EndIf If 2/3<$N Then $X = 0.5*(1+$X) $Y = 0.5*($Y) EndIf $SET_X = ($X * $WIDTH) $SET_Y = ($Y * $HEIGHT) GUICtrlSetGraphic($GRAPH, $GUI_GR_PIXEL, $SET_X, $SET_Y) ;~ GUICtrlSetColor(-1, 0) ToolTip ($k & @CRLF & ($k/$QUALITY)*100 & "%" ) Next GUICtrlSetColor(-1, 0) EndFunc Edited May 16, 2009 by colafrysen [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size] Link to comment Share on other sites More sharing options...
monoceres Posted May 16, 2009 Share Posted May 16, 2009 Use GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000) .. where 0x000000 is of course the color. However you will get a great speed boost if you do it in GDI+ instead. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 16, 2009 Moderators Share Posted May 16, 2009 colafrysen,Look at the Help file for GUICtrlSetGraphic and the $GUI_GR_COLOR type. It lets you set the drawing colour for the next $GUI_GR_* write operation.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
colafrysen Posted May 16, 2009 Author Share Posted May 16, 2009 (edited) Thanks guys , I'll take a look at those And GDI+ isn't that very difficult? (I haven't looked into it, but the name sounds dangerous) Edited May 16, 2009 by colafrysen [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size] Link to comment Share on other sites More sharing options...
monoceres Posted May 16, 2009 Share Posted May 16, 2009 And GDI+ isn't that very difficult? (I haven't looked into it, but the name sounds dangerous)Nah, the examples in the help file should give you enough info to get you started and there are like ten thousand examples posted all around the forums how to use it. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
colafrysen Posted May 16, 2009 Author Share Posted May 16, 2009 Well i got this far, and i like the result it gives me onscreen... But i am never satesfied. now i want to able to write the output to a file and create a picture that way. so i guess that GDI+ is the only way... or is there a function to write to file without GDI? i couldnt find one... expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> $HEIGHT = @DesktopHeight $WIDTH = @DesktopWidth ;~ $QUALITY = InputBox("Quality", "This equals the tries made to create a point" & @CRLF & "The higher the number the better the picture" & @CRLF & "It is recomended to use a value of at least 10000." & @CRLF & "For best result on large screen use a value of 50000", 10000, "", 400, 200) If @error <> 0 Then Exit Global $Hex_Func, $QUALITY $GUI = GUICreate("Preferences", 250, 232, 193, 125) $Acurracy = GUICtrlCreateInput("10000", 56, 8, 185, 21) $Label1 = GUICtrlCreateLabel("Acurracy", 8, 8, 46, 17) $Style = GUICtrlCreateList("", 8, 104, 233, 110, $WS_BORDER + $WS_VSCROLL) GUICtrlSetData($Style, "Black on White|White on Black|Blue and Green|Blue and Green 2|Spectrum|RGB|Red and Blue|Random Colors", "Blue and Green") $Inp_Width = GUICtrlCreateInput(@DesktopWidth, 56, 32, 121, 21) $Inp_Height = GUICtrlCreateInput(@DesktopHeight, 56, 56, 121, 21) $Label2 = GUICtrlCreateLabel("Width", 8, 32, 32, 17) $HEIGHT = GUICtrlCreateLabel("Height", 8, 56, 35, 17) $Label3 = GUICtrlCreateLabel("Color Style", 8, 80, 54, 17) $GO = GUICtrlCreateButton("Triangiulize", 180, 32, 62, 46, 0) GUISetState(@SW_SHOW) Func _Getdata() Global $QUALITY = GUICtrlRead($Acurracy) Global $HEIGHT = GUICtrlRead($Inp_Height) Global $WIDTH = GUICtrlRead($Inp_Width) Global $Color_scheme = GUICtrlRead($Style) Switch $Color_scheme Case "Black on White" Global $Hex_Func = "_HEX_Black_White" Case "White on Black" Global $Hex_Func = "_HEX_White_Black" Case "Blue and Green" Global $Hex_Func = "_HEX_Blue_Green" Case "Blue and Green 2" Global $Hex_Func = "_HEX_Blue_Green_2" Case "Random Colors" Global $Hex_Func = "_HEX_Random" Case "Spectrum" Global $Hex_Func = "_HEX_Spectrum" Case "RGB" Global $Hex_Func = "_HEX_RGB" Case "Red and Blue" Global $Hex_Func = "_HEX_Red_Blue" EndSwitch EndFunc ;==>_Getdata While 1 $Gui_action = GUIGetMsg() Switch $Gui_action Case $GUI_EVENT_CLOSE Exit Case $GO _Getdata() _go() EndSwitch WEnd Func _GO() $Triangle = GUICreate("Sierpins Fractal", $WIDTH, $HEIGHT, 0, 0, BitOR($WS_BORDER, $WS_POPUP), $WS_EX_WINDOWEDGE, $GUI) $GRAPH = GUICtrlCreateGraphic(0, 0, $WIDTH, $HEIGHT);BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) Switch $Hex_Func Case "_HEX_Black_White" GUICtrlSetBkColor($GRAPH, 0xFFFFFF) GUICtrlSetColor(-1, 0) Case Else GUICtrlSetBkColor($GRAPH, 0x000000) GUICtrlSetColor(-1, 0) EndSwitch GUICtrlSetColor(-1, 0) $Y = Random(0, 1) $X = Random(0, 1) GUISetState(@SW_MINIMIZE, $Triangle) For $k = 0 To $QUALITY Step 1 $N = Random(0, 1) If $N <= 1 / 3 Then $X *= 0.5 $Y *= 0.5 EndIf If 1 / 3 < $N And $N <= 2 / 3 Then $X = 0.5 * (0.5 + $X) $Y = 0.5 * (1 + $Y) EndIf If 2 / 3 < $N Then $X = 0.5 * (1 + $X) $Y = 0.5 * ($Y) EndIf $SET_X = ($X * $WIDTH) $SET_Y = ($Y * $HEIGHT) $PIX = GUICtrlSetGraphic($GRAPH, $GUI_GR_PIXEL, $SET_X, $SET_Y) $HEX = Call($Hex_Func, $X, $Y) ;~ $HEX = Call("_hex_dev" ,$X,$Y) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $HEX) ;~ GUICtrlSetColor(-1, 0) ToolTip($k & @CRLF & ($k / $QUALITY) * 100 & "%") Next GUICtrlSetColor(-1, 0) ToolTip("") GUISetState(@SW_MAXIMIZE, $Triangle) EndFunc ;==>_GO Func _HEX_Black_White($X, $Y) $HEX = 0x000000 Return $HEX EndFunc ;==>_HEX_Black_White Func _HEX_White_Black($X, $Y) $HEX = 0xFFFFFF Return $HEX EndFunc ;==>_HEX_White_Black Func _HEX_Random($X, $Y) $HEX = "0x" & Hex(Random(0, 255), 2) & Hex(Random(0, 255), 2) & Hex(Random(0, 255), 2) Return $HEX EndFunc ;==>_HEX_Random Func _HEX_Red_Blue($X, $Y) $HEX_X = Round($X * 255, 0) $HEX_Y = Round($Y * 255, 0) $HEX_Z = Round(($X * 255 * $Y) / 2, 0) ;~ $HEX = Random (0,255*255*255) $HEX = "0x" & StringLeft(Hex($HEX_X * $HEX_Y, 4), 2) & "00" & StringRight(Hex($HEX_X * $HEX_Y, 4), 2) ;$HEX_Z,6) ;~ MsgBox(0,"",$hex) Return $HEX EndFunc ;==>_HEX_Red_Blue Func _HEX_Blue_Green($X, $Y) $HEX_X = Round($X * 255, 0) $HEX_Y = Round($Y * 255, 0) $HEX_Z = Round(($X * 255 * $Y) / 2, 0) $HEX = "0x00" & Hex($HEX_X * $HEX_Y, 4) Return $HEX EndFunc ;==>_HEX_Blue_Green Func _HEX_Blue_Green_2($X, $Y) $HEX_X = Round($X * 255, 0) $HEX_Y = Round($Y * 255, 0) $HEX_Z = Round(($X * 255 * $Y) / 2, 0) ;~ $HEX = Random (0,255*255*255) $HEX = "0x" & StringLeft(Hex($HEX_X * $HEX_Y, 4), 2) & Hex( $Y*255,2) & StringRight(Hex($HEX_X * $HEX_Y, 4), 2) ;$HEX_Z,6) ;~ MsgBox(0,"",$hex) Return $HEX EndFunc ;==>_HEX_DEV Func _HEX_Spectrum($X, $Y) $HEX_X = Round($X * 255, 0) $HEX_Y = Round($Y * 255, 0) $HEX_Z = Round(($X * 255 * $Y) / 2, 0) ;~ $HEX = Random (0,255*255*255) $HEX = "0x" & Hex($x*255,2) & Hex( $Y*255,2) & StringRight(Hex($HEX_X * $HEX_Y, 4), 2) ;$HEX_Z,6) ;~ MsgBox(0,"",$hex) Return $HEX EndFunc ;==>_HEX_DEV Func _HEX_RGB($X, $Y) $HEX_X = Round($X * 255, 0) $HEX_Y = Round($Y * 255, 0) $HEX_Z = Round(($X * 255 * $Y) / 2, 0) ;~ $HEX = Random (0,255*255*255) $HEX = "0x" & Hex($x*255,2) & Hex( $Y*255,2) & Hex(-Abs($x*255),2) ;$HEX_Z,6) ;~ MsgBox(0,"",$hex) Return $HEX EndFunc ;==>_HEX_DEV Func _HEX_DEV($X, $Y) $HEX_X = Round($X * 255, 0) $HEX_Y = Round($Y * 255, 0) $HEX_Z = Round(($X * 255 * $Y) / 2, 0) ;~ $HEX = Random (0,255*255*255) $HEX = "0x" & Hex($x*255,2) & Hex( $Y*255,2) & Hex(-Abs($x*255),2) ;$HEX_Z,6) ;~ MsgBox(0,"",$hex) Return $HEX EndFunc ;==>_HEX_DEV PS. i know that some functions contains things that do not fill a function, like "-Abs($x*255)", but i experimented so much with them so i left them there for easy editing later on. [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now