RosettaCodeData/Task/Draw-a-rotating-cube/Amazing-Hopper/draw-a-rotating-cube.hopper
2023-07-01 13:44:08 -04:00

71 lines
2 KiB
Text

#context-free Draw a cube
Loop for (i=1, #(i<=3), ++i)
Draw a line (size_2, {size_2} Minus(scale_zoff), [i] Get 'x',\
{size_2} Minus(scale x zoff) )
Draw a line (size_2, {size_2} Plus(scale_zoff), [{7}Minus(i)] Get 'x' ,\
{size_2} Plus(scale x zoff) )
Draw a line ([i] Get 'x', {size_2} Minus(scale x zoff),\
[Minusone(i) Module(3) Plus(4)] Get 'x', {size_2} Plus(scale x zoff) )
Draw a line ([i] Get 'x', {size_2} Minus(scale x zoff), \
[{i} Module(3) Plus(4)] Get 'x', {size_2} Plus(scale x zoff) )
Next
Return\\
#context-free Delete old cube
Color back '0', Draw a cube
Return\\
#context-free Setting values of program
Set( Div(M_PI,6), Mul(5,Div(M_PI,6)), Mul(3,M_PI_2), Mul(11,Div(M_PI,6)),\
M_PI_2, Mul(7,Div(M_PI,6)) )
Append to list 'cylphi'
/* pre-cálculos */
Let ( dt := Div(1,30 ))
Let (size_2 := Div( SIZE, 2))
Let (scale_zoff := Div( SCALE,zoff))
Let (scale x zoff := Mul (SCALE, zoff))
Return \\
#include <jambo.h>
/*
Execute with:
$ rxvt -g 250x250 -fn "xft:FantasqueSansMono-Regular:pixelsize=1" -e hopper jm/cubo.jambo
*/
#define SCALE 50
#define SIZE 200
#define zoff 0.5773502691896257645091487805019574556
#define cylr 1.6329931618554520654648560498039275946
Main
Set break
theta=0, dtheta=1.5, lasttime=0, dt=0 , timer=0
size_2=0, scale_zoff=0, scale x zoff=0, cylphi = {}
Dim (6) as zeros (x)
Setting values of program
Cls
/* Draw a cube */
Loop while ( Not (Keypressed))
Tic(lasttime)
Loop for( i=1, #(i<=6), ++i )
Add( size_2, Mul( Mul(SCALE,cylr), Cos( [i] Get 'cylphi' Plus 'theta')) )
Put 'x'
Next
Color back '15', Draw a cube
Loop
Timecpu(timer)
While ( This 'timer' Compared to 'Add(lasttime, dt)' Is less )
Let ( theta := Add( theta, Mul( dtheta, Sub(timer, lasttime))))
Sleep (0.01)
Delete old cube
Back
End
Subrutines