41223108 cp2023

  • Home
    • SMap
    • reveal
    • blog
  • About
  • 倉儲維護
    • s.cycu.org維護
    • windows維護
  • weekly progress
    • w1~4
    • w5
    • w6
    • w7
    • w9
    • w12
      • helloworld
      • GD繪圖程式1
    • W13
    • w15
  • ANSIC
    • 1.
    • 2.
    • 3.
    • 4.
    • 5.
    • 6.
    • 7.
    • 8.
    • 9.
    • 10.
  • NOTE
    • ssh
    • puttygen
  • 國旗練習
    • Thai
    • Laos
    • Bangladesh
    • vietnam
    • Italian
    • Russia
    • Belgium
    • Ukraine
    • Korea
  • 課程評分
  • Brython
  • setup
  • C_lib
  • replit
  • MSD
  • Final
C_lib << Previous Next >> MSD

replit

https://docs.replit.com/

w8: 為了強化保全, Replit 目前只能透過 Gmail 或 Github 帳號登入, 無法直接利用帳號與密碼登入.

請注意: 原本 Replit Python 3.8 虛擬環境的目錄為 venv, 但是 Python 3.10 虛擬環境的目錄已經改用 .pythonlibs, 因此倉儲若不希望帶著此一虛擬環境檔案, 則可以將 .pythonlibs 附加到 .gitignore

另外在近端必須處理 Python 3.12.0 版本中的 https://docs.python.org/3/library/ssl.html 

1
2
3
httpd.socket = ssl.wrap_socket(httpd.socket,
                   ^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'

將 GitHub cmsimde 倉儲導入 Replit 的方法, 請參考 https://mde.tw/cadnote/content/Replit.html 中的說明.

備註:建立 yengm (at gm.nfu) 帳號, for Replit Teams for Education.

在 Replit C 程式環境中額外納入 gnuplot 套件的 replit.nix 設定:

1
2
3
4
5
6
7
8
9
10
{ pkgs }: {
    deps = [
        pkgs.sudo
        pkgs.clang_12
        pkgs.ccls
        pkgs.gdb
        pkgs.gnumake
        pkgs.gnuplot
    ];
}

C with gnuplot:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
 
int main() {
    // Open a file to write displacement and velocity data
    FILE *outputFile = fopen("motion_data.txt", "w");
    if (!outputFile) {
        fprintf(stderr, "Failed to create data file.\n");
        return 1;
    }
 
    // Simulate motion for 10 seconds and calculate displacement and velocity, while writing data to the file
    double x = 0.2;  // Initial displacement
    double v = 0.0;  // Initial velocity
    double dt = 0.01; // Time step
    double t = 0.0;  // Time
 
    while (t <= 10.0) {
        double acceleration = (-10.0 * x - 0.5 * v) / 1.0; // Modified system parameters here
        v += acceleration * dt;
        x += v * dt;
 
        fprintf(outputFile, "%lf %lf %lf\n", t, x, v);
 
        t += dt;
    }
 
    // Close the data file
    fclose(outputFile);
 
    // Start a Gnuplot process using popen
    FILE *gnuplotPipe = popen("gnuplot -persistent", "w");
    if (!gnuplotPipe) {
        fprintf(stderr, "Failed to start Gnuplot.\n");
        return 1;
    }
 
    // Use Gnuplot plotting commands, specify font and output as PNG
    fprintf(gnuplotPipe, "set terminal pngcairo enhanced font 'default,10' size 800,400\n");
    fprintf(gnuplotPipe, "set output 'motion_plot.png'\n");
    fprintf(gnuplotPipe, "set title 'Displacement and Velocity vs. Time'\n");
    fprintf(gnuplotPipe, "set xlabel 'Time (s)'\n");
    fprintf(gnuplotPipe, "set ylabel 'Displacement (m)'\n");
    fprintf(gnuplotPipe, "plot 'motion_data.txt' using 1:2 with lines lw 2 title 'Displacement', \
                             'motion_data.txt' using 1:3 with lines lw 2 title 'Velocity'\n");
 
    // Close the Gnuplot process
    fprintf(gnuplotPipe, "exit\n");
    pclose(gnuplotPipe);
 
    return 0;
}

在選擇 Python 作為 Language 的 repl 專案中, cc 已經內建, 若要加裝 gnuplot 套件則可在 replit.nix 設定檔案中加入 pkgs.gnuplot, pkgs.ncurses.dev, pkgs.gd, pkgs.vimHugeX 與 pkgs.raylib:

1
2
3
4
5
6
7
8
9
{ pkgs }: {
    deps = [
      pkgs.gnuplot
      pkgs.ncurses.dev
      pkgs.gd
      pkgs.vimHugeX
      pkgs.raylib
    ];
}

gnuplot: 數值分析繪圖程式庫

gd: 泛用型繪圖程式庫

ncurses: 文字型類 GUI 程式庫

vim: 指令模式編輯器

raylib: 電動遊戲程式庫


C_lib << Previous Next >> MSD

Copyright © All rights reserved | This template is made with by Colorlib