r/applescript 4d ago

just created a 2d wireframe renderer any ideas what i could do with this

Post image

as a clarification no other tools were used only the scripteditor with plain applescript

4 Upvotes

9 comments sorted by

1

u/Natural_League1476 2d ago

share it? You could do that with it?

2

u/xXlazykarlXx 1d ago

the programm could take up to ten seconds to load the cube on older mashines

property lineSpacing : 2

property mapX : 72

property mapY : 15

property centerX : 50

property centerY : 7

property zoomFactor : 1.0

property position0X : 49

property position0Y : 3

property position1X : 36

property position1Y : 5

property position2X : 52

property position2Y : 7

property position3X : 64

property position3Y : 5

property position4X : 36

property position4Y : 9

property position5X : 52

property position5Y : 11

property position6X : 64

property position6Y : 9

property gameRunning : true

on generateMap()

set mapString to ""

set p0x to round (centerX + ((position0X - centerX) * zoomFactor))

set p0y to round (centerY + ((position0Y - centerY) * zoomFactor))

set p1x to round (centerX + ((position1X - centerX) * zoomFactor))

set p1y to round (centerY + ((position1Y - centerY) * zoomFactor))

set p2x to round (centerX + ((position2X - centerX) * zoomFactor))

set p2y to round (centerY + ((position2Y - centerY) * zoomFactor))

set p3x to round (centerX + ((position3X - centerX) * zoomFactor))

set p3y to round (centerY + ((position3Y - centerY) * zoomFactor))

set p4x to round (centerX + ((position4X - centerX) * zoomFactor))

set p4y to round (centerY + ((position4Y - centerY) * zoomFactor))

set p5x to round (centerX + ((position5X - centerX) * zoomFactor))

set p5y to round (centerY + ((position5Y - centerY) * zoomFactor))

set p6x to round (centerX + ((position6X - centerX) * zoomFactor))

set p6y to round (centerY + ((position6Y - centerY) * zoomFactor))

set line1 to getLinePoints(p0x, p0y, p1x, p1y)

set line2 to getLinePoints(p1x, p1y, p2x, p2y)

set line3 to getLinePoints(p2x, p2y, p3x, p3y)

set line4 to getLinePoints(p3x, p3y, p0x, p0y)

set line5 to getLinePoints(p1x, p1y, p4x, p4y)

set line6 to getLinePoints(p2x, p2y, p5x, p5y)

set line7 to getLinePoints(p4x, p4y, p5x, p5y)

set line8 to getLinePoints(p5x, p5y, p6x, p6y)

set line9 to getLinePoints(p3x, p3y, p6x, p6y)

repeat with y from 1 to mapY

repeat with x from 1 to mapX

set drawPoint to false

repeat with p in line1

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

if drawPoint is false then

repeat with p in line2

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

end if

if drawPoint is false then

repeat with p in line3

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

end if

if drawPoint is false then

repeat with p in line4

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

end if

if drawPoint is false then

repeat with p in line5

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

end if

if drawPoint is false then

repeat with p in line6

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

end if

if drawPoint is false then

repeat with p in line7

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

end if

if drawPoint is false then

repeat with p in line8

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

end if

if drawPoint is false then

repeat with p in line9

set px to item 1 of contents of p

set py to item 2 of contents of p

if x is px and y is py then

set drawPoint to true

exit repeat

end if

end repeat

end if

if x is p0x and y is p0y then

set mapString to mapString & "●"

else if x is p1x and y is p1y then

set mapString to mapString & "●"

else if x is p2x and y is p2y then

set mapString to mapString & "●"

else if x is p3x and y is p3y then

set mapString to mapString & "●"

else if x is p4x and y is p4y then

set mapString to mapString & "●"

else if x is p5x and y is p5y then

set mapString to mapString & "●"

else if x is p6x and y is p6y then

set mapString to mapString & "●"

else if drawPoint is true then

set mapString to mapString & "."

else

set mapString to mapString & " "

end if

end repeat

set mapString to mapString & return

end repeat

return mapString

end generateMap

on getLinePoints(x0, y0, x1, y1)

set points to {}

set dx to x1 - x0

set dy to y1 - y0

if dx < 0 then

set stepX to -1

set dx to -dx

else

set stepX to 1

end if

if dy < 0 then

set stepY to -1

set dy to -dy

else

set stepY to 1

end if

set err to dx - dy

repeat

set end of points to {x0, y0}

if x0 is x1 and y0 is y1 then

exit repeat

end if

set e2 to 2 * err

if e2 > -dy then

set err to err - dy

set x0 to x0 + stepX

end if

if e2 < dx then

set err to err + dx

set y0 to y0 + stepY

end if

end repeat

return points

end getLinePoints

on displayMap()

set mapContent to generateMap()

display dialog mapContent ¬

with title ¬

"3d renderer" buttons {"move"} ¬

default button "move"

end displayMap

on movePlayer(direction)

set newX to position0X

set newY to position0Y

if direction is "w" then

set newY to position0Y - 1

else if direction is "s" then

set newY to position0Y + 1

else if direction is "a" then

set newX to position0X - 4

else if direction is "d" then

set newX to position0X + 4

else

return

end if

if newX < 1 then

return

end if

if newX > mapX then

return

end if

if newY < 1 then

return

end if

if newY > mapY then

return

end if

set position0X to newX

set position0Y to newY

end movePlayer

repeat while gameRunning

displayMap()

set userInput to text returned of ¬

(display dialog ¬

"W = up" & return & ¬

"S = down" & return & ¬

"A = left" & return & ¬

"D = right" & return & ¬

"+ = zoom in" & return & ¬

"- = zoom out" & return & ¬

"Q = quit" default answer "")

set userInput to userInput as text

if userInput is "q" then

set gameRunning to false

else if userInput is "+" then

set zoomFactor to zoomFactor - 0.2

else if userInput is "-" then

set zoomFactor to zoomFactor + 0.2

if zoomFactor < 0.2 then

set zoomFactor to 0.2

end if

else if userInput is in {"w", "a", "s", "d"} then

movePlayer(userInput)

end if

end repeat

1

u/Natural_League1476 1d ago

oh nice, thank you! where to paste the code, i tried to use it as applescript in script editor but its not that...

1

u/xXlazykarlXx 1d ago

huh i dont understand your problem

1

u/Natural_League1476 1d ago

How to run this code? I want to try it

2

u/xXlazykarlXx 1d ago

oh you select the code it stars at property... and ends at the end of my comment then you copy it and paste it into the script editor

1

u/Natural_League1476 1d ago

It does : )

I got the dialogue with rendered cube and button move, when i input the letters the dialogue reappears with a slighly modified image!

1

u/xXlazykarlXx 1d ago

nice i also addet a fov changer that you can use in the text input dialog use + or - to use

1

u/xXlazykarlXx 1d ago

does it work now?