Subscribe to RSS Feed ログイン

オーガニック・ウェルス

Wednesday
2018年2月21日

Javascriptで物理演算の練習2

以前作成した物理演算の練習に壁の跳ね返り、床を転がるモーションを追加しました。

以前作成したもの

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />

<title>物理演算</title>
<script>
<!--
var objects = [];

function CircleObject() {
  this.x = 5;
  this.y = 5;
  this.div_x = 0;
  this.div_y = 0;
}

var timerId;
var context;
var canObj= [];
window.onload = function myload() {
  var canvas = document.getElementById('canvas_1');
  if (!canvas || ! canvas.getContext) { return false; };
  context = canvas.getContext('2d');
  canObj.h = canvas.clientHeight;
  canObj.w = canvas.clientWidth;
  // Y軸の反転
  context.setTransform(1, 0, 0, -1, 0, canObj.h);

  timerId = setInterval(interval, 30);
}
function interval() {
  context.beginPath();
  context.clearRect(0, 0, 500, 500);
  for(i = 0;i < objects.length;i++) {
    var circle = objects[i];
    circle.x -= circle.div_x;
    circle.y -= circle.div_y;
    if(circle.y <= 0) {
      circle.y = 0;
      circle.div_y = (- (circle.div_y * 0.5)); // 反発係数
      circle.div_x = circle.div_x * 0.9; // 転がり摩擦
    } else {
      circle.div_y += 0.98;
    }
    // 壁に当たったとき
    if(circle.x < 0) {
      circle.x = 0;
      circle.div_x = -(circle.div_x * 0.8);
    } else if(circle.x > canObj.w) {
      circle.x = canObj.w;
      circle.div_x = -(circle.div_x * 0.8);
    }
    context.beginPath();
    context.arc(parseInt(circle.x), parseInt(circle.y) + 5, 5, 0, Math.PI*2, false);
    context.fill();
  }
}
function addObj() {
  var newCircle = new CircleObject();
  newCircle.x = 5.0 + Math.floor( Math.random() * 495 );
  newCircle.y = canObj.h;
  newCircle.div_x = -10.0 + Math.floor( Math.random() * 20 );
  objects.push(newCircle);
}
function clearObj() {
  objects = [];
}
-->
</script>

</head>

<body>
<div style="border:1px solid #666;width:500px;height:500px;">
<canvas id="canvas_1" width="500" height="500"></canvas>
</div>
<input type="button" onclick="addObj();" value="追加" />
<input type="button" onclick="clearObj();" value="クリア" />
<div id="debug"></div>
</body>

</html>

コメント(1)続きを読む

swfmillでActionScriptを書いてみるテスト

<?xml version="1.0" encoding="UTF-8"?>
<swf version="10" compressed="1">
  <Header framerate="1" frames="3">
    <size>
      <Rectangle left="0" right="11000" top="0" bottom="8000"/>
    </size>
    <tags>
      <SetBackgroundColor>
        <color>
          <Color red="80" green="128" blue="255"/>
        </color>
      </SetBackgroundColor>
      <ShowFrame/>
      <DoAction>
        <actions>
         <GetURL url="javascript:console.log('Frame 1_1');" target=""/>
         <GetURL url="javascript:console.log('Frame 1_2');" target=""/>
         <GetURL url="javascript:console.log('Frame 1_3');" target=""/>
          <EndAction/>
        </actions>
      </DoAction>
      <ShowFrame/>
      <DoAction>
        <actions>
         <GetURL url="javascript:console.log('Frame 2_1');" target=""/>
          <EndAction/>
        </actions>
        <actions>
         <GetURL url="javascript:console.log('Frame 2_2');" target=""/>
          <EndAction/>
        </actions>
        <actions>
         <GetURL url="javascript:console.log('Frame 2_3');" target=""/>
          <EndAction/>
        </actions>
      </DoAction>
      <ShowFrame/>
      <DoAction>
        <actions>
         <GetURL url="javascript:console.log('Frame 3');" target=""/>
          <EndAction/>
        </actions>
      </DoAction>
      <ShowFrame/>
      <End/>
    </tags>
  </Header>
</swf>

上記XMLをtest1.xmlで保存しswfに変換します。

$ swfmill xml2swf test1.xml test1.swf

<object width="200" height="200">
  <embed src="test1.swf"
  loop="false"
  pluginspage="http://www.macromedia.com/go/getflashplayer"
  type="application/x-shockwave-flash"
  width="200"
  height="200"></embed>
</object>

上記タグで表示します。

青背景の領域が表示されます。またconsole.logを実行しています。これはframerate[fps]で指定した間隔でActionScriptが実行されます。

ひとつのactionsタグの中に複数のGetURLを記述すると最後の値が評価されます。

またactionsタグを複数記述すると最初のactionsだけが評価されます。

コメント(0)続きを読む

Rustがdebianでコンパイルできない

先日Rust-compilerが0.2になっていました。そして最近debianを使い始めたのですが0.1/0.2ともmakeに失敗します。

ただいま原因を調査しています。どなたかご存知の方がいれば一報いただけますと幸いです。

0.1のmake結果
compile: rustllvm/x86_64-unknown-linux-gnu/RustGCMetadataPrinter.o
compile: rustllvm/x86_64-unknown-linux-gnu/RustGCStrategy.o
compile: rustllvm/x86_64-unknown-linux-gnu/RustWrapper.o
def: rustllvm/rustllvm.linux.def
link: rustllvm/x86_64-unknown-linux-gnu/librustllvm.so
cp: x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/librustllvm.so
compile_and_link: x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore.so
compile_and_link: x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd.so
compile_and_link: x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/librustc.so
error: internal compiler error unexpected failure
note: The compiler hit an unexpected failure path. This is a bug. Try running with RUST_LOG=rustc=0,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
make: *** [x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/librustc.so] Error 101

0.2のmake結果

make: *** [x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/librustc.so] Error 137

 

コメント(0)続きを読む

メイリオKEフォントを試してみる

以下のサイトより

メイリオフォントよりメイリオKEフォント 「MeiryoKeGothic」 – Net Life

メイリオKEフォントの場合
なぜ41%の数字かというと、カロリー総額のうち油脂類が供給量では大部分を占めているのに自給率では3%にしか成りません。でも生産額ベースでは殆ど割合には含まれません。つまり油脂類は購入しているヒトは少ないがカロリーが高いため数値への影響が大きく自給率を見た目上引き下げているのです。

メイリオの場合
なぜ41%の数字かというと、カロリー総額のうち油脂類が供給量では大部分を占めているのに自給率では3%にしか成りません。でも生産額ベースでは殆ど割合には含まれません。つまり油脂類は購入しているヒトは少ないがカロリーが高いため数値への影響が大きく自給率を見た目上引き下げているのです。

MS Pゴシックの場合
なぜ41%の数字かというと、カロリー総額のうち油脂類が供給量では大部分を占めているのに自給率では3%にしか成りません。でも生産額ベースでは殆ど割合には含まれません。つまり油脂類は購入しているヒトは少ないがカロリーが高いため数値への影響が大きく自給率を見た目上引き下げているのです。

確かに文字幅が調整されていてMS Pゴシックと混同しても大丈夫そうですね。



コメント(0)続きを読む

スティーブ・ジョブズ、スタンフォード大学での演説英語原文

いくつかのサイトを見て回ったのだけれど完全にあっている文が見つからなかったので以下のサイトを使って修正したのを掲載したいと思います。

Slashdot Comments | Steve Jobs In Praise of Dropping Out

Thank you. I’m honored to be with you today for your commencement from one of the finest universities in the world. Truth be told, I never graduated from college and this is the closest I’ve ever gotten to a college graduation.

Today I want to tell you three stories from my life. That’s it. No big deal. Just three stories. The first story is about connecting the dots.

I dropped out of Reed College after the first six months but then stayed around as a drop-in for another eighteen months or so before I really quit. So why did I drop out? It started before I was born. My biological mother was a young, unwed graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife, except that when I popped out, they decided at the last minute that they really wanted a girl. So my parents, who were on a waiting list, got a call in the middle of the night asking, “We’ve got an unexpected baby boy. Do you want him?” They said, “Of course.” My biological mother found out later that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would go to college.

This was the start in my life. And seventeen years later, I did go to college, but I naïvely chose a college that was almost as expensive as Stanford, and all of my working-class parents’ savings were being spent on my college tuition. After six months, I couldn’t see the value in it. I had no idea what I wanted to do with my life, and no idea of how college was going to help me figure it out, and here I was, spending all the money my parents had saved their entire life. So I decided to drop out and trust that it would all work out OK. It was pretty scary at the time, but looking back, it was one of the best decisions I ever made. The minute I dropped out, I could stop taking the required classes that didn’t interest me and begin dropping in on the ones that looked far more interesting.

It wasn’t all romantic. I didn’t have a dorm room, so I slept on the floor in friends’ rooms. I returned Coke bottles for the five-cent deposits to buy food with, and I would walk the seven miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example.

Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer was beautifully hand-calligraphed. Because I had dropped out and didn’t have to take the normal classes, I decided to take a calligraphy class to learn how to do this. I learned about serif and sans-serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can’t capture, and I found it fascinating.

None of this had even a hope of any practical application in my life. But ten years later when we were designing the first Macintosh computer, it all came back to me, and we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the Mac would have never had multiple typefaces or proportionally spaced fonts, and since Windows just copied the Mac, it’s likely that no personal computer would have them.

If I had never dropped out, I would have never dropped in on that calligraphy class and personals computers might not have the wonderful typography that they do.

Of course it was impossible to connect the dots looking forward when I was in college, but it was very, very clear looking backwards 10 years later. Again, you can’t connect the dots looking forward. You can only connect them looking backwards, so you have to trust that the dots will somehow connect in your future. You have to trust in something–your gut, destiny, life, karma, whatever–because believing that the dots will connect down the road will give you the confidence to follow your heart, even when it leads you off the well-worn path, and that will make all the difference.

My second story is about love and loss. I was lucky. I found what I loved to do early in life. Woz and I started Apple in my parents’ garage when I was twenty. We worked hard and in ten years, Apple had grown from just the two of us in a garage into a $2 billion company with over 4,000 employees. We’d just released our finest creation, the Macintosh, a year earlier, and I’d just turned thirty, and then I got fired. How can you get fired from a company you started? Well, as Apple grew, we hired someone who I thought was very talented to run the company with me, and for the first year or so, things went well. But then our visions of the future began to diverge, and eventually we had a falling out. When we did, our board of directors sided with him, and so at thirty, I was out, and very publicly out. What had been the focus of my entire adult life was gone, and it was devastating. I really didn’t know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down, that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly. I was a very public failure and I even thought about running away from the Valley. But something slowly began to dawn on me. I still loved what I did. The turn of events at Apple had not changed that one bit. I’d been rejected but I was still in love. And so I decided to start over.

I didn’t see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods in my life. During the next five years I started a company named NeXT, another company named Pixar and fell in love with an amazing woman who would become my wife. Pixar went on to create the world’s first computer-animated feature film, “Toy Story,” and is now the most successful animation studio in the world.

In a remarkable turn of events, Apple bought NeXT and I returned to Apple and the technology we developed at NeXT is at the heart of Apple’s current renaissance, and Lorene and I have a wonderful family together.

I’m pretty sure none of this would have happened if I hadn’t been fired from Apple. It was awful-tasting medicine but I guess the patient needed it. Sometimes life’s going to hit you in the head with a brick. Don’t lose faith. I’m convinced that the only thing that kept me going was that I loved what I did. You’ve got to find what you love, and that is as true for work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work, and the only way to do great work is to love what you do. If you haven’t found it yet, keep looking, and don’t settle. As with all matters of the heart, you’ll know when you find it, and like any great relationship it just gets better and better as the years roll on. So keep looking. Don’t settle.

My third story is about death. When I was 17 I read a quote that went something like “If you live each day as if it was your last, someday you’ll most certainly be right.” It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself, “If today were the last day of my life, would I want to do what I am about to do today?” And whenever the answer has been “no” for too many days in a row, I know I need to change something. Remembering that I’ll be dead soon is the most important thing I’ve ever encountered to help me make the big choices in life, because almost everything–all external expectations, all pride, all fear of embarrassment or failure–these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.

About a year ago, I was diagnosed with cancer. I had a scan at 7:30 in the morning and it clearly showed a tumor on my pancreas. I didn’t even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months. My doctor advised me to go home and get my affairs in order, which is doctors’ code for “prepare to die.” It means to try and tell your kids everything you thought you’d have the next ten years to tell them, in just a few months. It means to make sure that everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes.

I lived with that diagnosis all day. Later that evening I had a biopsy where they stuck an endoscope down my throat, through my stomach into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated but my wife, who was there, told me that when they viewed the cells under a microscope, the doctor started crying, because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and, thankfully, I am fine now.

This was the closest I’ve been to facing death, and I hope it’s the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept. No one wants to die, even people who want to go to Heaven don’t want to die to get there, and yet, death is the destination we all share. No one has ever escaped it. And that is as it should be, because death is very likely the single best invention of life. It’s life’s change agent; it clears out the old to make way for the new. right now, the new is you. But someday, not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it’s quite true. Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma, which is living with the results of other people’s thinking. Don’t let the noise of others’ opinions drown out your own inner voice, and most important have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.

When I was young, there was an amazing publication called The Whole Earth Catalogue, which was one of the bibles of my generation. It was created by a fellow named Stuart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late Sixties, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and Polaroid cameras. it was sort of like Google in paperback form thirty-five years before Google came along. I was idealistic, overflowing with neat tools and great notions. Stuart and his team put out several issues of the The Whole Earth Catalogue, and then when it had run its course, they put out a final issue. It was the mid-Seventies and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath were the words, “Stay hungry, stay foolish.” It was their farewell message as they signed off. “Stay hungry, stay foolish.” And I have always wished that for myself, and now, as you graduate to begin anew, I wish that for you. Stay hungry, stay foolish.

Thank you all, very much.

スティーブ・ジョブズ、スタンフォード大学での演説英語原文 はコメントを受け付けていません。続きを読む

これからブログを始めることにしました

ict-startドメインでブログをはじめることにしました。

日々色々なことを書いていきたいです。

コメント(0)続きを読む