REM Plotting 3d worm hole
REM iPhone 6 plus / 8.3 b1
REM its slow, any thoughts?
REM enjoy
'graphics screen
graphics
'math
pi=3.1415
'Set the center of the screen..
cntx = Screen_Width()
cnty = Screen_Height()
'Set are camera lens..
LENS = 256
'Start timer for frames per second
T = TIMER
'Main LOOP
loop:
refresh off
r = 40 ' Radius of worm hole 40
z = z + 1 'Z cord of worm hole
Rang = ang * PI/180 'Degrees to Radians
x = r * COS(Rang) 'Polar to Cartesain X
y = r * SIN(Rang) 'Polar to Cartesain Y
Dist = LENZ - z ' Find distance
IF z > 256 THEN ' Check for max Z,..
z = 0 'If true, reduce back to 0
END IF 'End code block
IF z > 0 AND z < 256 THEN 'Make sure z is still on screen
nx = cntx + (LENS * x) / Dist 'Find new X
ny = cnty - (LENS * y) / Dist 'Find new Y
ELSE 'So we don't divide by 0
END IF 'End code block
draw COLOR 0, 0, z/255 'Place blue pixel
draw PIXEL nx, ny
draw COLOR 0, z/255, 0 'Place green pixel
draw PIXEL nx + 1, ny - 1
ang = (ang + 1)%360 'Add angle, MOD keeps it from going over 360
F = F + 1 'Frame counter
refresh on
GOTO loop ' end LOOP
PRINT "Average FPS:"; F / (TIMER - T)' Frames per second equation.
pause 1 'Wait until screen is pressed..
Plotting a wormhole
-
- Posts: 167
- Joined: Wed Oct 22, 2014 3:26 pm
- My devices: iPhone 4 to 6+,iPad mini to iPad air 2
Plotting a wormhole
- Attachments
-
- image.jpg (397.61 KiB) Viewed 1652 times
-
- image.jpg (387.38 KiB) Viewed 1652 times
-
- image.jpg (322.71 KiB) Viewed 1652 times
-
- image.jpg (271.42 KiB) Viewed 1652 times
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Plotting a wormhole
It's a bit faster now, by refreshing the screen less frequent
Code: Select all
graphics ! refresh off ! option angle degrees
pi=3.14529 ! lens=256
cntx = Screen_Width() ! cnty = Screen_Height()
loop:
r = 40 ! z = z + 1
x = r * COS(ang) ! y = r * SIN(ang)
Dist = LENS - z
IF z > 256 THEN ! z = 0 ! refresh ! end if
IF z > 0 AND z < 256 THEN
nx = cntx + (LENS * x) / Dist
ny = cnty - (LENS * y) / Dist
END IF
draw COLOR 0,0,z/255 ! draw PIXEL nx, ny
draw COLOR 0,z/255,0 ! draw PIXEL nx + 1, ny - 1
ang = (ang + 1)%360
GOTO loop
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Plotting a wormhole
DRAW PIXEL works with physical pixels, not with points. So this program will run differently on retina and non-retina screens because SCREEN_SCALE() is not respected here.