Skip to content

Instantly share code, notes, and snippets.

View Reine0017's full-sized avatar
❤️

Fang Ran Reine0017

❤️
View GitHub Profile
@Reine0017
Reine0017 / sketch.js
Last active July 13, 2022 04:37
Simple Drawing app - sketch.js (1)
window.addEventListener("load", () => {
const canvas = document.querySelector("#canvas");
const ctx = canvas.getContext('2d');
const img = new Image();
img.src = "assets/images/reinePic.jpg";
img.onload = () => {
const [img_scaled_width, img_scaled_height] = drawImageToScale(img, ctx);
canvas.width = img_scaled_width;
@Reine0017
Reine0017 / index.html
Last active April 27, 2020 22:01
Simple Drawing app - index.html (with control buttons)
<body>
<div id="drawingComp">
<canvas id="canvas"></canvas>
<div class="controls">
<label id="clearLabel"><button id="clear">X</button> Clear</label>
<label id="blackColourLabel"><button id="blackColour">O</button> Black Colour</label>
<label id="whiteColourLabel"><button id="whiteColour">O</button> White Colour</label>
</div>
</div>
@Reine0017
Reine0017 / sketch.js
Created April 27, 2020 22:03
Simple Drawing app - sketch.js (2 - with control buttons)
window.addEventListener("load", () => {
const clearButton = document.querySelector('#clear');
const blackButton = document.querySelector('#blackColour');
const whiteButton = document.querySelector('#whiteColour');
const canvas = document.querySelector("#canvas");
const ctx = canvas.getContext('2d');
const img = new Image();
img.src = "assets/images/reinePic.jpg";
@Reine0017
Reine0017 / sketch.css
Created April 27, 2020 22:05
Simple Drawing app - sketch.css
*{
margin:0;
padding:0;
box-sizing: border-box;
}
#drawingComp {
display:flex;
align-items:center;
}
@Reine0017
Reine0017 / Example.js
Created April 28, 2020 12:40
React "Hello World Counter" Example.js
import React, { useState } from "react";
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
@Reine0017
Reine0017 / App.js
Created April 28, 2020 12:48
React "Hello World Counter" App.js
import React from "react";
import logo from "./logo.svg";
import "./App.css";
import Example from "./Example";
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
@Reine0017
Reine0017 / part of app.py
Last active May 10, 2020 11:29
@app.route("/upload", methods=['POST']) in app.py
@app.route("/upload", methods=['POST'])
def upload():
target = os.path.join(APP_ROOT, 'images/')
print("TARGET", target)
if not os.path.isdir(target):
os.mkdir(target)
else:
print("Couldn't create upload directory: {}".format(target))
import json
from urllib.request import urlopen
import requests
import urllib.request
import igraph as ig
import chart_studio.plotly as py
from plotly.offline import iplot
import plotly.graph_objs as go
@Reine0017
Reine0017 / Generate graph and prepare x,y,z
Created November 10, 2020 04:28
Generate the graphs and plot with kk layout + prepare Xe, Ye, Ze and Xn, Yn, Zn
G=ig.Graph(Edges, directed=False)
layt=G.layout('kk', dim=3) # plot network with the Kamada-Kawai layout algorithm
print(G)
print(layt[:3])
print(Edges[:3])
labels=[]
group=[]
for node in data['nodes']:
@Reine0017
Reine0017 / Scatter plot and visualize the figure
Created November 10, 2020 04:47
Scatter plot and visualize the figure
trace1=go.Scatter3d(x=Xe, y=Ye, z=Ze, mode='lines', line=dict(color='rgb(125,125,125)', width=1),hoverinfo='none')
trace2=go.Scatter3d(x=Xn, y=Yn, z=Zn, mode='markers', name='actors',
marker=dict(symbol='circle', size=6, color=group, colorscale='Viridis',
line=dict(color='rgb(50,50,50)', width=0.5)), text=labels, hoverinfo='text')
axis=dict(showbackground=False, showline=False, zeroline=False, showgrid=False, showticklabels=False, title='')
layout = go.Layout(
title="Network of coappearances of characters in Victor Hugo's novel<br> Les Miserables (3D visualization)",