Skip to content

Instantly share code, notes, and snippets.

View celestialphineas's full-sized avatar
🐢
Slowly working on hanzi stuff

Celestial Phineas celestialphineas

🐢
Slowly working on hanzi stuff
View GitHub Profile
@celestialphineas
celestialphineas / homework_sys.sh
Created July 15, 2017 06:57
Homework management in shell :)
#!/bin/bash
# A simple homework management system in bash
#============================================
# By: Celestial Phineas @ ZJU (Yehang YIN)
# July 14, 2017
# No database is used in this project.
# It is based on pure ASCII text files.
# Serves as a homework and demo.
@celestialphineas
celestialphineas / jandan.m
Created September 12, 2017 15:09
画一只超载鸡咩~ = ̄ω ̄=
ζ[x_] := (1 - x/10) Sqrt[1 - Abs[x^3]];
η[x_] := (1 - x/10) Sqrt[1 - Abs[x^2]];
Show[
ParametricPlot3D[{{4/5 ζ[v] Cos[u], 4/5 ζ[v] Sin[u], v},
{24/25 η[v] Cos[u], 1/2 η[-2 v] Sin[u],v - 1/6}},
{u, 0, 2 π}, {v, -1, 1},
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1.2}}, Mesh -> None,
PlotStyle -> Directive[Yellow, Specularity[White, 20]]],
Graphics3D[
@celestialphineas
celestialphineas / circle.m
Created October 3, 2017 13:00
Draw a circle using Bresenham’s algorithm
r = 10;
it[{x_, y_}] :=
If[2 (r^2 - x^2 - y^2) - 4 x + 2 y - 3 > 0, {x + 1, y}, {x + 1,
y - 1}];
oct = NestWhileList[it, {0, r}, #[[1]] <= #[[2]] &][[1 ;; -2]];
showMatPlot[points_List] :=
MatrixPlot@SparseArray[# + {r + 1, r + 1} -> 1 & /@ points]
showMatPlot[
Join[oct, # /. {{x_, y_} -> {y, x}} & /@
oct, # /. {{x_, y_} -> {x, -y}} & /@
@celestialphineas
celestialphineas / circle.c
Created October 3, 2017 13:02
Efficiency testing between Bresenham’s and floating point methods
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
void write_pixel(int a, int b)
{
int *k = (int*)malloc(2 * sizeof(int));
k[0] = a; k[1] = b;
free(k);
F[x_] := NumberForm[HarmonicNumber[x]/x, 20]
str = StringJoin[
ToString[#] <> "\n" & /@ ({N[\[Pi]^2/6, 13]}~Join~
Table[F[i], {i, 0.1, 300, 0.1}])];
Export["D:\\na\\mma.txt", str]
1.644934066848
1.534607244905
1.440878841547
1.360082586782
1.289577800791
1.227411277760
1.172105196125
1.122519342536
1.077758872744
1.037110917851
#include <stdio.h>
void Series_Sum(double sum[]);
int main()
{
int i;
double x, sum[3001];
Series_Sum( sum );
@celestialphineas
celestialphineas / traffic.cpp
Created October 25, 2017 11:05
Simulation of traffic scheduling on a crossroad with multiple threads (OS lab)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <unistd.h>
#include <pthread.h>
#include <algorithm>
// #define TEST_OUTPUT
#include <stdio.h>
#include <string.h>
void Series_Sum(double sum[]);
int main(void)
{
int i;
double x, sum[3001];
memset((void*)sum, 0xffffffff, sizeof(sum));
#include <stdio.h>
void Series_Sum(double sum[]);
int main(void)
{
int i;
double x, sum[3001];
Series_Sum(sum);