Skip to main content

Ruby-Processing 3939 Responses

Last post: 2 years, 2 months ago | Thread started: Mar 20, 10, 5:12 p.m.

RespondNew TopicDisable Images

Out of context: Response #1 [Mar 20, 10, 5:12 p.m.]

  • stewdio

    QBN is going to destroy the pretty code indentation here, but the program will still work. Getting a spinning red cube is just another three steps away :

    1. Copy and paste the code into a new *plain* text document and save it as "MyCubes.rb"

    2. Open Terminal to the folder where your MyCubes.rb is located.

    3. Paste this into Terminal and hit enter :
    rp5 run MyCubes.rb

    That's it. You should see a red cube spinning in black space. When you're done being mesmerized hit Command+Q to quit. Here's the code for it :

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    class MyCubes < Processing::App
    load_library :opengl

    def setup

    size 640, 360, OPENGL
    frame_rate 30

    @x_degree = 45
    @y_degree = 0
    no_stroke

    end

    def draw
    background 0
    lights
    push_matrix

    translate width / 2, height / 2, 0
    rotate_x radians( @x_degree )
    rotate_y radians( @y_degree )

    fill 255, 0, 0, 240
    box 100

    pop_matrix
    @x_degree = ( @x_degree + 1 ).modulo 360
    @y_degree = ( @y_degree + 2 ).modulo 360
    end

    end
    MyCubes.new :title => "My Cubes!"

    • Thanks!lukus_W1/3
      Thanks for the ShellHere tip as well. Handy little app.ctcliff2/3
      you could always just post the code on pastie.org or gist....(github)sublocked3/3
    next note >+ add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel

Skip to main content