Jump to content

Strange grids formed when using random clicks?


Recommended Posts

I decided to make a cloud generator, something that makes random blobs that somewhat represent clouds for an upcoming game I've been developing (university project). To test out some functions I used MS paint and made my code click on random points within a rectangle, using a simple algorithm to make a sort of wispy blob shape. Anyway, this is what always happens no matter what I do to the code (and I've spent hours changing it):

71VNi5f.png

I mean I'm just using this for testing, it's not a big deal, but the curiosity is killing me. Why the hell would a grid be formed here??? I just don't get it, does anyone know why this is happening?

Link to comment
Share on other sites

  • Moderators

itsnotluketime,

It is obviously the recursive call to the _CloudGenerate function that is causing the problem.

...

Seriously, if you want some help, please post the code you use. The random number generator used by AutoIt is pretty good, so it must be something in your algorithm that is causing the effect.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here's the function I have so far:

$midx = $tlpos[0] + (($brpos[0] - $tlpos[0]) / 2)
$midy = $tlpos[1] + (($brpos[1] - $tlpos[1]) / 2)
$specialmidx = $midx
$specialmidy = $midy

Func click($tl, $br)
   $temprandnum = Random(1, 10, 1)
   If ($temprandnum >= 7) Then
      If $specialmidx > $midx Then
         $specialmidx += Random(0 - ($specialmidx - $midx), 2, 1)
      ElseIf $specialmidx <= $midx Then
         $specialmidx += Random(-2,($midx - $specialmidx), 1)
      EndIf
      If $specialmidy > $midy Then
         $specialmidy += Random(0 - ($specialmidy - $midy), 2, 1)
      ElseIf $specialmidy <= $midy Then
         $specialmidy += Random(-2, ($midy - $specialmidy), 1)
      EndIf
   EndIf
   If ($temprandnum <= 6) Then
      $specialmidx += Random(-1, 1, 1)
      $specialmidy += Random(-1, 1, 1)
   EndIf
   If $specialmidx >= $br[0] Then
      $Specialmidx -= Random(1, 2, 1)
   EndIf
   If $specialmidx <= $tl[0] Then
      $Specialmidx += Random(1, 2, 1)
   EndIf
   If $specialmidy >= $br[1] Then
      $Specialmidy -= Random(1, 2, 1)
   EndIf
   If $specialmidy <= $tl[1] Then
      $Specialmidy += Random(1, 2, 1)
   EndIf
   MouseMove($specialmidx, $specialmidy, 10)
   MouseDown( "left" )
   MouseUp( "left" )
EndFunc

$tlpos and $brpos are defined earlier on in the script, for the top right and bottom right corners of the triangle. The code is super crude, it clicks the same places over and over, but like I said I'm just testing things out. And for now it only works for smaller triangles

EDIT*: Perhaps my program thinks my screen is smaller than it really is, so when it moves to each pixel it's actually moving like 1.2 pixels on the screen, meaning every now and then it will skip a pixel. I agree with you Melba23 about the random functions, I've used them a lot and they've never failed me.

Edited by itsnotluketime
Link to comment
Share on other sites

  • Moderators

itsnotluketime,

Using that algorithm I get nothing like your "grid" pattern - and as expected each pass produces a different pattern:

#include <Array.au3>

HotKeySet("{ESC}", "_Exit")

Global $tlpos[2] = [10, 10], $brpos[2] = [110, 110]

$midx = $tlpos[0] + (($brpos[0] - $tlpos[0]) / 2)
$midy = $tlpos[1] + (($brpos[1] - $tlpos[1]) / 2)
$specialmidx = $midx
$specialmidy = $midy

While 1

    Global $aPos[30][30]

    For $i = 1 To 100
        click($tlpos, $brpos)
    Next

    _ArrayDisplay($aPos, "", Default, 8)

WEnd

Func click($tl, $br)
   $temprandnum = Random(1, 10, 1)
   If ($temprandnum >= 7) Then
      If $specialmidx > $midx Then
         $specialmidx += Random(0 - ($specialmidx - $midx), 2, 1)
      ElseIf $specialmidx <= $midx Then
         $specialmidx += Random(-2,($midx - $specialmidx), 1)
      EndIf
      If $specialmidy > $midy Then
         $specialmidy += Random(0 - ($specialmidy - $midy), 2, 1)
      ElseIf $specialmidy <= $midy Then
         $specialmidy += Random(-2, ($midy - $specialmidy), 1)
      EndIf
   EndIf
   If ($temprandnum <= 6) Then
      $specialmidx += Random(-1, 1, 1)
      $specialmidy += Random(-1, 1, 1)
   EndIf
   If $specialmidx >= $br[0] Then
      $Specialmidx -= Random(1, 2, 1)
   EndIf
   If $specialmidx <= $tl[0] Then
      $Specialmidx += Random(1, 2, 1)
   EndIf
   If $specialmidy >= $br[1] Then
      $Specialmidy -= Random(1, 2, 1)
   EndIf
   If $specialmidy <= $tl[1] Then
      $Specialmidy += Random(1, 2, 1)
   EndIf

   $aPos[$specialmidx - 45][$specialmidy - 45] &= "X"

EndFunc

Func _Exit()
    Exit
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Wow thanks for doing that. I guess it's just a problem with paint then. I'll try changing my resolution and tweaking other settings until I can get this to work, thanks for the help. I didn't even know you could display an array like that, ill definitely use that in the future :).

Edited by itsnotluketime
error in phrasing
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...