Code Monkey home page Code Monkey logo

graphics's Introduction

graphics

home

github.com/seattlerb/graphics

rdoc

docs.seattlerb.org/graphics

DESCRIPTION:

Graphics provides a simple framework to implement games and/or simulations and is designed to follow mathematical conventions, NOT game programming conventions. Particularly it:

  • Uses degrees.

  • Draws in quadrant 1 (0-90 degrees).

  • Right hand rule: 0 degrees is east, 90 is north, etc.

These allow simple things like Trigonometry functions to work as expected. It means that all that stuff you were taught in grade school still work as intended. This makes one less thing you have to adjust when implementing your simulation.

FEATURES/PROBLEMS:

  • REAL MATHS!

  • Simple drawing primitives.

  • PRETTY drawing primitives! Nearly everything is anti-aliased.

  • Plenty of helpers to make your code clean

SYNOPSIS:

class Ball < Graphics::Body
  def initialize w
    super

    # ...
  end

  def draw
    w.angle x, y, a, 10+3*m, :red
    w.circle x, y, 5, :white, :filled
  end

  def update
    fall
    move
    bounce
  end

  # ...
end

class BounceSimulation < Graphics::Simulation
  attr_accessor :bs

  def initialize
    super 640, 640, 16, "Bounce"

    self.bs = populate Ball
  end

  def update n
    bs.each(&:update)
  end

  def draw n
    clear
    bs.each(&:draw)
    fps n
  end

  # ...
end

BounceSimulation.new.run

See examples/*.rb for more

REQUIREMENTS:

  • libsdl2 & friends

See and/or run graphics_setup.sh. If you’re on OSX and have homebrew installed, running this will ensure you have a working setup.

You may want to run ‘brew update` beforehand to ensure you get up-to-date versions.

INSTALL:

LICENSE:

(The MIT License)

Copyright © Ryan Davis, seattle.rb

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

graphics's People

Contributors

zenspider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

graphics's Issues

'graphics' not simply downloadable via rubygems ?

Hello

There is something strange with this gem :

jcll-mac:~ jcll$ gem install graphics
ERROR: Could not find a valid gem 'graphics' (>= 0) in any repository
ERROR: Possible alternatives: graphify, graphist, graphit, graphite, graphes

However we clearly see 'graphics' listed in rubygems.org (1.0.0b6 2016).

JCLL

I don't like the color system

Painting a single color by name is fine... but I want the overall color system to be more intelligent.

Something like providing a knob that you simply turn and get an appropriate color out of it. I don't entirely know what that looks like yet, but it needs to be cleaner than the current system.

List of examples + common things I do + a few other interesting things

Common things I do

  • 31 px to deal with the colour thing: super 800, 600, 31

  • default proc on colour: color.default_proc = lambda { |h, c| c }

  • Give a line girth by drawing multiple copies of it.

    line xpx(x), ypx(y+1),   xpx(x+1), ypx(y+1),   :white
    line xpx(x), ypx(y+1)+1, xpx(x+1), ypx(y+1)+1, :white
    line xpx(x), ypx(y+1)+2, xpx(x+1), ypx(y+1)+2, :white
  • Slow it down by skipping draw cycles (eg) (probably dumb, I think you have an fps method)

  • Looks like I override event handling in several of them 1, 2, but none of them look the way I was expecting. So maybe I only did "good enough for my use case" kind of overriding instead of making something more lib-like.

Other interesting things

  • Check whether text displays newlines correctly, I think I had to do .lines and calculate offsets b/c it wasn't putting the newlines in.
  • For text: left vs right vs center justify
  • Delaying drawing by keeping an array of things that need to happen on upcoming frames (stored in lambdas). eg
  • Doing math on a "wrap around" canvas was pretty rough, IIRC https://vimeo.com/205930710 though that probably isn't Graphics' job.

Examples

Performance Regression

Okay, watch like 10 seconds of this video. The code for that is here.

When I try it with the graphics built from c46b846, it is very very slow, which I think causes other issues, in turn. Eg I think that causes it to miss events, so it doesn't put the window in the foreground, and doesn't quit when I press the red circle or the q key.

I believe it has to do with the number of lines being drawn, eg if you comment out line x1, y1, x2, y2, color from #draw_lines_between, everything is fine.


A few changes I made so it would work correctly with the new version:

  • Remove the third argument to super
  • Swap the method screen to renderer
  • Delete the unused @num_lines
  • Run it with ruby instead of rsdl

How best to compose sprites?

Playing around with sprites to see how they compose. blit attaches them at the center point of the sprite. It took quite a bit of effort to figure that out and then figure out how to put the sprite in the right spot, given that information. I didn't understand how to do it until I drew a lot more lines on the screen so I could see why things were moving the way they were:

https://gist.github.com/JoshCheek/505d6722e80786461d04cbe8ede3c290#file-1_attach_at_bottom_mid-rb-L225-L230
composing_sprites_1


Since the trees were going in a single direction, I felt like their branches should be billowing in the wind, so I reworked the them to do that. This caused them to be entirely contained in the bottom right quadrant of their sprite. With some versions, they would occasionally go beneath the ground, out of the sprite's viewport. I'm not sure how to get things out of the viewport to be visible other than to make the sprite larger and move the starting point inward. But if I move the starting point, eg if I remove the 3 irrelevant quadrants and have the tree's trunk grow from the bottom left, then I also have to edit the code that determines where the sprite attaches, which is rather unappealing. https://gist.github.com/JoshCheek/505d6722e80786461d04cbe8ede3c290#file-2_attach_at_bottom_left-rb

composing_sprites_2


Not sure if I don't understand how to compose sprites, or if this is just not how sprites were meant to be used (eg this is probably where the Graphics::Body is most useful). Just figured I'd ask if others have a good approach to composition and how they deal with the need to attach at different points without a lot of code churn.

Alpha is always opaque

Per suggestion I'm moving this comment to a new issue :P Note that this diff was applied locally.

  R = ((dc & Rmask) + (( (color & Rmask) - (dc & Rmask) ) * alpha >> 8)) & Rmask;
  G = ((dc & Gmask) + (( (color & Gmask) - (dc & Gmask) ) * alpha >> 8)) & Gmask;
- B = ((dc & Bmask) + (( (color & Bmask) - (dc & Bmask) ) * alpha >> 8)) & Bmask;
+ // need to do different shifting here to avoid overflow
+ B = ((dc & Bmask) + ((((color & Bmask) - (dc & Bmask)) >> 8) * alpha)) & Bmask;

Alpha is still not responding (it's always fully opaque). Note that it's not responding on rect or point, eitiher. Alpha also doesn't work on 24 bpp, though there is code in there to support it. Alpha is handled differently from all the other channels, it gets passed in as its own arg. I assume it works in general, because I assume anti aliasing uses it, but I couldn't think of an example that would make it obvious. The one below shows that it is always opaque.

screenshot 2016-11-29 16 50 41

require "graphics"

side    = 100
alphas  = [0, 0.5, 1, 128, 255]
drawing = Graphics::Drawing.new alphas.length*1.5*side+side/2, side*2, 32
drawing.color.default_proc = -> h, k { k }

alphas.each_with_index do |alpha, i|
  color = drawing.screen.format.map_rgba(255, 255, 255, alpha)
  drawing.rect i*1.5*side+side/2, side/2, side, side, color, true
  drawing.text alpha.to_s, i*1.5*side+side/2, 1.5*side, :white
end

drawing.run

Necessary setup for Ubuntu

I don't know if you'd want to add this to the README or whatever, but I thought someone might find this useful.

To get the current version (1.0.0b5) to install on Ubuntu 15.10 (Wily Werewolf), I had to install the following packages:

# apt-get install libsdl-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev

hline and vline have each other's defaults for the endpoints

hline and vline have each other's defaults for the endpoints (here and here)

It passes the tests because FakeSimulation's width and height are the same (here).

require 'graphics'

d1 = Graphics::Drawing.new 400, 300, 0, 'wider than tall'
d1.vline d1.w/2, :red
d1.hline d1.h/2, :white
d1.run

d2 = Graphics::Drawing.new 300, 400, 0, 'taller than wide'
d2.vline d2.w/2, :red
d2.hline d2.h/2, :white
d2.run

image

image

Sammyghold Graphics Design and logo

<script type="text/javascript">(window.NREUM||(NREUM={})).init={ajax:{deny_list:["bam.nr-data.net"]}};(window.NREUM||(NREUM={})).loader_config={licenseKey:"b76de0635f",applicationID:"487378958"};window.NREUM||(NREUM={}),__nr_require=function(t,e,n){function r(n){if(!e[n]){var i=e[n]={exports:{}};t[n][0].call(i.exports,function(e){var i=t[n][1][e];return r(i||e)},i,i.exports)}return e[n].exports}if("function"==typeof __nr_require)return __nr_require;for(var i=0;i0){var r=n[n.length-1];if(u&&uv.offset&&e<=Date.now()?(e-=v.offset,n.fid=v.now()-e):e=v.now(),w=!0,l("timing",["fi",e,n])}}function f(t){"hidden"===t&&(u=v.now(),l("pageHide",[u]))}if(!("init"in NREUM&&"page_view_timing"in NREUM.init&&"enabled"in NREUM.init.page_view_timing&&NREUM.init.page_view_timing.enabled===!1)){var u,s,d,p,l=t("handle"),v=t("loader"),m=t(8),g=t(3),y=NREUM.o.EV;if("PerformanceObserver"in window&&"function"==typeof window.PerformanceObserver){s=new PerformanceObserver(r);try{s.observe({entryTypes:["paint"]})}catch(h){}d=new PerformanceObserver(i);try{d.observe({entryTypes:["largest-contentful-paint"]})}catch(h){}p=new PerformanceObserver(o);try{p.observe({type:"layout-shift",buffered:!0})}catch(h){}}if("addEventListener"in document){var w=!1,b=["click","keydown","mousedown","pointerdown","touchstart"];b.forEach(function(t){document.addEventListener(t,c,g(!1))})}m(f)}},{}],7:[function(t,e,n){function r(t,e){if(!i)return!1;if(t!==i)return!1;if(!e)return!0;if(!o)return!1;for(var n=o.split("."),r=e.split("."),a=0;a <title>Sign In to KOL</title> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-KNWNSBS'); </script> <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KNWNSBS" height="0" width="0" style="display:none;visibility:hidden"></iframe>
Jumia KOL

Sign In to KOL

Enter your details below

Email
Password
SIGN IN
    <div class="form-control z-0 w-full text-sm text-center">
        <a href="https://kol.jumia.com/password/email">Forgot your password?</a>
    </div>
</form>
        </div>
        <div class="text-sm text-center">
                <span>Don&#039;t have an account?</span>
<a href="https://kol.jumia.com/register">Sign Up now!</a>
        </div>
    </div>
</div>
<script src="/assets/js/login.js?id=435f345c52fac8a8d6be"></script>
<script src="https://www.google.com/recaptcha/api.js"></script> <script type="text/javascript">window.NREUM||(NREUM={});NREUM.info={"beacon":"bam.nr-data.net","licenseKey":"b76de0635f","applicationID":"487378958","transactionName":"NVxXYhMHChFYVUELDQwWdFUVDwsMFlpaBQsM","queueTime":0,"applicationTime":26,"atts":"GRtUFFsdGR8=","errorBeacon":"bam.nr-data.net","agent":""}</script>

Possibly useful SDL2 reference

OptCarrot is the Ruby NES emulator being used as a benchmark for Ruby3x3 (the goal to make MRI 3x faster by v3.0). It interacts with SDL2 through FFI. Not sure if it's useful or not, but figured I'd bring it up. Files are in this dir. Here's a screenshot:

screenshot 2016-12-01 12 35 35

Gem Release Announcement Emails Have Bad Links

From the 1.0.0b1 release today, the links are expecting this to live under Seattle.rb

graphics version 1.0.0b1 has been released!

* home: <https://github.com/seattlerb/graphics>
* rdoc: <http://docs.seattlerb.org/graphics>

Graphics provides a simple framework to implement games and/or
simulations and is designed to follow mathematical conventions, NOT
game programming conventions. Particularly it:

* Uses degrees.
* Draws in quadrant 1 (0-90 degrees).
* Right hand rule: 0 degrees is east, 90 is north, etc.

These allow simple things like Trigonometry functions to work as
expected. It means that all that stuff you were taught it grade school
still work as intended. This makes one less thing you have to adjust
when implementing your simulation.

Changes:

### 1.0.0b1 / 2015-08-04

* 1 major enhancement

  * Beta Birthday!

Fullscreen mode doesn't work

Given this code:

require "graphics"
Graphics::Simulation.new(200, 200, 0, 'Example', true).run

It cannot find the constant SDL::FULLSCREEN

/Users/josh/.gem/ruby/2.3.1/gems/graphics-1.0.0b6/lib/graphics/simulation.rb:70:in `initialize': uninitialized constant SDL::FULLSCREEN (NameError)
Did you mean?  SDL::Screen
	from f4.rb:2:in `new'
	from f4.rb:2:in `<main>'

I looked through all the constants and didn't see it (grepped the otuput of this):

%w[graphics graphics/body graphics/decorators graphics/extensions graphics/rainbows graphics/simulation graphics/trail graphics/v sdl/sdl]
  .each { |p| require p }

def all_consts(mod, seen)
  return mod unless mod.kind_of? Module
  return mod if seen.include? mod
  seen << mod
  mod.constants.map { |name|
    const = mod.const_get name
    [name, all_consts(const, seen)]
  }.to_h
end

require 'pp'
pp all_consts(SDL, [])

Looks like it was supposed to be defined here

Missing text_size method

Hi!

I've tried using Simulation#text_size but got this problem:

.../gems/graphics-1.0.0b6/lib/graphics/simulation.rb:440:in `text_size': undefined method `text_size' for #<SDL::TTF:0x007fde9ca1fb30> (NoMethodError)

It seems the code expects fonts to implement that method but it's not present in SDL::TTF.

Just FYI, I've checked out this graphics by by adapting a little test prgram and I'm liking it! In that example you can find a text-rotating function that can be handy.

Menlo not available for linux users

The paths and font don't match for linux systems. Not sure what a good universal default is here, but this blows up in creating a new simulation. No idea what happens on Windows (probably catches fire and explodes).

Blue lines are dim

blue-not-showing-up

require "graphics"

class Clock < Graphics::Simulation
  def initialize
    @radius     = 75
    @num_lines  = 200
    @colors     = [:red, :green, :blue]
    super 200, 200
  end

  def update iteration
    @multiplier = 0.1 * iteration
    @colors.rotate!          if (iteration+1) % 100 == 0
    @draw_line = !@draw_line if (iteration+1) % 50 == 0
  end

  def draw(iteration)
    clear
    @num_lines.times do |index|
      start  = 2 * Math::PI  * index / @num_lines
      finish = start * @multiplier
      x1 = Math.cos(start)  * @radius + w/2
      x2 = Math.cos(finish) * @radius + w/2
      y1 = Math.sin(start)  * @radius + h/2
      y2 = Math.sin(finish) * @radius + h/2
      if @draw_line
        line x1, y1, x2, y2, @colors.first
      else
        rect x1, y1, x2, y2, @colors.first
      end
    end
  end
end

Clock.new.run if $0 == __FILE__

Alpha not preserved when blitting

This may be related to #26

In this code, there is alpha around the dots, I assume this is anti aliasing. When I blit them, it doesn't blend the alpha with the new background, so there are artifacts around the dots that almost look like an outline.

screenshot 2016-12-09 11 48 33

# encoding: utf-8
require 'graphics'
require 'pp'

class MySim < Graphics::Simulation
  include Math

  def initialize
    super 800, 600, 32
  end

  def draw(n)
    side     = 2 + n/10.0
    half     = side/2
    radius   = sqrt (w/2)**2 + (h/2)**2
    diameter = 2 * radius

    dots = sprite diameter, diameter do
      (diameter/side).to_i.times do |y|
        xoff = (y%2) * half
        (diameter/side).to_i.times do |x|
          circle x*side+xoff, y*side+half, 0.35*side, :white, true
        end
      end
    end

    clear
    blit dots, w/2, h/2, 0
    blit dots, w/2, h/2, n
  end
end

MySim.new.run

Segfault

Tried out the example from the readme

The exception:

$ ruby f2.rb
ruby f2.rb
2015-09-13 05:43:05.960 ruby[98903:507] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 263'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff94a2c25c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff8dab2e75 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff94a2c10c +[NSException raise:format:] + 204
    3   AppKit                              0x00007fff8ba36eb5 _NSCreateWindowWithOpaqueShape2 + 1403
    4   AppKit                              0x00007fff8ba35a41 -[NSWindow _commonAwake] + 3720
    5   AppKit                              0x00007fff8b911420 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 882
    6   AppKit                              0x00007fff8b9108a2 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1054
    7   AppKit                              0x00007fff8b910478 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
    8   libSDL-1.2.0.dylib                  0x000000010c04b0f4 -[SDL_QuartzWindow initWithContentRect:styleMask:backing:defer:] + 279
    9   libSDL-1.2.0.dylib                  0x000000010c048a6a QZ_SetVideoMode + 1172
    10  libSDL-1.2.0.dylib                  0x000000010c03fdfa SDL_SetVideoMode + 907
    11  sdl_ext.bundle                      0x000000010c003cce Screen_s_open + 158
    12  ruby                                0x000000010bcebf8b vm_call_cfunc + 1547
    13  ruby                                0x000000010bceb300 vm_call_method + 880
    14  ruby                                0x000000010bcd025d vm_exec_core + 12605
    15  ruby                                0x000000010bcdfaa1 vm_exec + 129
    16  ruby                                0x000000010bce845e vm_call0_body + 830
    17  ruby                                0x000000010bcd8633 rb_funcallv + 211
    18  ruby                                0x000000010bbfc3e9 rb_class_new_instance + 41
    19  ruby                                0x000000010bcebf8b vm_call_cfunc + 1547
    20  ruby                                0x000000010bceb300 vm_call_method + 880
    21  ruby                                0x000000010bcd025d vm_exec_core + 12605
    22  ruby                                0x000000010bcdfaa1 vm_exec + 129
    23  ruby                                0x000000010bce0a98 rb_iseq_eval_main + 504
    24  ruby                                0x000000010bb9cec4 ruby_exec_internal + 148
    25  ruby                                0x000000010bb9cdee ruby_run_node + 78
    26  ruby                                0x000000010bb54f8f main + 79
    27  libdyld.dylib                       0x00007fff904f45fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
fish: 'ruby f2.rb' terminated by signal SIGABRT (Abort)

The dependencies:

$ sh rubysdl_setup.sh
+ brew uninstall libogg
Uninstalling /usr/local/Cellar/libogg/1.3.2... (95 files, 672K)
+ brew uninstall libvorbis
Uninstalling /usr/local/Cellar/libvorbis/1.3.5... (155 files, 2.6M)
+ brew uninstall libpng
Uninstalling /usr/local/Cellar/libpng/1.6.18... (17 files, 1.3M)
libpng 1.5.18, 1.6.10, 1.6.16, 1.6.17 are still installed.
Remove them all with `brew uninstall --force libpng`.
+ brew uninstall sdl
Uninstalling /usr/local/Cellar/sdl/1.2.15... (223 files, 2.1M)
+ brew uninstall sdl_ttf
Uninstalling /usr/local/Cellar/sdl_ttf/2.0.11... (8 files, 96K)
+ brew uninstall sdl_mixer
Uninstalling /usr/local/Cellar/sdl_mixer/1.2.12... (8 files, 420K)
+ brew uninstall sdl_image
Uninstalling /usr/local/Cellar/sdl_image/1.2.12_1... (8 files, 140K)
+ gem uninstall -ax rsdl

You have requested to uninstall the gem:
    rsdl-0.1.5

graphics-1.0.0b1 depends on rsdl (~> 0.1)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Removing rsdl
Successfully uninstalled rsdl-0.1.5
+ gem uninstall -ax rubysdl

You have requested to uninstall the gem:
    rubysdl-2.2.0

graphics-1.0.0b1 depends on rubysdl (~> 2.2)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Successfully uninstalled rubysdl-2.2.0
+ gem uninstall -ax graphics
Successfully uninstalled graphics-1.0.0b1
+ brew install sdl
==> Downloading https://homebrew.bintray.com/bottles/sdl-1.2.15.mavericks.bottle.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/sdl-1.2.15.mavericks.bottle.2.tar.gz
==> Pouring sdl-1.2.15.mavericks.bottle.2.tar.gz
🍺  /usr/local/Cellar/sdl/1.2.15: 223 files, 2.1M
+ brew install sdl_mixer --with-smpeg
==> Installing dependencies for sdl_mixer: smpeg
==> Installing sdl_mixer dependency: smpeg
==> Downloading https://homebrew.bintray.com/bottles/smpeg-0.4.5.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring smpeg-0.4.5.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/smpeg/0.4.5: 22 files, 700K
==> Installing sdl_mixer
==> Downloading http://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-1.2.12.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/sdl_mixer/1.2.12
==> make install
🍺  /usr/local/Cellar/sdl_mixer/1.2.12: 8 files, 428K, built in 25 seconds
+ brew install sdl_ttf
==> Installing dependencies for sdl_ttf: libpng
==> Installing sdl_ttf dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.18.mavericks.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/libpng-1.6.18.mavericks.bottle.tar.gz
==> Pouring libpng-1.6.18.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/libpng/1.6.18: 17 files, 1.3M
==> Installing sdl_ttf
==> Downloading https://homebrew.bintray.com/bottles/sdl_ttf-2.0.11.mavericks.bottle.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/sdl_ttf-2.0.11.mavericks.bottle.2.tar.gz
==> Pouring sdl_ttf-2.0.11.mavericks.bottle.2.tar.gz
🍺  /usr/local/Cellar/sdl_ttf/2.0.11: 8 files, 96K
+ brew install sdl_image
==> Downloading https://homebrew.bintray.com/bottles/sdl_image-1.2.12_1.mavericks.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/sdl_image-1.2.12_1.mavericks.bottle.1.tar.gz
==> Pouring sdl_image-1.2.12_1.mavericks.bottle.1.tar.gz
🍺  /usr/local/Cellar/sdl_image/1.2.12_1: 8 files, 140K

The gem:

$ gem install graphics  --pre
Fetching: rubysdl-2.2.0.gem (100%)
Building native extensions.  This could take a while...
Successfully installed rubysdl-2.2.0
Fetching: rsdl-0.1.5.gem (100%)
Building native extensions.  This could take a while...
Successfully installed rsdl-0.1.5
Fetching: graphics-1.0.0b1.gem (100%)
Successfully installed graphics-1.0.0b1
3 gems installed

Code being run (taken from the readme, I only added the first line):

require 'graphics'
class Ball < Graphics::Body
  def initialize w
    super

    # ...
  end

  def draw
    w.angle x, y, a, 10+3*m, :red
    w.circle x, y, 5, :white, :filled
  end

  def update
    fall
    move
    bounce
  end

  # ...
end

class BounceSimulation < Graphics::Simulation
  attr_accessor :bs

  def initialize
    super 640, 640, 16, "Bounce"

    self.bs = populate Ball
  end

  def update n
    bs.each(&:update)
  end

  def draw n
    clear
    bs.each(&:draw)
    fps n
  end

  # ...
end

BounceSimulation.new.run

--without-webp is an invalid option

Description

Running brew install sdl2_image --without-webp as specified in the graphics_setup script for mac OS results in an invalid option error.

I use homebrew, but I am not familiar with all the available options, and was unable to find an alternative. The closest option I found was --ignore-dependencies which says it is:

An unsupported Homebrew development flag to skip installing any dependencies of any kind.

--ignore_dependencies does not seem to be the right option.

I suppose I could install it with the webp dependency, but am curious to know if there is a way to install it using homebrew without that dependency. Does anyone have any insight on this?

blit blip

Graphics::Simulation#blit is not passing the parameters for scaling factors (xs, ys) down to SDL::Surface.transform_blit, and is instead passing ones (maintaining the scale of the image). Also consider defaulting the angle parameter a° to 0.

Current Code:

def blit o, x, y, , xs=1, ys=1, opt=0
  SDL::Surface.transform_blit o, screen, -, 1, 1, o.w/2, o.h/2, x, h-y, opt
end

Alternative Code:

def blit o, x, y, =0, xs=1, ys=1, opt=0
  SDL::Surface.transform_blit o, screen, -, xs, ys, o.w/2, o.h/2, x, h-y, opt
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.