2011-12-01から1ヶ月間の記事一覧

オイラー法による等速度直線運動

#include<GL/glut.h> double dt = 0.02; //秒 int step = 0; typedef struct{ float xPosition; float yPosition; float zPosition; float xVelocity; float yVelocity; float zVelocity; }PARTICLE; PARTICLE particle[1] = {-10.0, 0.0, 0.0, 5.0, 0.0, 0.0}; void in</gl/glut.h>…

テクスチャマッピング

#include <GL/glut.h> #include <stdio.h> #define TEXTURE_HEIGHT 16 #define TEXTURE_WIDTH 16 unsigned char image[TEXTURE_HEIGHT][TEXTURE_WIDTH][4]; void initTexture(void) { int i, j; int color; for (i = 0; i < TEXTURE_HEIGHT; i++) { for (j = 0; j < TEXTURE_WIDT</stdio.h></gl/glut.h>…

Mysql + Eclipse

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; class test { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver…

lex/yacc part2

%% "+" return(ADD); "-" return(SUB); "*" return(MUL); "/" return(DIV); "(" return(LP); ")" return(RP); [0-9]+ {yylval = atoi(yytext); return(NUMBER);} \n return(NEWLINE); [ \t] ; %% %{ #include<stdio.h> %} %token NEWLINE %token NUMBER %token LP %to</stdio.h>…

lex/yacc part1

%% I return (I); You return(You); ate return(ate); bought return(bought); apples return(apples); oranges return(oranges); [ \t] ; %% %{ #include<stdio.h> %} %token I %token You %token ate %token bought %token apples %token oranges %% sentence : sub</stdio.h>…

簡単なプログラム

printf("input :") n = scanf("%d") if (modulo(n, 2)) then printf("%d is odd.", n) else printf("%d is even.", n) end 実行結果 >exec('C:\Users\user\Desktop\test.sce', -1) input : >99 99 is odd. >exec('C:\Users\user\Desktop\test.sce', -1) inpu…

plot2d

-->x = 1:9 x = 1. 2. 3. 4. 5. 6. 7. 8. 9. -->y = [0.7, 0.6, 0.7, 9.6, 3.5, 4.2, 29.4, 7.2, 5.6] y = 0.7 0.6 0.7 9.6 3.5 4.2 29.4 7.2 5.6 -->plot2d(x, y)

scilab再入門

-->A = [2, 1; 5, 3] A = 2. 1. 5. 3. -->B = inv(A) B = 3. - 1. - 5. 2. -->A * B ans = 1. 0. 3.553D-15 1. -->det(A) ans = 1. -->A' ans = 2. 5. 1. 3. -->1/3 ans = 0.3333333 -->rand() ans = 0.2113249 -->rand() ans = 0.7560439 -->%i^2 ans = - 1.

エコーサーバー

RFC862に準拠 import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; public class echo_server { public final static int BUFSIZE = 32; public static void mai…

ソケットのアドレス

import java.net.InetAddress; public class test { public static void main(String[] args) { try { InetAddress address = InetAddress.getLocalHost(); System.out.println("host name : " +address.getHostName()); System.out.println("host address :…

lexの入出力

in.dat1 2 3 4 5 6 7 8 9 10 %{ int total; %} NUMBER [0-9] %% {NUMBER}+ {printf("number (%s)", yytext); total = total+atoi(yytext);} %% main(int argc, char *argv[]) { char str[256]; total = 0; if(argc < 3) { printf("Argument Error!!\n"); exi…

lex

%{ int number_total; int alphabet_total; %} %% [0-9]+ {printf("number (%s)", yytext); number_total++;} [a-zA-Z]+ {printf("alphabet (%s)", yytext); alphabet_total++;} "\n"|" "|"\t" {printf("%s", yytext);} %% main( ) { number_total = 0; alph…

scliab入門〜その1

t = [0 : 0.1 : 2 * %pi]'; xtitle('三角関数', 't[sec]', 'sin(t) cos(t)') plot2d(t, [sin(t) cos(t)],[-4 -14]) [f:id:gotysoft:20111224210030j:image:medium]

xyz軸の回転

#include<GL/glut.h> int xAngle = 0; int yAngle = 0; int zAngle = 0; void init(char *name) { int width = 300, height = 300; glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(width, height); glutCreateWindow(name); glClearColor(0.0, 0.0, 0.0, 1.0); gl</gl/glut.h>…

最大値を求める

name score natsumi 97 yozora 78 sena 78 ohana 97 nakoti 52 D:\sql>sqlite3 test.db SQLite version 3.7.9 2011-11-01 00:52:41 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table person(name text, sco…

IN演算子とBETWEEN演算子

id name 1 natsumi 2 yozora 3 sena 4 ohana 8 nakoti D:\sql>sqlite3 test.db SQLite version 3.7.9 2011-11-01 00:52:41 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table person(id integer, name text)…

サブクエリ

D:\sql>sqlite3 test.db SQLite version 3.7.9 2011-11-01 00:52:41 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table person(id integer, name text, math integer); sqlite> insert into person values(1…

頂点配列その3

#include<stdio.h> #include<GL/glut.h> void init(char *name) { int width = 300, height = 300; glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(width, height); glutCreateWindow(name); glClearColor(1.0, 1.0, 1.0, 1.0); } void display(void) { GLfloat ary[] = {-</gl/glut.h></stdio.h>…

頂点配列その2

#include<stdio.h> #include<GL/glut.h> void init(char *name) { int width = 300, height = 300; glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(width, height); glutCreateWindow(name); glClearColor(1.0, 1.0, 1.0, 1.0); } void display(void) { GLfloat ary[] = {0</gl/glut.h></stdio.h>…

頂点配列その1

#include<stdio.h> #include<GL/glut.h> void init(char *name) { int width = 300, height = 300; glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(width, height); glutCreateWindow(name); glClearColor(1.0, 1.0, 1.0, 1.0); } void display(void) { GLfloat ary[] = {-</gl/glut.h></stdio.h>…

フォームへ入力された要素のエラーチェック

<html> <head> <script type="text/javascript"> <!-- function check(){ var q = document.form1.label1.value; if (q.match(/^[a-z]+$/)) { alert("入力成功 " + q); }else { alert("入力失敗 " + q); } } //--> </script> </head> <body> <form name="form1" method="POST" onsubmit="return check()"> <label>input : </label></form></body></html>

テキストエリアに入力された文字列を取得する

<html> <head> <title>テスト</title> </head> <body> <script type="text/javascript"><!-- <!-- function test(){ window.alert(document.form1.textarea1.value); return false; } //--> </script> </head> <body> <form name="form1" onsubmit="return test()"> </form></body>

サブウィンドウに動的に書き込む

<html> <head> <title>テスト</title> </head> <body> <script type="text/javascript">どうしても変わらない。。。</font>'); subwin.document.clo…

プロトタイプベースのオブジェクト指向

var Point = function(x, y) { this.x = x; this.y = y; }; Point.prototype.length = function() {return Math.sqrt(this.x * this.x + this.y * this.y)}; var point1 = new Point(3, 4); document.write("x = " + point1.x + " y = ", point1.y + " lentg…

関数で足し算

function sum(ary) { var sum = ary[0]; document.write(ary[0]); for (var i = 1; i < ary.length; i++) { document.write(" + " + ary[i]); sum += ary[i] } document.write(" = "); return sum; } document.write(sum([1, 2, 3]) + "<br>"); document.write(s…

Dateオブジェクト

var date = new Date('2032/03/26'); document.write(date.getFullYear(), '年', '<br>'); document.write(date.getMonth(), '月', '<br>'); document.write(date.getDate(), '月', '<br>'); // --></script> </body> </html>

外部ファイルの読み込み

test.txt1|natsumi 2|yozora 3|sena上記のファイルを読み込む。 d:\sql>sqlite3 test.db SQLite version 3.7.9 2011-11-01 00:52:41 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table person(id integer, n…

結合(sqlite3)

personテーブル id name 1 reika 2 tae 3 moe 4 natsumi mathテーブル name score natsumi 32 tae 84 moe 35 kaoru 97 以上のテーブルがあるとする。内部結合 sqlite> select * from person inner join math on person.name = math.name; 2|tae|tae|84 3|moe…

フォーム

掛け算をする。 <html> <head> <title>テスト</title> </head> <body> <script type="text/javascript"> <!-- function multiply() { var x = parseInt(document.product.value1.value); var y = parseInt(document.product.value2.value); document.product.result.value = x * y; } // --> </script> <form name="product"> </form></body></html>

画像の高さと幅

画像をクリックしたら画像の高さと幅が表示する。 <html> <head> <title>テスト</title> <script type="text/javascript"><!-- function test(picture_name) { var image = new Image(); image.src = picture_name; document.write(image.height + "<br>" + image.width); } // --></script> </head> <body> </body></html>