Advertisement
Guest User

Untitled

a guest
Nov 18th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. image = LoadImage("HueEverywhere_example8.png")
  2. Graphics ImageWidth(image), ImageHeight(image)
  3.  
  4. image = LoadImage("HueEverywhere_example8.png")
  5. x = 0
  6. y = 0
  7. w = ImageWidth(image)
  8. h = ImageHeight(image)
  9.  
  10. Type start
  11. Field x,y
  12. Field dis#
  13. Field nex.start
  14. End Type
  15.  
  16. Type cell
  17. Field x,y
  18. Field dis#
  19. End Type
  20.  
  21. Type oldCell
  22. Field x,y
  23. Field dis#
  24. End Type
  25.  
  26. initCell.start = New start
  27. initCell\x = x
  28. initCell\y = y
  29. initCell\dis = 1
  30.  
  31. DrawImage image,0,0
  32.  
  33. Dim array#(w,h)
  34. maxDis = 0
  35. changed = 0
  36.  
  37. imgBuff = ImageBuffer(image)
  38. LockBuffer(imgBuff)
  39.  
  40. s.start = First start
  41.  
  42. colr = col(0,0,0)
  43. colg = col(0,0,1)
  44. colb = col(0,0,2)
  45. newcol = 1*( (colr*256*256) + (colg*256) + colb )
  46. WritePixelFast(s\x,s\y, newcol, imgBuff)
  47.  
  48. While s <> Null
  49. ;DebugLog Str(s)+", "+s\x+", "+s\y+", "+s\dis
  50. DebugLog Int(s)
  51.  
  52. c.cell = New cell
  53. c\x = s\x
  54. c\y = s\y
  55. c\dis = s\dis
  56.  
  57. While c <> Null
  58. dis# = s\dis + Sqr#((c\x-s\x)*(c\x-s\x)+(c\y-s\y)*(c\y-s\y))
  59.  
  60. For dy = -1 To 1
  61. For dx = -1 To 1
  62. If dx <> 0 Or dy <> 0
  63.  
  64. nx = c\x+dx
  65. ny = c\y+dy
  66. ndis# = s\dis + Sqr#((nx-s\x)*(nx-s\x)+(ny-s\y)*(ny-s\y))
  67.  
  68. If nx >= 0 And nx < w And ny >= 0 And ny < h
  69.  
  70. If KeyHit(1) End
  71.  
  72. pixcol = ReadPixelFast(nx, ny, imgBuff)
  73.  
  74. If pixcol <> -16777216 ;if the pixel is not black
  75.  
  76. If array(nx,ny) = 0 Or ndis < array(nx,ny)
  77. check = 1
  78.  
  79. steps = Ceil(dis)*2
  80. For k = 0 To steps
  81. r# = k*1./steps
  82. offx# = Int(s\x + (c\x-s\x)*r)
  83. offy# = Int(s\y + (c\y-s\y)*r)
  84.  
  85. pixcol2 = ReadPixelFast(offx,offy,imgBuff)
  86.  
  87. If pixcol2 = -16777216
  88. check = 0
  89. Exit
  90. EndIf
  91. Next
  92.  
  93. If check
  94. array(nx,ny) = ndis
  95. changed = changed + 1
  96.  
  97. If ndis > maxDis
  98. maxDis = ndis
  99. EndIf
  100.  
  101. newCell.cell = New cell
  102. newCell\x = nx
  103. newCell\y = ny
  104. newCell\dis = ndis
  105. EndIf
  106. EndIf
  107.  
  108. EndIf
  109.  
  110. EndIf
  111. EndIf
  112. Next
  113. Next
  114.  
  115. o.oldCell = New oldCell
  116. o\x = c\x
  117. o\y = c\y
  118. o\dis = c\dis
  119. ;DebugLog " "+Str(o)
  120.  
  121. Delete c
  122. c = First cell
  123. Wend
  124.  
  125. For o.oldCell = Each oldCell
  126.  
  127. bordersWhite = 0
  128.  
  129. For dy = -1 To 1
  130. For dx = -1 To 1
  131. If dx <> 0 Or dy <> 0
  132.  
  133. nx = o\x+dx
  134. ny = o\y+dy
  135.  
  136. If nx >= 0 And nx < w And ny >= 0 And ny < h
  137.  
  138. pixcol = ReadPixelFast(nx,ny,imgBuff)
  139.  
  140. If (pixcol = -1 And array(nx,ny) = 0) Or array(nx,ny) > o\dis+10
  141. bordersWhite = 1
  142. Exit
  143. EndIf
  144.  
  145. EndIf
  146.  
  147. EndIf
  148. Next
  149. If bordersWhite Exit
  150. Next
  151.  
  152. If bordersWhite
  153. ns.start = New start
  154. ns\x = o\x
  155. ns\y = o\y
  156. ns\dis = o\dis
  157.  
  158. s2.start = First start
  159. While s2\nex <> Null
  160. If ns\dis < s2\nex\dis
  161. Exit
  162. EndIf
  163. s2 = s2\nex
  164. Wend
  165. ns\nex = s2\nex
  166. s2\nex = ns
  167. ;Stop
  168. EndIf
  169.  
  170. Delete o
  171. Next
  172.  
  173. If changed > 20
  174. For j = 0 To h
  175. For i = 0 To w
  176. If KeyHit(1) End
  177.  
  178. dis2# = array(i,j)*360./maxDis
  179.  
  180. If array(i,j) <> 0
  181. colr = col(dis2,0,0)
  182. colg = col(dis2,0,1)
  183. colb = col(dis2,0,2)
  184. newcol = 1*( (colr*256*256) + (colg*256) + colb )
  185. WritePixelFast(i,j, newcol, imgBuff)
  186. EndIf
  187.  
  188. Next
  189. Next
  190.  
  191. UnlockBuffer(imgBuff)
  192. DrawImage image,0,0
  193. LockBuffer(imgBuff)
  194.  
  195. changed = 0
  196. EndIf
  197.  
  198. If KeyHit(1) End
  199.  
  200. s2 = s
  201. s = s\nex
  202. Delete s2
  203. Wend
  204.  
  205. For j = 0 To h
  206. For i = 0 To w
  207.  
  208. dis2# = array(i,j)*360./maxDis
  209.  
  210. If array(i,j) <> 0
  211. colr = col(dis2,0,0)
  212. colg = col(dis2,0,1)
  213. colb = col(dis2,0,2)
  214. newcol = 1*( (colr*256*256) + (colg*256) + colb )
  215. WritePixelFast(i,j, newcol, imgBuff)
  216. EndIf
  217.  
  218. Next
  219. Next
  220.  
  221. DebugLog "Done!"
  222.  
  223. UnlockBuffer(imgBuff)
  224. DrawImage image,0,0
  225.  
  226. WaitKey
  227. If KeyDown(28) SaveBuffer(FrontBuffer(), "HueEverywhere_example8.2.png")
  228. End
  229.  
  230. Function col(ang1#, ang2#, kind)
  231.  
  232. While ang1 > 360
  233. ang1 = ang1 - 360
  234. Wend
  235. While ang1 < 0
  236. ang1 = ang1 + 360
  237. Wend
  238.  
  239. While ang2 > 180
  240. ang2 = ang2 - 360
  241. Wend
  242. While ang2 < -180
  243. ang2 = ang2 + 360
  244. Wend
  245.  
  246. a3# = ang2/180.
  247.  
  248. ; DebugLog kind
  249.  
  250. If ang1 > 300
  251. diff# = (ang1-300)/60.
  252. r = 255
  253. g = 0
  254. b = 255*(1-diff)
  255. ElseIf ang1 > 240
  256. diff# = (ang1-240)/60.
  257. r = 255*diff
  258. g = 0
  259. b = 255
  260. ElseIf ang1 > 180
  261. diff# = (ang1-180)/60.
  262. r = 0
  263. g = 255*(1-diff)
  264. b = 255
  265. ElseIf ang1 > 120
  266. diff# = (ang1-120)/60.
  267. r = 0
  268. g = 255
  269. b = 255*diff
  270. ElseIf ang1 > 60
  271. diff# = (ang1-60)/60.
  272. r = 255*(1-diff)
  273. g = 255
  274. b = 0
  275. Else
  276. diff# = (ang1-00)/60.
  277. r = 255
  278. g = 255*diff
  279. b = 0
  280. EndIf
  281.  
  282. If a3 > 0
  283. r2 = r + a3*(255-r)
  284. g2 = g + a3*(255-g)
  285. b2 = b + a3*(255-b)
  286. Else
  287. r2 = r + a3*r
  288. g2 = g + a3*g
  289. b2 = b + a3*b
  290. EndIf
  291.  
  292. ; DebugLog "First: " + r2 + ":" + g2 + ":" + b2
  293.  
  294. If r2 > 255
  295. r2 = 255
  296. ElseIf r2 < 0
  297. r2 = 0
  298. EndIf
  299.  
  300. If g2 > 255
  301. g2 = 255
  302. ElseIf g2 < 0
  303. g2 = 0
  304. EndIf
  305.  
  306. If b2 > 255
  307. b2 = 255
  308. ElseIf b2 < 0
  309. b2 = 0
  310. EndIf
  311.  
  312. ; DebugLog "Second: " + r2 + ":" + g2 + ":" + b2
  313.  
  314. If kind = 0
  315. Return r2
  316. ElseIf kind = 1
  317. Return g2
  318. ElseIf kind = 2
  319. Return b2
  320. Else
  321. Return 0
  322. EndIf
  323.  
  324. If KeyHit(1) End
  325.  
  326. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement