programmers please help
Author: bla on June 11 2008
Viewed 3778 times. 9 people liked this blog. You can rate it below if you haven't already.
People who enjoyed reading this: lematt, license, cbit, delete, jogn, Roshi, mlbot, lysdexic, Bogiwoye
--> i need someone to write a (probably) very simple program for me
its to generate a picture of black and white squares (pixels on or off)
i dont know shit about programming (except a bit of zx spectrum basic back in the day) but im pretty sure itd be easy to do for someone whos into coding
theres not much to it- ive been doing it 'by hand' but i always make mistakes so i need to get a computer to do it
anyway, it goes like this:
start in the middle square and go round in a spiral 1 square at a time (might as well be clockwise first going up then right then down, down, left ,left, up , up ,up, right.... etc)
the only rule to determine whether each square is black or white is if theres an even number of black squares adjacent to it then its black, if its an odd number then its white
thats it
i REALLY want to see what it looks like with 1000's of squares but doing it by hand is a real pain and its almost impossible not to make mistakes- ive done it on graph paper to about 100x100 but i need to see it much bigger to see what structures develop in it
if noone fancies it then i guess i could take suggestions for programming languages and tutorials but im a really slow learner
Read bla's other blogs.bla's Recent Blogs
Comments

1 | 2 | 3 | 4
my brain has really deteriorated over the years
through lack of use i guess
im good at using my imagination but trying to fill in all the useful details necessary to actually do something just makes me feel ill

I still think excel is good for this kind of thing and easy to use. you could use binary numbers and make a formula that added up all the squares around the square and use conditional formating to change it black if it is 0 or white if it is 1. Then you could copy the design using paint. I started to try but got circular references, I think you can turn that off though.

my mind asplode if i think about trying to get excel to carry out calculations in the correct sequence to form an expanding 'spiral' though. surely thats not possible?

I was kinda suprised:
no one said: "WHY exactly do you want this, I mean, besides you just really wanna see the result???"


Then I remembered this is the dude who prorgammed his own sine wave in binary.

bla, you are an odd duck

cbit: you could totally do it, just convert columns to/from integers.
Recent blogs: Signing Off, Audio OS?, suspended  

mlbot said: "I was kinda suprised:
no one said: "WHY exactly do you want this, I mean, besides you just really wanna see the result???"


Then I remembered this is the dude who prorgammed his own sine wave in binary.
"


hahahaha
put the 2 together........

FTW: someone should program a javascript that does it with and [love] icons

okay i spent way too much time on this but i think i got it in vb.

it's a lot trickier than i thought. the hardest part was planning the attack then i racked my brain until i figured there must be a formula to determine your turning points since you're starting in the middle of a 2d array. turns out it's the series of squares + the series of squares - the squareRoot.

i'm sure there's a bug in there so download the zipped exe here and tell me if i understood you right: link

code:
Imports System.IO
Public Class Form1

Dim strDirection As String = "Up"
Dim arrSquares() As Integer
Dim arrRectangles() As Integer
Dim arrGrid(,) As Integer
Dim strBlack As String
Dim strWhite As String

Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click

If CDbl(txtSquareFactor.Text) Mod 2 = 0 Then
MessageBox.Show("Enter an odd number so that you can start in a central location on the grid", "You need an odd factor.")
Else

strBlack = CStr(txtBlack.Text)
strWhite = CStr(txtWhite.Text)

Dim intSquareFactor As Integer = (CInt(Val(txtSquareFactor.Text)))
ReDim arrGrid(intSquareFactor + 1, intSquareFactor + 1)
Dim intHStart As Integer = CInt((((CInt(Val(txtSquareFactor.Text)) + 1) / 2)))
Dim intVStart As Integer = CInt((((CInt(Val(txtSquareFactor.Text)) + 1) / 2)))
Dim intCurrentH As Integer = intHStart
Dim intCurrentV As Integer = intVStart
Dim intMoves As Integer = (intSquareFactor * intSquareFactor) - 1

'get yer turning points
Dim i As Integer
ReDim arrSquares(intSquareFactor)
For i = 0 To (intSquareFactor)
arrSquares(i) = CInt((i + 1) * (i + 1))
Next
Dim j As Integer
ReDim arrRectangles(intSquareFactor)
For j = 0 To (intSquareFactor)
arrRectangles(j) = CInt(((j + 1) * (j + 1)) - (j + 1))
Next

'gets this f'ing party started
arrGrid(intHStart, intVStart) = 1

For index As Integer = 1 To intMoves

Select Case strDirection
Case "Up"
intCurrentH = intCurrentH
intCurrentV = intCurrentV - 1
arrGrid(intCurrentH, intCurrentV) = Decide(intCurrentH, intCurrentV)
Case "Right"
intCurrentH = intCurrentH + 1
intCurrentV = intCurrentV
arrGrid(intCurrentH, intCurrentV) = Decide(intCurrentH, intCurrentV)
Case "Down"
intCurrentH = intCurrentH
intCurrentV = intCurrentV + 1
arrGrid(intCurrentH, intCurrentV) = Decide(intCurrentH, intCurrentV)
Case "Left"
intCurrentH = intCurrentH - 1
intCurrentV = intCurrentV
arrGrid(intCurrentH, intCurrentV) = Decide(intCurrentH, intCurrentV)
End Select

Dim intCount As Integer
For intCount = 0 To UBound(arrSquares)
If index = arrSquares(intCount) Or index = arrRectangles(intCount) Then
strDirection = SwitchDirection(strDirection)
Exit For
End If
Next
Next

Dim fs As New FileStream("C:TempTest.txt", FileMode.Create, FileAccess.Write)
Dim s As New StreamWriter(fs)
s.BaseStream.Seek(0, SeekOrigin.End)

s.WriteLine("Extra padding is to avoid out-of-bounds errors in neighbor comparisons.")
s.WriteLine()

Dim intRowCounter, intColumnCounter As Integer
For intRowCounter = 0 To intSquareFactor + 1
s.WriteLine()
For intColumnCounter = 0 To intSquareFactor + 1
s.Write(Replace(Replace(CStr(arrGrid(intRowCounter, intColumnCounter)), "1", strBlack), "0", strWhite) & "|")
Next
Next
s.Close()

MessageBox.Show("Thank you for this pointless exercise.", "Process Complete")

End If
End Sub

Function Decide(ByVal intCurrentInputH As Integer, ByVal intCurrentInputV As Integer) As Integer
Dim intTotal As Integer = 0
intTotal = (Check(intCurrentInputH, intCurrentInputV - 1)) + _
(Check(intCurrentInputH + 1, intCurrentInputV - 1)) + _
(Check(intCurrentInputH + 1, intCurrentInputV)) + _
(Check(intCurrentInputH + 1, intCurrentInputV + 1)) + _
(Check(intCurrentInputH, intCurrentInputV + 1)) + _
(Check(intCurrentInputH - 1, intCurrentInputV + 1)) + _
(Check(intCurrentInputH - 1, intCurrentInputV)) + _
(Check(intCurrentInputH - 1, intCurrentInputV - 1))

If intTotal Mod 2 = 0 Then
Return 1
Else : Return 0
End If
End Function

Function Check(ByVal intCheckH As Integer, ByVal intCheckV As Integer) As Integer
If arrGrid(intCheckH, intCheckV) = 1 Then
Return 1
Else : Return 0
End If
End Function

Function SwitchDirection(ByVal Previous As String) As String
If Previous = "Up" Then
Return "Right"
Else
If Previous = "Right" Then
Return "Down"
Else
If Previous = "Down" Then
Return "Left"
Else
If Previous = "Left" Then
Return "Up"
Else : Return "Boobs" ' just closes all paths so don't get excited
End If
End If
End If
End If
End Function

End Class
i justed 10 minutes ago and i already see how i messed up. i redimmed the wronged array in the second loop of getting the turning points. i'll correct it tomorrow.

so the zipped exe is no good?
anyway- thanks for your efforts- it looks like this is much more hard work than i thought- its so easy to do in the mind

mlbot said: "I was kinda suprised:
no one said: "WHY exactly do you want this, I mean, besides you just really wanna see the result???"
"

To see what happens! Surprising that a scientist would have to ask ;)

actually, i think the exe is good i think i was seeing things last night. run the program and see if it outputs what you'd expect or post a bigger picture of your manual efforts. i copied and pasted the ouput into excel and split on the pipes |, then did a conditional format to color the boxes. Looks pretty neat... but i can't tell if it's the same pic you posted in the blog.

i just ran that exe and examinied the result- i dont think its quite doing what it should
does it go up first then clockwise as its writing new squares?
i got this for 9x9
(i removed the extra padding)
|X|O|X|X|O|O|O|O|O|
|X|X|O|O|O|X|O|O|X|
|O|X|X|X|X|O|X|O|O|
|X|O|X|O|O|O|O|O|X|
|O|X|O|O|X|O|X|X|X|
|O|X|X|O|O|O|O|X|O|
|X|X|O|O|X|O|X|O|X|
|X|O|O|O|O|X|X|X|O|
|O|O|X|O|O|X|X|O|O|
and it should be:
|X|X|O|X|O|O|X|X|O|
|O|X|X|O|X|X|X|O|O|
|X|O|X|X|O|X|O|O|X|
|X|O|X|O|O|O|O|O|O|
|O|O|X|O|X|O|X|O|O|
|O|X|O|O|O|O|O|X|X|
|O|O|X|O|X|O|X|X|X|
|O|O|O|O|X|X|O|X|O|
|O|X|O|X|X|O|X|O|O|
unless ive made mistakes

oh yeah- X is black O is white
thanks for your efforts!
i really need it in little pixels though

comparing those 2 results again it looks like its just mirrored and rotated but otherwise correct
how could it be done with individual pixels?

1 | 2 | 3 | 4

Register / login
You must be a member to reply or post. signup or login