Skip to content

Instantly share code, notes, and snippets.

View jsyeh's full-sized avatar

Jeng-Sheng Yeh 葉正聖 jsyeh

View GitHub Profile
#include <GL/glut.h> ///第18行留下來,使用 GLUT外掛
void display()
{
glColor3f(1,1,0);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
int main(int argc, char *argv[]) ///第138行, main()函式
@jsyeh
jsyeh / DigimonFractal.bas
Created August 7, 2023 05:32
數碼寶貝Digimon 第1季第5集的程式碼
100 /* func sample. coast creation */
110 float s
120 while s<1 or s>=2
130 input "ratio 1 to 2";s
140 endwhile
150 s = (s-1)/10+1
160 screen 1,2,1,1
170 s=sqr(s*s-1)
180 float x0=100, x1=412, y0=0, y1=0
190 fractal(x0,x1,y0,y1,1)
@jsyeh
jsyeh / IntegerSet.cpp
Created August 6, 2023 16:24
回答 Nina Chen 的 IntegerSet 問題
#include <iostream>
#include "IntegerSet.h"
using namespace std;
IntegerSet::IntegerSet(){
bool v[50] = {}; //但是你這裡初始化的,是local區域變數,與 IntegerSet 裡的 v[50] 沒有關係
}
IntegerSet::IntegerSet(int n, int y[]){
bool v[50] = {}; //但是你這裡初始化的,是另一個local區域變數,與 IntegerSet 裡的 v[50] 沒有關係
@jsyeh
jsyeh / 3digit.cpp
Created October 19, 2022 09:58
每3位隔逗號 (銘傳大學阿平老師出的題目)
// https://www.facebook.com/groups/1403852566495675/posts/3295538717327041/
// 每3位隔逗號 (銘傳大學阿平老師出的題目)
#include <stdio.h>
int main()
{
long long int n=123456789012345;//很長很長的整數,最多19位吧
int ans[20], len=0;//用ans[i]陣列來存每個位數的值
for(int i=0; i<20; i++){//陣列開20格,一定夠用啦
ans[i] = n % 10; //把個位數存起來
n = n / 10;//n被剝皮,就變少了
@jsyeh
jsyeh / twoPlayerGame.pde
Last active June 6, 2022 10:40
雙人的小遊戲
//回覆網友 雙人的小遊戲 https://www.facebook.com/groups/1403852566495675/posts/3188292548051659/
//我寫了一段程式給你參考。鍵盤左邊的 wsad 控制 玩家1, 右邊方向鍵控制 玩家2。
//這段程式的重點: (1) 位置 x y 配合 速度 vx vy 來更新
//(2) 按下按鍵時, 要去改速度
//(3) 放開按鍵時, 就把速度設0
//建議寫程式時: File-Preference 字型調大一點,配合中文字型,截圖較清楚
float x=100, y=300, x2=700, y2=300;//位置, 用來畫2位玩家
float vx=0, vy=0, vx2=0, vy2=0;//玩家的速度, 用來修改玩家的位置
void setup(){
@jsyeh
jsyeh / myEarth.cpp
Last active April 25, 2022 11:12
畫出會旋轉的地球: 利用 OpenGL/GLU/GLUT + OpenCV 讀入地圖的圖檔
///全刪,拿剛剛的程式來用!!!
#include <opencv/highgui.h> ///使用 OpenCV 2.1 比較簡單, 只要用 High GUI 即可
#include <opencv/cv.h>
#include <GL/glut.h>
GLUquadric * sphere = NULL;///一個指到二次曲面的指標
int myTexture(char * filename)
{
IplImage * img = cvLoadImage(filename); ///OpenCV讀圖
cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
@jsyeh
jsyeh / myTexture.cpp
Created April 18, 2022 10:13
OpenCV 最簡單的貼圖程式片斷, 利用 OpenCV 2.1 及 OpenGL 即可完成貼圖的設定
#include <opencv/highgui.h> ///使用 OpenCV 2.1 比較簡單, 只要用 High GUI 即可
#include <opencv/cv.h>
#include <GL/glut.h>
int myTexture(char * filename)
{
IplImage * img = cvLoadImage(filename); ///OpenCV讀圖
cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID
glGenTextures(1, &id); /// 產生Generate 貼圖ID
@jsyeh
jsyeh / fortran_bubble.f90
Created April 4, 2022 15:41
在 Fortran 寫 Bubble Sort, 回覆網友Yunping Su作業的問題 https://www.facebook.com/groups/1403852566495675/posts/3140766886137559/
program fortran_bubble
character (len = 8), dimension(20) :: name
integer, dimension(20) :: grade ! Total 20 students
character (len = 8) :: tempName ! Temp swapping variables
integer :: tempGrade
open(20, file = 'student_grad.txt')
do i = 1,20
read(20,*) name(i), grade(i)
@jsyeh
jsyeh / myLight.cpp
Last active April 25, 2022 05:37
打光的程式
#include <GL/glut.h>
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
@jsyeh
jsyeh / uva10062.cpp
Created March 23, 2022 09:39
UVA10062 統計頻率 Tell me the frequencies!
#include <stdio.h>
char line[2000];
int main()
{
int t=1;//t=1是火車頭 2是掛勾車廂 3是掛勾車廂 4是掛勾車廂 ....
while( gets(line) ){ //一次讀入 得到一整行
if(t>1) printf("\n");//火車頭不印,掛勾車廂才印
t++;//這個容易漏掉,我放前面一點,方便你看到
int freq[256]={};//別忘了陣列初始化