Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- image = LoadImage("HueEverywhere_example8.png")
- Graphics ImageWidth(image), ImageHeight(image)
- image = LoadImage("HueEverywhere_example8.png")
- x = 0
- y = 0
- w = ImageWidth(image)
- h = ImageHeight(image)
- Type start
- Field x,y
- Field dis#
- Field nex.start
- End Type
- Type cell
- Field x,y
- Field dis#
- End Type
- Type oldCell
- Field x,y
- Field dis#
- End Type
- initCell.start = New start
- initCell\x = x
- initCell\y = y
- initCell\dis = 1
- DrawImage image,0,0
- Dim array#(w,h)
- maxDis = 0
- changed = 0
- imgBuff = ImageBuffer(image)
- LockBuffer(imgBuff)
- s.start = First start
- colr = col(0,0,0)
- colg = col(0,0,1)
- colb = col(0,0,2)
- newcol = 1*( (colr*256*256) + (colg*256) + colb )
- WritePixelFast(s\x,s\y, newcol, imgBuff)
- While s <> Null
- ;DebugLog Str(s)+", "+s\x+", "+s\y+", "+s\dis
- DebugLog Int(s)
- c.cell = New cell
- c\x = s\x
- c\y = s\y
- c\dis = s\dis
- While c <> Null
- dis# = s\dis + Sqr#((c\x-s\x)*(c\x-s\x)+(c\y-s\y)*(c\y-s\y))
- For dy = -1 To 1
- For dx = -1 To 1
- If dx <> 0 Or dy <> 0
- nx = c\x+dx
- ny = c\y+dy
- ndis# = s\dis + Sqr#((nx-s\x)*(nx-s\x)+(ny-s\y)*(ny-s\y))
- If nx >= 0 And nx < w And ny >= 0 And ny < h
- If KeyHit(1) End
- pixcol = ReadPixelFast(nx, ny, imgBuff)
- If pixcol <> -16777216 ;if the pixel is not black
- If array(nx,ny) = 0 Or ndis < array(nx,ny)
- check = 1
- steps = Ceil(dis)*2
- For k = 0 To steps
- r# = k*1./steps
- offx# = Int(s\x + (c\x-s\x)*r)
- offy# = Int(s\y + (c\y-s\y)*r)
- pixcol2 = ReadPixelFast(offx,offy,imgBuff)
- If pixcol2 = -16777216
- check = 0
- Exit
- EndIf
- Next
- If check
- array(nx,ny) = ndis
- changed = changed + 1
- If ndis > maxDis
- maxDis = ndis
- EndIf
- newCell.cell = New cell
- newCell\x = nx
- newCell\y = ny
- newCell\dis = ndis
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- Next
- Next
- o.oldCell = New oldCell
- o\x = c\x
- o\y = c\y
- o\dis = c\dis
- ;DebugLog " "+Str(o)
- Delete c
- c = First cell
- Wend
- For o.oldCell = Each oldCell
- bordersWhite = 0
- For dy = -1 To 1
- For dx = -1 To 1
- If dx <> 0 Or dy <> 0
- nx = o\x+dx
- ny = o\y+dy
- If nx >= 0 And nx < w And ny >= 0 And ny < h
- pixcol = ReadPixelFast(nx,ny,imgBuff)
- If (pixcol = -1 And array(nx,ny) = 0) Or array(nx,ny) > o\dis+10
- bordersWhite = 1
- Exit
- EndIf
- EndIf
- EndIf
- Next
- If bordersWhite Exit
- Next
- If bordersWhite
- ns.start = New start
- ns\x = o\x
- ns\y = o\y
- ns\dis = o\dis
- s2.start = First start
- While s2\nex <> Null
- If ns\dis < s2\nex\dis
- Exit
- EndIf
- s2 = s2\nex
- Wend
- ns\nex = s2\nex
- s2\nex = ns
- ;Stop
- EndIf
- Delete o
- Next
- If changed > 20
- For j = 0 To h
- For i = 0 To w
- If KeyHit(1) End
- dis2# = array(i,j)*360./maxDis
- If array(i,j) <> 0
- colr = col(dis2,0,0)
- colg = col(dis2,0,1)
- colb = col(dis2,0,2)
- newcol = 1*( (colr*256*256) + (colg*256) + colb )
- WritePixelFast(i,j, newcol, imgBuff)
- EndIf
- Next
- Next
- UnlockBuffer(imgBuff)
- DrawImage image,0,0
- LockBuffer(imgBuff)
- changed = 0
- EndIf
- If KeyHit(1) End
- s2 = s
- s = s\nex
- Delete s2
- Wend
- For j = 0 To h
- For i = 0 To w
- dis2# = array(i,j)*360./maxDis
- If array(i,j) <> 0
- colr = col(dis2,0,0)
- colg = col(dis2,0,1)
- colb = col(dis2,0,2)
- newcol = 1*( (colr*256*256) + (colg*256) + colb )
- WritePixelFast(i,j, newcol, imgBuff)
- EndIf
- Next
- Next
- DebugLog "Done!"
- UnlockBuffer(imgBuff)
- DrawImage image,0,0
- WaitKey
- If KeyDown(28) SaveBuffer(FrontBuffer(), "HueEverywhere_example8.2.png")
- End
- Function col(ang1#, ang2#, kind)
- While ang1 > 360
- ang1 = ang1 - 360
- Wend
- While ang1 < 0
- ang1 = ang1 + 360
- Wend
- While ang2 > 180
- ang2 = ang2 - 360
- Wend
- While ang2 < -180
- ang2 = ang2 + 360
- Wend
- a3# = ang2/180.
- ; DebugLog kind
- If ang1 > 300
- diff# = (ang1-300)/60.
- r = 255
- g = 0
- b = 255*(1-diff)
- ElseIf ang1 > 240
- diff# = (ang1-240)/60.
- r = 255*diff
- g = 0
- b = 255
- ElseIf ang1 > 180
- diff# = (ang1-180)/60.
- r = 0
- g = 255*(1-diff)
- b = 255
- ElseIf ang1 > 120
- diff# = (ang1-120)/60.
- r = 0
- g = 255
- b = 255*diff
- ElseIf ang1 > 60
- diff# = (ang1-60)/60.
- r = 255*(1-diff)
- g = 255
- b = 0
- Else
- diff# = (ang1-00)/60.
- r = 255
- g = 255*diff
- b = 0
- EndIf
- If a3 > 0
- r2 = r + a3*(255-r)
- g2 = g + a3*(255-g)
- b2 = b + a3*(255-b)
- Else
- r2 = r + a3*r
- g2 = g + a3*g
- b2 = b + a3*b
- EndIf
- ; DebugLog "First: " + r2 + ":" + g2 + ":" + b2
- If r2 > 255
- r2 = 255
- ElseIf r2 < 0
- r2 = 0
- EndIf
- If g2 > 255
- g2 = 255
- ElseIf g2 < 0
- g2 = 0
- EndIf
- If b2 > 255
- b2 = 255
- ElseIf b2 < 0
- b2 = 0
- EndIf
- ; DebugLog "Second: " + r2 + ":" + g2 + ":" + b2
- If kind = 0
- Return r2
- ElseIf kind = 1
- Return g2
- ElseIf kind = 2
- Return b2
- Else
- Return 0
- EndIf
- If KeyHit(1) End
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement