tilt
Generic interface to multiple Ruby template engines
rtomayko/tilt · GitHub tilt - generic interface to multiple ruby template engines
I've been trying to create the following effect with no success and would really appreciate any help given
The effect is moving an image from left to right according to the iPad tilt. The iPad is held in landscape view and the image should move from left to right (actually it is up and down).
The image width is doubled the iPad stage (2048px) and should duplicate itsefe when reaching the end of the window.
Can some one help me to start this?
Thanks in advance
Source: (StackOverflow)
I am trying to write a game. That game uses tilt effect, but i don't know how to test it on Iphone Simulator 3.0.
I search it on internet, but the result is zero. How can i...?
Source: (StackOverflow)
The Android game My Paper Plane is a great example of how to implement tilt controls, but I've been struggling to understand how I can do something similar.
I have the following example that uses getOrientation() from the SensorManager. The whole thing is on pastebin here. It just prints the orientation values to text fields. Here is the most relevant snippet:
private void computeOrientation() {
if (SensorManager.getRotationMatrix(m_rotationMatrix, null,
m_lastMagFields, m_lastAccels)) {
SensorManager.getOrientation(m_rotationMatrix, m_orientation);
/* 1 radian = 57.2957795 degrees */
/* [0] : yaw, rotation around z axis
* [1] : pitch, rotation around x axis
* [2] : roll, rotation around y axis */
float yaw = m_orientation[0] * 57.2957795f;
float pitch = m_orientation[1] * 57.2957795f;
float roll = m_orientation[2] * 57.2957795f;
/* append returns an average of the last 10 values */
m_lastYaw = m_filters[0].append(yaw);
m_lastPitch = m_filters[1].append(pitch);
m_lastRoll = m_filters[2].append(roll);
TextView rt = (TextView) findViewById(R.id.roll);
TextView pt = (TextView) findViewById(R.id.pitch);
TextView yt = (TextView) findViewById(R.id.yaw);
yt.setText("azi z: " + m_lastYaw);
pt.setText("pitch x: " + m_lastPitch);
rt.setText("roll y: " + m_lastRoll);
}
}
The problem is that the values this spits out look like nonsense, or at least there's no way to isolate which type of motion the user performed. I've drawn a diagram to indicate the 2 types of motion that I'd like to detect - 1. "tilt" for pitch and 2. "rotate" for roll/steering:
(That's an isometric-ish view of a phone in landscape mode, of course)
When I tilt the phone forwards and backwards along its long axis - shown by 1. - I expected only 1 of the values to change much, but all of them seem to change drastically. Similarly, if I rotate the phone about an imaginary line that comes out of the screen - shown in 2. - I'd hope that only the roll value changes, but all the values change a lot.
The problem is when I calibrate my game - which means recording the current values of the angles x, y and z - I later don't know how to interpret incoming updated angles to say "ok, looks like you have tilted the phone and you want to roll 3 degrees left". It's more like "ok, you've moved the phone and you're a-tiltin' and a-rollin' at the same time", even if the intent was only a roll. Make sense?
Any ideas? I've tried using remapCoordinateSystem to see if changing the axis has any effect. No joy. I think I'm missing something fundamental with this :-(
Source: (StackOverflow)
I tried to use the Z axis data from SensorEvent.values, but it doesn't detect rotation of my phone in the XY plane, ie. around the Z-axis.
I am using this as a reference for the co-ordinate axes. Is it correct?
How do I measure that motion using accelerometer values?
These games do something similar: Extreme Skater, Doodle Jump.
PS: my phone orientation will be landscape.
Source: (StackOverflow)
I'm trying to create a sprockets preprocessor for Rails that finds .png.rb
files in the asset pipeline and uses them to generate png screenshots of various pages in my application.
I've read up on this topic quite a bit but I can't seem to find any straightforward documentation on how to get this set up. Help, please?
Here's what I have so far:
/initializers/sprockets.rb
:
require 'screenshot_preprocessor'
Rails.application.assets.register_mime_type('screenshot/png', '.png.rb')
Rails.application.assets.register_preprocessor('screenshot/png', ScreenshotPreprocessor)
/lib/screenshot_preprocessor.rb:
class ScreenshotPreprocessor
# What API do I need to provide here?
# - What methods do I need to provide?
# - What parameters does Sprockets pass me?
# - What do I need to return to Sprockets?
end
Source: (StackOverflow)
has anybody already programmed a iphone compass heading tilt compensation?
i have got some approaches, but some help or a better solution would be cool!
FIRST
i define a vector Ev, calculated out of the cross product of Gv and Hv. Gv is a gravity vector i build out of the accelerometer values and Hv is an heading vector built out the magnetometer values.
Ev stands perpendicular on Gv and Hv, so it is heading to horizonatl East.
SECOND
i define a vector Rv, calculated out of the cross product Bv and Gv. Bv is my looking vector and it is defined as [0,0,-1]. Rv is perpendicular to Gv and Bv and shows always to the right.
THIRD
the angle between these two vectors, Ev and Rv, should be my corrected heading. to calculate the angle i build the dot product and thereof the arcos.
phi = arcos ( Ev * Rv / |Ev| * |Rv| )
Theoretically it should work, but maybe i have to normalize the vectors?!
Has anybody got a solution for this?
Thanks, m01d
Source: (StackOverflow)
I am working on an android app that requires the detection of vertical motion. When moving the tablet upward, the Gyroscope, Accelerometer, and Linear Acceleration sensors give a corresponding value indicating upward or downward motion.
The problem I have is that these sensors will also read an upward/downward motion when you tilt the tablet towards the user or away from the user. For example, the x value in the gyroscope represents the vertical plane. But when you tilt the device forwards, the x value will change.
When I make this motion, the same sensor that reads vertical motion reads a value for this.
http://i.imgur.com/BHEx4.png
The same goes for the rest of the sensors. I have tried to use orientation coupled with the gyro to make the conditional statement, if the pitch is not changing, but the x variable is going up/down, then we have vertical motion. The problem with this is that if the user moves it up but tilted slightly, it will no longer work. I also tried making it so if there is a change in tilt, then there is no vertical motion. But it iterates so quickly that there may be a change in tilt for 1/100 of a second, but for the next there isn't.
Is there any way I can read only vertical changes and not changes in the devices pitch?
Here is what I want to detect:
http://i.imgur.com/o0iAW.png
edit:
"Please come up with a mathematically sound definition of what you consider 'moving upwards.'"
This was my initial question, how can I write a function to define when the tablet is moving upwards or downwards? I consider a vertical translation moving upwards. Now how do I detect this? I simply do not know where to begin, thank you.
Source: (StackOverflow)
Is it possible to render fragments of Tilt templates (i.e., without using a template file on disk)?
Background: I'd like to render inline template strings in a Ruby CGI program.
Source: (StackOverflow)
when I am trying to use the styl: tag in the stylus file I am not able to compile it...here is the error I am getting.
Temple::FilterError: Tilt engine styl is not available.
Use --trace for backtrace.
Source: (StackOverflow)
I need to upgrade my apps to Rails 3.2.16, when I did bundle update rails
it gives me the following error.
Bundler could not find compatible versions for gem "tilt":
In Gemfile:
sass-rails (= 3.2.6) ruby depends on
tilt (~> 1.3) ruby
slim (>= 0) ruby depends on
tilt (2.0.0)
My Gemfile:
gem 'sass-rails', '~> 3.2.6'
gem 'slim'
I don't know how to fix this. Help please.
Thanks,
Source: (StackOverflow)
I need to read the pitch value (how much the phone is tilted backwards and forwards) both in portrait and landscape modes. using the code bellow in portrait I get my value from value[1] with 0.0 when phone stay laying flat with face up, -90 when standing upright and 180 when lying flat on the device face. All great till now...
The problem comes when the device is in landscape mode. At this point I'm using value[2] to measure device tilt, but the problem is with the values : 0 when the phone stay laying flat (OK) rise to 90 when it is standing upright (OK), but when I continue the movement the value drop again below 90 (80, 75, etc...), so basically I can't differentiate between these 2 positions as the values are identical.
So, what I'm doing wrong, what other values from the sensors I can read in order to have a full picture of the device tilt both in landscape and portrait mode ?
Same questoion as here: http://groups.google.com/group/android-beginners/browse_thread/thread/c691bbac3e294c7c?pli=1
I Have the following code :
private void ReadOrientationSensor(){
final SensorManager sensorManager;
final TextView text = (TextView) this.findViewById(R.id.TextView01);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
SensorEventListener listener = new SensorEventListener() {
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
public void onSensorChanged(SensorEvent event) {
float x,y,z;
x=event.values[0];
y=event.values[1];
z=event.values[2];
//text.setText(String.valueOf(event.values[0]));
text.setText("x: " + x + " y: " + y + " z: " + z);
}
};
sensorManager.registerListener(listener, sensor,SensorManager.SENSOR_DELAY_FASTEST);
}
Source: (StackOverflow)
TL;DR - how can I use something like improved_markdown :some_file
to do custom rendering, but still render the layout as usual?
Normally, to render Markdown in Sinatra, you'd just do:
markdown :some_file
But I'd like to add the ability to do "fenced" syntax highlighting, like you can do in Github README files.
```ruby
class Foo
# etc
end
```
I've got this partially working.
First, I installed Redcarpet and added a custom rendering class that uses Pygments.rb for syntax highlighting:
# create a custom renderer that allows highlighting of code blocks
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
Pygments.highlight(code, lexer: language)
end
end
Then I used it in a route, like this:
# Try to load any Markdown file specified in the URL
get '/*' do
viewname = params[:splat].first
if File.exist?("views/#{viewname}.md")
# Uses my custom rendering class
# The :fenced_code_blocks option means it will take, for example,
# the word 'ruby' from ```ruby and pass that as the language
# argument to my block_code method above
markdown_renderer = Redcarpet::Markdown.new(HTMLwithPygments, :fenced_code_blocks => true)
file_contents = File.read("views/#{viewname}.md")
markdown_renderer.render(file_contents)
else
"Nopers, I can't find it."
end
end
This almost works. The Markdown is rendered as HTML with additional markup for highlighting purposes.
The only problem is that it does not use my layout; after all, I'm just reading a file and returning the rendered string. The normal markdown :foo
call would involve Tilt in the process.
Do I have to create a custom Tilt template engine to get that to work, or is there an easier way?
Source: (StackOverflow)
Running bundle update
on my padrino app gives me:
Bundler could not find compatible versions for gem "tilt":
In Gemfile:
padrino (= 0.11.1) ruby depends on
tilt (~> 1.3.0) ruby
padrino (= 0.11.1) ruby depends on
tilt (1.4.0)
This just started happening: not sure what's changed.
Running Ruby 1.9.3-p392
Gemfile
looks like:
source 'https://rubygems.org'
ruby '1.9.3'
gem 'unicorn'
gem 'rake'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'slim'
gem 'mongoid', '~>3.0.0'
gem 'haml'
gem 'padrino', '0.11.1'
Source: (StackOverflow)
How to determine the angle of the phone orientation in the one plane?
Now I make it through SensorManager:
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
...
public void onSensorChanged(SensorEvent event) {
xy_angle = event.values[0];
xz_angle = event.values[1];
zy_angle = event.values[2];
Here I get different angles, but I need only one angle, which varies with the rotation of the phone, while driving along the blue line.
How calc or how get this angle?
How can I use SensorManager.getOrientation for tilt controls like "My Paper Plane"? - similar question here, but I don't understand how author solve his problem.
Source: (StackOverflow)
I am currently making an ios game in a program called istencyl for a contest on there website. The game involves rolling a character around with the accelerometer. Everything would be going fine but unfortunately in the ios simulator you can't test tilt! I would test it on my device but I'm 13 and I don't have the money to buy a dev kit, meaning I can't test it on a device. I saw something on here about using a subclass UIAccelerometer but I'm not a good programmer (istencyl lets you use either a block system or regular code, i chose the blocks) so I didn't understand it. Istencyl programs with a gui usually but you can do the coding yourself I'm just not sure how. Any ideas? I heard about this one app on the app store called iSimulate but its 16 dollars! Is it worth it?
Source: (StackOverflow)