Jump to content

Math Magic


CoePSX
 Share

Recommended Posts

WOW!! That's really amazing!

I never thought about using DllCalls for that! :whistle:

Dll drawing doesn't make the screen flash because it doesn't need

to be refreshed. Thanks!

If it's OK i'll use it instead of GUICtrlSetGraphic.

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Got it! :)

It's now a (nearly) real screen saver.

I got the command-line stuff. /c = configure; /s = play

There's a zip file with the compiled .scr and the code attached.

Hope you like it.

wow nice job, i had no clue that u can create screensavers with autoit, maybe ill use this knew knowledge some times :whistle:

Link to comment
Share on other sites

WOW!! That's really amazing!

I never thought about using DllCalls for that! :whistle:

Dll drawing doesn't make the screen flash because it doesn't need

to be refreshed. Thanks!

If it's OK i'll use it instead of GUICtrlSetGraphic.

Yw, Feel free to tidy it up... :)

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

As for screen savers, they need a couple of extra functions that I'm sure are not built in to AutoIt.

actually it IS a screensaver.

copy .src into system-directory and u can choose it in your screensaver-settings.

only thing that is not similiar to normal screensavers is the fact that u cant close it by pressing any key (only mousemove)

Link to comment
Share on other sites

Hmm, that's not something I expected.

Mixing this with a Windows Media Player visualization I made a few months ago and a GDI+ testing utility I also made a few months ago, I created these.

colors.png

colorsquare.png

Both are rendered at 1280x800 pixels, but only about 400 kb.

Shows how programs can work together.

By the way, these are settings 4 and 11 respectively.

Edit: Since these are png with a transparent background, Internet Explorer users may experience a weird background color which I cannot fix. I got black when I tested it, but Firefox users should get their background color through the images.

Edited by Icekirby1
Link to comment
Share on other sites

Hmm, that's not something I expected.

Mixing this with a Windows Media Player visualization I made a few months ago and a GDI+ testing utility I also made a few months ago, I created these.

colors.png

colorsquare.png

Both are rendered at 1280x800 pixels, but only about 400 kb.

Shows how programs can work together.

By the way, these are settings 4 and 11 respectively.

Edit: Since these are png with a transparent background, Internet Explorer users may experience a weird background color which I cannot fix. I got black when I tested it, but Firefox users should get their background color through the images.

Could you post the code? That is really cool!

Link to comment
Share on other sites

HotKeySet ("{ESC}", "Quit")
WinActivate("Paint", "")
For $i = 2 To 11
    MagicDraw($i)
    Sleep(1000)
    Send("^+n")
Next

Hey all, try changing the For $i = 2 To 11 to For $i = 2 To 101

It makes a whole bunch more designs. Also, I accidentally close MSPaint while it was running, and it starting making really cool designs on my desktop with the dotted-line boxes. Just be forewarned that if you are going to use it on your plain desktop that your icons are either out of the way, or you dont mind if they get randomly scattered :whistle: Really cool program!

- Dan [Website]

Link to comment
Share on other sites

Could you post the code? That is really cool!

The GDI+ tester is a standalone .Net 2.0 assembly. It allows you to type in a series of C# commands which then get compiled into memory, loaded, then called. Very few people will understand it so source won't help you much. The color cycle is a simple algorythm. I also didn't save the drawing code. It was really stupid and I should have saved it.

Link to comment
Share on other sites

The GDI+ tester is a standalone .Net 2.0 assembly. It allows you to type in a series of C# commands which then get compiled into memory, loaded, then called. Very few people will understand it so source won't help you much. The color cycle is a simple algorythm. I also didn't save the drawing code. It was really stupid and I should have saved it.

Hmmm... well, i was mainly thinking of the coloring, so I updated the code in the While loop to this:

While GUIGetMsg() <> $GUI_EVENT_CLOSE
        $PicSize = 1
        $iNumber = Random(1, 360, 1)
        $ColorStart = Random(150, 255, 1) & Random(150, 255, 1) & Random(150, 255, 1) ;new/changed
        $Color = "0x" & Hex($ColorStart, 6) ;new/changed
        GUICtrlSetColor($Label, $Color)
        GUICtrlSetData($Label, $iNumber)
        Dim $OldCoord[2]
        $OldCoord[0] = @DesktopWidth/2
        $OldCoord[1] = @DesktopHeight/2
        For $R = 1 To $MaxTimes
            $ColorStart = $ColorStart + 1   ;new/changed
            $Color = "0x" & Hex($ColorStart, 6)  ;new/changed
            $PicSize += $IncreaseSize
            $X = Sin($R * $iNumber) * $PicSize + @DesktopWidth/2
            $Y= Cos($R * $iNumber) * $PicSize + @DesktopHeight/2
            GUICtrlSetGraphic($Graphic,$GUI_GR_MOVE, $OldCoord[0], $OldCoord[1])
            GUICtrlSetGraphic($Graphic,$GUI_GR_COLOR, $Color)
            GUICtrlSetGraphic($Graphic,$GUI_GR_LINE, $X, $Y)
            GUICtrlSetGraphic($Graphic,$GUI_GR_REFRESH)
            $OldCoord[0] = $X
            $OldCoord[1] = $Y
            Sleep($Delay)
        Next
        Sleep(2000)
        GUICtrlDelete($Graphic)
        $Graphic = GUICtrlCreateGraphic(0, 0, @DesktopWidth, @DesktopHeight)
    WEnd

But it doesn't really make that great of a gradient... still working on it.

WOW!! That's really amazing!

I never thought about using DllCalls for that! tongue.gif

Dll drawing doesn't make the screen flash because it doesn't need

to be refreshed. Thanks!

If it's OK i'll use it instead of GUICtrlSetGraphic.

How's it coming? :whistle:
Link to comment
Share on other sites

The DLLCall drawing is good because it doesn't flash the picture, but i'm

also working on a color scheme.

I'll post the whole code when i get this color stuff. Soon.

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

Oh, the color algorythm? That's easy. This is C# code by the way.

static int r = 254, g = 0, b = 1;
static string d = "br";

static System.Drawing.Pen GetPen()
{
    if (d == "br")
    {
        if (b > 0)
        {
            b -= 1;
            r += 1;
        }
        else
            d = "rg";
    }
    else if (d == "rg")
    {
        if (r > 0)
        {
            r -= 1;
            g += 1;
        }
        else
            d = "gb";
    }
    else if (d == "gb")
    {
        if (g > 0)
        {
            g -= 1;
            b += 1;
        }
        else
            d = "br";
    }
    return new System.Drawing.Pen(System.Drawing.Color.FromArgb(r, g, b));
}
Link to comment
Share on other sites

:whistle: Thanks icekirby, but i was just finishing the GUI example when I read your post.

It was useful, because I actually learned something now, and this little script can be useful

to people since it's written in AutoIt.

I tried not to complicate it too much, but it's not THAT simple. Anyway, soon I'll be posting

the screensaver with AutoIt gradients :)

#NoTrayIcon
#include <GUIConstants.au3>

;/// Settings Here ///
$NumberOfGradients = 100
$SizeOfLayer = 2
;/////////////////////

GUICreate("Gradients", $NumberOfGradients*$SizeOfLayer, 70, -1, -1)
Dim $Label[$NumberOfGradients]
For $i = 0 To $NumberOfGradients-1
    $Label[$i] = GUICtrlCreateLabel("", $i*$SizeOfLayer, 0, 10, 50)
Next
$Button = GUICtrlCreateButton("Random Gradient", 0, 50, $NumberOfGradients*$SizeOfLayer, 20)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            $Color = ColorGradient(RandomColor(), RandomColor(), $NumberOfGradients)
            For $i = 0 To $NumberOfGradients-1
                GUICtrlSetBkColor($Label[$i], $Color[$i])
            Next
    EndSwitch
WEnd

Func ColorGradient($hInitialColor, $hFinalColor, $iReturnSize)
    $hInitialColor = Hex($hInitialColor, 6)
    $hFinalColor = Hex($hFinalColor, 6)
    
    Local $iRed1 = Dec (StringLeft($hInitialColor, 2))
    Local $iGreen1 = Dec (StringMid($hInitialColor, 3, 2))
    Local $iBlue1 = Dec (StringMid($hInitialColor, 5, 2))
    
    Local $iRed2 = Dec (StringLeft($hFinalColor, 2))
    Local $iGreen2 = Dec (StringMid($hFinalColor, 3, 2))
    Local $iBlue2 = Dec (StringMid($hFinalColor, 5, 2))
    
    Local $iPlusRed = ($iRed2-$iRed1)/($iReturnSize-1)
    Local $iPlusBlue = ($iBlue2-$iBlue1)/($iReturnSize-1)
    Local $iPlusGreen = ($iGreen2-$iGreen1)/($iReturnSize-1)
    
    Dim $iColorArray[$iReturnSize]
    For $i = 0 To $iReturnSize-1
        $iNowRed = Floor($iRed1 + ($iPlusRed*$i))
        $iNowBlue = Floor($iBlue1 + ($iPlusBlue*$i))
        $iNowGreen = Floor($iGreen1 + ($iPlusGreen*$i))
        $iColorArray[$i] = Dec (Hex($iNowRed, 2) & Hex($iNowGreen, 2) & Hex($iNowBlue, 2))
    Next
    Return ($iColorArray)
EndFunc
Func RandomColor($hMinColor = 0x000000, $hMaxColor = 0xFFFFFF)
    $hMinColor = Hex($hMinColor, 6)
    $hMaxColor = Hex($hMaxColor, 6)
    
    Local $iRed1 = Dec (StringLeft($hMinColor, 2))
    Local $iGreen1 = Dec (StringMid($hMinColor, 3, 2))
    Local $iBlue1 = Dec (StringMid($hMinColor, 5, 2))
    
    Local $iRed2 = Dec (StringLeft($hMaxColor, 2))
    Local $iGreen2 = Dec (StringMid($hMaxColor, 3, 2))
    Local $iBlue2 = Dec (StringMid($hMaxColor, 5, 2))
    
    Local $iRndRed = Random($iRed1, $iRed2, 1)
    Local $iRndGreen = Random($iGreen1, $iGreen2, 1)
    Local $iRndBlue = Random($iBlue1, $iBlue2, 1)
    
    Return Dec (Hex($iRndRed, 2) & Hex($iRndGreen, 2) & Hex($iRndBlue, 2))
EndFunc
Edited by CoePSX

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

:whistle:

Finally done! It's got a better configuration now.

Diferences in this one:

-= Gradients (optional)

-= 2 Colors drawing option (optional)

-= Pencil showing (optional)

-= Looks nicer! (sorry, not optional)

OK, the code is in the first post.

The attach too.

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

Well I will try to explain what I think is the math behind this. Its actually pretty simple if you think about it. The main functions that describe the drawing are basically the parametric equations.

x( R ) = sin(R*inumber)*(picsize) + constant

and

y( R ) = cos(R*inumber)*(picsize) + constant

The equations of a circle in parametric style is

x(t) = sin(t) and y(t) = cos(t)

The difference between these functions is a matter of multiples and constants.

The pic size value increases with every iteration and accounts for the increasing radius of the drawing.

(The spiral effect)

The @desktopwidth/2 and @desktophieght/2 account for centering the image on the screen.

The only reason every one does not look look like a circle is because the step value is very large. If you changed the step to an infintecimal number than it would make a spiral or at least part of arc every time.

The reason for the odd shapes is that since your facts R and t are not factors of pi (3.14...) the points are always offset.

The number of degrees between the points of the line segmant traverses every step is found witht he conversion, (if stepsize is over 180 then subtract as many 360's as needed until you get a number between -180 and 180).

Stepsize = (R*180)/pi

i.e.

for R=2

2*180/pi = 114 degrees step size

for R=3

171 deg

R=4

229 deg, however effectivly this is -131 deg

R=5

286 deg (effectively -76 deg)

Now we get to the "spiral one"

R=6

344 deg (effectivly -16 degrees)

Well this is the small step value that we want, and it produces a fairly good semblance of a smooth curve especially with the picsize incremenet added in.

A few quick calculations how that R = 19 would most likely be a good spiral too. (8 deg step)

Well that about does the explanation.

I assume the writer of this understood most of this.

If anyone has anymore q's id be happy to try to answer them, I like math and stuff like this intrigues me.

EDIT: Made the paren R paren into ® and I fixed it.

Edited by Wus
Link to comment
Share on other sites

Thanks WUS. Yeah I understood it.

My high school math teacher would have loved it too XD

I'll try to have more control over the shapes in the code.

Thanks for brightening it up for me.

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

If you want to have more control its easy, just throw a pi factor in and offset it to your desired amount.

i.e.

instead of

sin(2*[1->360])

use

sin(X*(degrees*(pi/180))

And degrees is your step arclength (size) and X is your number of steps.

So rather small degree values will give you smooth spirals and larger ones will give you shapes. 120 deg would give you a triangle so 125 (added a small offset) would give you a rotating triangle. 90 a square, 95 a rotating square... and so on. Though the offset should be smaller for shapes with more numbers of sides or the resolution of the shape will deteriorate.

Degree increments from -120 to -180 and 120 - 180 will give starish or almost hash-like images.

Edited by Wus
Link to comment
Share on other sites

Amazing!!

Now I can do any shape I desire!

For entertaing purposes I will keep the random number, but it's good to

know that I can control the draw now.

Thanks man!

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...