Author Topic: Rubic's Cube Code Challenge  (Read 3320 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Rubic's Cube Code Challenge
« on: June 01, 2018, 10:57:00 PM »
Online Rubic's Cube Simulator

The direction I would like to see happen with this challenge is use the JavaScript version as a guide to rework the O2 Pine Cone GL example. I personally don't have the skills level with graphics programming to do the merge. I'm just the facilitator in this effort.

If this materializes, I suggest we call it RobbeK's Cube as a tribute




Code: Text
  1.   #compact
  2.   % Title "PineCone"
  3.   % Animated
  4.   % ScaleUp
  5.  '% PlaceCentral
  6.  '% AnchorCentral
  7.  '% NoEscape
  8.   % ColorCodedPick
  9.   % MultiSamples 4
  10.  
  11.   includepath "$\inc\"
  12.   include "ConsoleG.inc"
  13.  
  14.  
  15.   function makelist() as sys
  16.   ==========================
  17.  
  18.   type coor float x,y,z
  19.  
  20.   static coor z
  21.   static float golden_angle = 137.508  
  22.   static float golden       = golden_angle*Pi/180
  23.                                      
  24.   macro floret(n, r,ang,xc,yc) 'inner procedure
  25.   ----------------------------
  26.   float r , ang , xc , yc
  27.   r =(5.3 * Sqr(n*golden))
  28.   ang = (n*golden)
  29.   xc = r*Cos(ang)/100
  30.   yc = r*Sin(ang)/100
  31.   z.x=xc : z.y=yc
  32.   end macro    
  33.  
  34.   sys i
  35.   static sys seeds
  36.   seeds=CompileList seeds
  37.   for i=1 to 140
  38.     floret(i)
  39.     glPushMatrix
  40.     glTranslatef z.x , z.y , i/100
  41.     scale 0.11+i/900
  42.     go sphere
  43.     glPopMatrix  
  44.   next  
  45.   for i=144 To 1 step -1
  46.     floret(i)  
  47.     glPushMatrix
  48.     glTranslatef -z.x , -z.y , 2.2-i/200
  49.     Scale  0.11+i/1000
  50.     go sphere
  51.     glPopMatrix  
  52.   next
  53.   glEndList
  54.   return seeds
  55.   end function
  56.  
  57.  
  58.  function main()
  59.   ===============
  60.   sys i,p
  61.   string s
  62.   float  a
  63.   cls 0,0.1,0.2
  64.   '
  65.   shading
  66.   '
  67.   pushstate
  68.   move 15,-15,-20
  69.   static MoveableObject seeds
  70.   static sys            seedform
  71.   static sys            idf
  72.   if not idf
  73.     idf=100  
  74.     seeds.snap=.5
  75.     seeds.id=idf
  76.     seeds.mode=0x100 'keyboard & mouse (left button rotate)
  77.     SeedForm=MakeList()
  78.   end if
  79.   picked=idf 'always selected
  80.   seeds.act
  81.   scale 10
  82.   move 0,0,-1
  83.  'static float ay
  84.  'rotateY ay : ay+=.2
  85.   if not pick then
  86.     SilverMaterial.act
  87.   end if
  88.   go SeedForm
  89.   'go cylinder
  90.   popstate
  91.   '
  92.   'F1 HELP
  93.   '
  94.   if key[0x70]
  95.     flat
  96.     pushstate
  97.     move 20,0
  98.     color .9,.9,.9
  99.     scale  1.5,1.0
  100.     printl "Active Keys:"
  101.     printl
  102.     scale  1/1.5,1.0
  103.     printl "Esc"    tab "Exit"
  104.     printl "Ctrl-P" tab "Take snapshot"
  105.     printl "F1 This help panel"
  106.     printl "Arrow keys PgUp PgDn to move"
  107.     printl "Ctrl Arrow keys PgUp PgDn to rotate"
  108.     printl "+ - keys to scale up and scale down"
  109.     printl "Ctrl Home to reset rotation"
  110.     printl "Shift for faster movement"
  111.     printl
  112.     scale 1.5,1.0
  113.     printl "Mouse:"
  114.     printl             
  115.     scale 1/1.5,1.0
  116.     printl "Point to Object, then"
  117.     printl "Left button to move"
  118.     printl "Middle button to scale"
  119.     printl "Right button to rotate"
  120.     printl "Wheel to move in Z direction"
  121.     popstate
  122.   end if
  123.   picklabel 0
  124.   lastkey=0
  125.   lastchar=0
  126.   end function
  127.  
  128.   EndScript
  129.  

Attached is Mike's 32 bit version of RobbeK's contribution. (.exe)
« Last Edit: June 02, 2018, 02:20:14 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Rubic's Cube Code Challenge
« Reply #1 on: June 17, 2018, 09:25:43 PM »