Author Topic: Another Wire Frame  (Read 421 times)

0 Members and 1 Guest are viewing this topic.

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 325
  • Karma: 26
  • Hard players don't go home.
    • View Profile
Another Wire Frame
« on: June 17, 2026 »
An Icosahedron this time.

The code includes putting the
points into data.
Which didn't work out.

Code: [Select]
restore edges
read tips
dim s(tips)
dim e(tips)

for a=1 to tips
read s(a)
read e(a)
next a

point=10
dim r(point)
dim x(point)
dim y(point)
dim l(point)
dim d(point)
dim s(point)
dim m(point)
rad=pi/180
ang=360/(point/2)

for a=1 to point
l(a)=400
s(a)=3
m(a)=.005
next a

for a=1 to 5
r(a)=a*ang*rad
d(a)=-0.35
next a

for a=6 to 10
r(a)=(a+0.5)*ang*rad
d(a)=0.35
next a

x=320
y=256

open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window

text 250,12,"ICOSAHEDRON"
text 250,24,"  12 points"
text 250,36,"20 triangles"
text 250,48,"  40 lines"

for a=1 to point
x(a)=cos(r(a))/(sin(r(a))+s(a))*l(a)+x
y(a)=d(a)/(sin(r(a))+s(a))*l(a)+y
next a

for a=1 to point
r(a)=r(a)+m(a)
if m(a)>360 m(a)=0
next a

for a=1 to 5
line x,y-120 to x(a),y(a)
next a

for a=6 to 10
line x,y+120 to x(a),y(a)
next a

line x(1),y(1) to x(2),y(2)
line x(2),y(2) to x(3),y(3)
line x(3),y(3) to x(4),y(4)
line x(4),y(4) to x(5),y(5)
line x(5),y(5) to x(1),y(1)

line x(1),y(1) to x(6),y(6)
line x(2),y(2) to x(6),y(6)
line x(2),y(2) to x(7),y(7)
line x(3),y(3) to x(7),y(7)
line x(3),y(3) to x(8),y(8)
line x(4),y(4) to x(8),y(8)
line x(4),y(4) to x(9),y(9)
line x(5),y(5) to x(9),y(9)
line x(5),y(5) to x(10),y(10)
line x(1),y(1) to x(10),y(10)

line x(6),y(6) to x(7),y(7)
line x(7),y(7) to x(8),y(8)
line x(8),y(8) to x(9),y(9)
line x(9),y(9) to x(10),y(10)
line x(10),y(10) to x(6),y(6)

for a=1 to point
'text x(a),y(a),str$(a)
next a

for a=1 to tips
'line x(s(a)),y(s(a)) to x(e(a)),y(e(a))
next a

until (1=0)

label edges
data 20
data 1,2
data 2,3
data 3,4
data 4,5
data 5,1

data 1,6
data 2,6
data 2,7
data 3,7
data 3,8
data 4,8
data 4,9
data 5,9
data 5,10
data 1,10

data 6,7
data 7,8
data 8,9
data 9,10
data 10,6

Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17426
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: Another Wire Frame
« Reply #1 on: August 02, 2026 »
Again, I like this, it's a neat illusion and this is useful a technique which is used on 8 bit machines to generate surprisingly convincing 3d rotating objects using some sin/cos instead of expensive rotation calculations.

If you;

1:store the 12  vertices as x,y,z co-ordinates
2:Rotate them around X,Y,Z using rotation matrices
3:Project the 3D points into 2D co-ordinates
4:Draw the edges

Then you can see you're not too far away.

Again, this may not have been your intention for this code but it's where my mind led me when I ran your effect;

Code: [Select]
restore edges
read edges
dim e1(edges)
dim e2(edges)

for a=1 to edges
read e1(a)
read e2(a)
next a


' 12 vertices of an icosahedron
phi=(1+sqrt(5))/2
scale=80

dim vx(12)
dim vy(12)
dim vz(12)

' two rings plus poles
vx(1)=0
vy(1)=scale
vz(1)=0

vx(12)=0
vy(12)=-scale
vz(12)=0

for a=0 to 4
ang=a*72*pi/180
vx(a+2)=cos(ang)*scale
vy(a+2)=scale*0.4
vz(a+2)=sin(ang)*scale
next a

for a=0 to 4
ang=(a*72+36)*pi/180
vx(a+7)=cos(ang)*scale
vy(a+7)=-scale*0.4
vz(a+7)=sin(ang)*scale
next a


dim sx(12)
dim sy(12)

ax=0
ay=0
az=0

open window 640,512

repeat

setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window


' rotate and project
for a=1 to 12

x=vx(a)
y=vy(a)
z=vz(a)


' rotate X
ty=y*cos(ax)-z*sin(ax)
tz=y*sin(ax)+z*cos(ax)
y=ty
z=tz


' rotate Y
tx=x*cos(ay)+z*sin(ay)
tz=-x*sin(ay)+z*cos(ay)
x=tx
z=tz


' rotate Z
tx=x*cos(az)-y*sin(az)
ty=x*sin(az)+y*cos(az)
x=tx
y=ty


' perspective projection
dist=300

sx(a)=320+x*dist/(z+dist)
sy(a)=256-y*dist/(z+dist)

next a


' draw edges
for a=1 to edges
line sx(e1(a)),sy(e1(a)) to sx(e2(a)),sy(e2(a))
next a


ax=ax+0.01
ay=ay+0.015
az=az+0.02

until (1=0)



label edges

data 30

data 1,2
data 1,3
data 1,4
data 1,5
data 1,6

data 12,7
data 12,8
data 12,9
data 12,10
data 12,11

data 2,3
data 3,4
data 4,5
data 5,6
data 6,2

data 7,8
data 8,9
data 9,10
data 10,11
data 11,7

data 2,7
data 2,11
data 3,7
data 3,8
data 4,8
data 4,9
data 5,9
data 5,10
data 6,10
data 6,11
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17426
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: Another Wire Frame
« Reply #2 on: August 02, 2026 »
There are other optimisations you can do here - You'll see them in many of the PS2 Yabasic demos where there are 3D rotations that some of the calculations can be precalculated outside the loop which was more important when running stuff on the actual PS2 console... The emulator is much faster though so it's not such a big deal unless you want to run it natively at some point.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 325
  • Karma: 26
  • Hard players don't go home.
    • View Profile
Re: Another Wire Frame
« Reply #3 on: August 03, 2026 »
I've seen many variations coding 3D including the cube on the PS2 demo disc.
It was beyond my comprehension and still is since I barely managed one axis.
But I had easy access to coding which was beyond my budget before.
I developed a lot faster when the emulator came along and then joined this site. So helpful.
My best work is on this site, but I have hundreds of small operational programs.
And some not so small like the search program for my 4500 dvd collection.
What a journey thanks to everyone here.
And Jim when I got him to transfer my PS2 memory cards to PC.
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.