From 1076ff2aa08a4c8b0638b88a62f2922ac6b0b352 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Sat, 21 May 2022 14:03:21 +0900 Subject: [PATCH] Initial commit --- JavaProjectTemplate.jar | Bin 0 -> 8133 bytes README.md | 27 +++ scripts/build.sh | 9 + scripts/clean.sh | 4 + scripts/commit.sh | 13 ++ scripts/jar.sh | 16 ++ scripts/lean.sh | 1 + scripts/md5 | 5 + sig | 8 + src/sig/JavaProjectTemplate.java | 21 +++ src/sig/engine/Color.java | 38 ++++ src/sig/engine/Edge.java | 33 ++++ src/sig/engine/Panel.java | 314 +++++++++++++++++++++++++++++++ src/sig/engine/Point.java | 32 ++++ utils/.coauthors | 1 + utils/.updateDirectories | 3 + utils/define.sh | 23 +++ utils/main.sh | 28 +++ utils/md5 | 5 + utils/search.sh | 77 ++++++++ 20 files changed, 658 insertions(+) create mode 100644 JavaProjectTemplate.jar create mode 100644 README.md create mode 100755 scripts/build.sh create mode 100755 scripts/clean.sh create mode 100755 scripts/commit.sh create mode 100755 scripts/jar.sh create mode 100644 scripts/lean.sh create mode 100644 scripts/md5 create mode 100755 sig create mode 100644 src/sig/JavaProjectTemplate.java create mode 100644 src/sig/engine/Color.java create mode 100644 src/sig/engine/Edge.java create mode 100644 src/sig/engine/Panel.java create mode 100644 src/sig/engine/Point.java create mode 100644 utils/.coauthors create mode 100644 utils/.updateDirectories create mode 100755 utils/define.sh create mode 100644 utils/main.sh create mode 100644 utils/md5 create mode 100644 utils/search.sh diff --git a/JavaProjectTemplate.jar b/JavaProjectTemplate.jar new file mode 100644 index 0000000000000000000000000000000000000000..94a1432a3a4fe37eed6dfa6e29c1765f4fe7107b GIT binary patch literal 8133 zcmb7J1yCK^vc-bCI{|__1a}DT?j#52;I6@f1a}V*?BEdGCAho0yL;dOKY925cXMz3 z_o{wRP1RIQckiA(-MzckQkH{;!G?f`hlk+Es#J&gO%NbpAQU9jMVVw2C0U*aAt0b3 zl;z;ye`!Gdsi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>VTjwCdEDZ(`-1FxbO%a{hz z7_1tY(d|oH)VPPkIyNjA>*={otLR5$tMc;|#XPKX4OPQorQn$p7=UT5&cqV3edN~% z`{vHj(1d0#c@AoQ0Ob9Kp5@n0^#mwvgl5h#lzftG6yyBnI#DOnrZzIX44Mm3_iT6~ zl6?ZWg+T^S4rYAc)Hb>{i|Kju7WrWy-zV(7w#b8X11INIi&3X>Mhd5m^j0y-=muB> ze*4T170o*^U-bniw333-jg7hM$jXY)CUWT5IwoIumYcy49=U9YGqG|w&N-846w#rM zQlSr5`ejbG`g&ySteObL%|nsbKa_-Mr+zkJZ*s7SRxV0oZSvf&Ty3;!mJ0~wIr~;a zP%W{ptT2IlLSHIkR`yi3T3_S#-O-2Q>WFp{?rFKU=N>GD`%N{niHz6x5t-EB=67YG5aFVjpUOFFHgn zkzBiXZuvGR*DnEvmNc<8&}?03;KxL0N^^+-Fb*+37{v{E2#10a25Y&iS*mMso`(6) zhAQU9r|+74;wB5oa{ynS1z7##d3I{kB|r15Bje0VtZ#`SK*5j)K*R8f-XraFdtGAN ziu&A5vk}e&>TO#t(+pNtY3DdbtyAbWGGpjJ|7!>e5Q67``&mV`|7zBdP}mTEuciOx zQh(8{f0uvrr@zQoWx2nb{!VZHB3u6w!Jm)+HvNry{pA4>;y=@%e|gyX`S=GZ`u8<| zr?-C5qJIe-{f {args} + + ==== Current Configuration ===================== + PROJECT_NAME JavaProjectTemplate + PROJECT_DIR src/sig + MAIN_CLASS sig.JavaProjectTemplate + OUT_DIR bin + ===================================================== + + Command List: + + build Builds and runs the project. + clean Cleans up and removes unused files. + commit Adds a commit message and pushes project to github repository. + jar Builds a runnable jar file using ${MAIN_CLASS} as an entry point and then runs the newly generated jar. +``` +Configuration is modified at the top of the script file while the command list includes all included modules inside of `scripts`. diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..bdcd96d --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,9 @@ +#Builds and runs the project. +#Java +rm -Rf out/* +javac -Xlint:unchecked -cp ${PROJECT_DIR}/.. -d ${OUT_DIR} ${PROJECT_DIR}/*.java +printf "\n\n\nRunning Program...\n\n" +ORIGINAL_LOC=$(pwd) +cd $OUT_DIR +java ${MAIN_CLASS} "$@" +${ORIGINAL_LOC}/scripts/clean.sh \ No newline at end of file diff --git a/scripts/clean.sh b/scripts/clean.sh new file mode 100755 index 0000000..55f2398 --- /dev/null +++ b/scripts/clean.sh @@ -0,0 +1,4 @@ +#Cleans up and removes unused files. +#Java +find . -type f -name *.class -delete +find . -type f -name manifest -delete \ No newline at end of file diff --git a/scripts/commit.sh b/scripts/commit.sh new file mode 100755 index 0000000..6c49768 --- /dev/null +++ b/scripts/commit.sh @@ -0,0 +1,13 @@ +#Adds a commit message and pushes project to github repository. +#Java +COMMIT_MESSAGE="$*" +while IFS= read -r line +do + COMMIT_MESSAGE+=" + +Co-authored-by: $line" +done < utils/.coauthors +git add -u +git add * +git commit -m "$COMMIT_MESSAGE" +git push \ No newline at end of file diff --git a/scripts/jar.sh b/scripts/jar.sh new file mode 100755 index 0000000..441b43b --- /dev/null +++ b/scripts/jar.sh @@ -0,0 +1,16 @@ +#Builds a runnable jar file using ${MAIN_CLASS} as an entry point and then runs the newly generated jar. +#Java +rm -Rf bin/* +javac -Xlint:unchecked -cp src -d bin ${PROJECT_DIR}/${PROJECT_NAME}.java +printf "\n\n\nGenerating Manifest...\n\n" +touch manifest +echo "Main-Class: ${MAIN_CLASS}" >> manifest +printf "\n\n\nCreating Jar...\n\n" +ORIGINAL_LOC=$(pwd) +cd ${OUT_DIR} +jar cfm ${PROJECT_NAME}.jar ${ORIGINAL_LOC}/manifest sig +printf "\n\n\nRunning Program...\n\n" +java -jar ${PROJECT_NAME}.jar +mv ${PROJECT_NAME}.jar ${ORIGINAL_LOC} +cd .. +./scripts/clean.sh \ No newline at end of file diff --git a/scripts/lean.sh b/scripts/lean.sh new file mode 100644 index 0000000..1becba2 --- /dev/null +++ b/scripts/lean.sh @@ -0,0 +1 @@ +404: Not Found \ No newline at end of file diff --git a/scripts/md5 b/scripts/md5 new file mode 100644 index 0000000..c4273a3 --- /dev/null +++ b/scripts/md5 @@ -0,0 +1,5 @@ +build.sh:a833e7598ad65672a9c01306d244b49f - +clean.sh:96ce35f2d2dcb555421e00a6afda23ca - +commit.sh:21af1fa6f09d01679c9e11408967264a - +jar.sh:2ac636f584c43a1124affb9ea6bdc7bf - +lean.sh:3be7b8b182ccd96e48989b4e57311193 - diff --git a/sig b/sig new file mode 100755 index 0000000..5f8d83f --- /dev/null +++ b/sig @@ -0,0 +1,8 @@ +source utils/define.sh + +define PROJECT_NAME "JavaProjectTemplate" +define PROJECT_DIR "src/sig" +define MAIN_CLASS "sig.${PROJECT_NAME}" +define OUT_DIR "bin" + +source utils/main.sh \ No newline at end of file diff --git a/src/sig/JavaProjectTemplate.java b/src/sig/JavaProjectTemplate.java new file mode 100644 index 0000000..ac5ae34 --- /dev/null +++ b/src/sig/JavaProjectTemplate.java @@ -0,0 +1,21 @@ +package sig; + +import javax.swing.JFrame; +import sig.engine.Panel; + +public class JavaProjectTemplate { + public static final String PROGRAM_NAME="Sig's Java Project Template"; + public static void main(String[] args) { + JFrame f = new JFrame(PROGRAM_NAME); + Panel p = new Panel(f); + + p.init(); + + f.add(p); + f.setSize(1280,720); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setVisible(true); + + p.render(); + } +} diff --git a/src/sig/engine/Color.java b/src/sig/engine/Color.java new file mode 100644 index 0000000..3a6bde7 --- /dev/null +++ b/src/sig/engine/Color.java @@ -0,0 +1,38 @@ +package sig.engine; + +public class Color { + int r,g,b,a; + + final static public Color BLACK = new Color(0,0,0); + final static public Color RED = new Color(204,0,0); + final static public Color GREEN = new Color(78,154,6); + final static public Color YELLOW = new Color(196,160,0); + final static public Color BLUE = new Color(114,159,207); + final static public Color MAGENTA = new Color(117,80,123); + final static public Color CYAN = new Color(6,152,154); + final static public Color WHITE = new Color(211,215,207); + final static public Color BRIGHT_BLACK = new Color(85,87,83); + final static public Color BRIGHT_RED = new Color(239,41,41); + final static public Color BRIGHT_GREEN = new Color(138,226,52); + final static public Color BRIGHT_YELLOW = new Color(252,233,79); + final static public Color BRIGHT_BLUE = new Color(50,175,255); + final static public Color BRIGHT_MAGENTA = new Color(173,127,168); + final static public Color BRIGHT_CYAN = new Color(52,226,226); + final static public Color BRIGHT_WHITE = new Color(255,255,255); + + public Color(int r, int g, int b) { + this(r,g,b,255); + } + + public Color(int r, int g, int b,int a) { + super(); + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + + public int getColor() { + return (a<<24)+(r<<16)+(g<<8)+b; + } +} diff --git a/src/sig/engine/Edge.java b/src/sig/engine/Edge.java new file mode 100644 index 0000000..867937e --- /dev/null +++ b/src/sig/engine/Edge.java @@ -0,0 +1,33 @@ +package sig.engine; + +public class Edge { + Point a,b; + int min_y; + int max_y; + int min_x; + int max_x; + double x_of_min_y; + double inverse_slope; + public Edge(Point a, Point b) { + super(); + this.a = a; + this.b = b; + min_y=Math.min(a.y, b.y); + max_y=Math.max(a.y, b.y); + min_x=Math.min(a.x, b.x); + max_x=Math.max(a.x, b.x); + if (a.y==min_y) { + x_of_min_y=a.x; + } else { + x_of_min_y=b.x; + } + + inverse_slope=(double)(a.x-b.x)/(a.y-b.y); + } + @Override + public String toString() { + return "Edge [a=" + a + ", b=" + b + ", min_y=" + min_y + ", max_y=" + max_y + ", min_x=" + min_x + ", max_x=" + + max_x + ", x_of_min_y=" + x_of_min_y + ", inverse_slope=" + inverse_slope + "]"; + } + +} diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java new file mode 100644 index 0000000..2f558f7 --- /dev/null +++ b/src/sig/engine/Panel.java @@ -0,0 +1,314 @@ +package sig.engine; +import java.awt.Graphics; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsEnvironment; +import java.awt.Image; +import java.awt.Toolkit; +import java.awt.image.ColorModel; +import java.awt.image.MemoryImageSource; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +import sig.JavaProjectTemplate; + +public class Panel extends JPanel implements Runnable { + JFrame window; + public int pixel[]; + public int width=1280; + public int height=720; + final int CIRCLE_PRECISION=32; + final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor(); + private Thread thread; + private Image imageBuffer; + private MemoryImageSource mImageProducer; + private ColorModel cm; + int scanLine=0; + int nextScanLine=0; + double x_offset=0; + double y_offset=0; + int frameCount=0; + long lastSecond=0; + int lastFrameCount=0; + + public Panel(JFrame f) { + super(true); + this.window=f; + thread = new Thread(this, "MyPanel Thread"); + } + + /** + * Get Best Color model available for current screen. + * @return color model + */ + protected static ColorModel getCompatibleColorModel(){ + GraphicsConfiguration gfx_config = GraphicsEnvironment. + getLocalGraphicsEnvironment().getDefaultScreenDevice(). + getDefaultConfiguration(); + return gfx_config.getColorModel(); + } + + /** + * Call it after been visible and after resizes. + */ + public void init(){ + cm = getCompatibleColorModel(); + int screenSize = width * height; + if(pixel == null || pixel.length < screenSize){ + pixel = new int[screenSize]; + } + if(thread.isInterrupted() || !thread.isAlive()){ + thread.start(); + } + mImageProducer = new MemoryImageSource(width, height, cm, pixel,0, width); + mImageProducer.setAnimated(true); + mImageProducer.setFullBufferUpdates(true); + imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); + } + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + // perform draws on pixels + render(); + // ask ImageProducer to update image + mImageProducer.newPixels(); + // draw it on panel + g.drawImage(this.imageBuffer, 0, 0, this); + + + if (window!=null&&System.currentTimeMillis()-lastSecond>=1000) { + window.setTitle(JavaProjectTemplate.PROGRAM_NAME+" - FPS: "+(frameCount-lastFrameCount)); + lastFrameCount=frameCount; + lastSecond=System.currentTimeMillis(); + } + frameCount++; + } + + /** + * Overrides ImageObserver.imageUpdate. + * Always return true, assuming that imageBuffer is ready to go when called + */ + @Override + public boolean imageUpdate(Image image, int a, int b, int c, int d, int e) { + return true; + } + /** + * Do your draws in here !! + * pixel is your canvas! + */ + public /* abstract */ void render(){ + int[] p = pixel; // this avoid crash when resizing + //a=h/w + + for (int x=0;x edges_sorted = new ArrayList(); + for (int i=0;i=edges[i].min_y) { + edges_sorted.add(j,edges[i]); + inserted=true; + break; + } + } + if (!inserted) { + edges_sorted.add(edges[i]); + } + } + } + } + //System.out.println(edges_sorted); + List active_edges = new ArrayList(); + scanLine = edges_sorted.get(0).min_y-1; + nextScanLine = scanLine+1; + do { + for (int i=0;i=0) { + Draw(p,index,col.getColor()); + } + } + } + List new_active_edges = new ArrayList(); + for (int i=0;ie.x_of_min_y) { + new_active_edges.add(j,e); + inserted=true; + break; + } + } + if (!inserted) { + new_active_edges.add(e); + } + } + active_edges=new_active_edges; + GetNextScanLineEdges(edges_sorted, active_edges); + } + while (active_edges.size()>0); + } + + private void GetNextScanLineEdges(List edges_sorted, List active_edges) { + if (scanLine==nextScanLine) { + for (int i=0;iscanLine) { + nextScanLine=e.min_y; + break; + } + } + } + } + + public void Draw(int[] canvas,int index, int col) { + int alpha = col>>>24; + if (alpha==0) { + return;} + else + if (alpha==255) { + canvas[index]=col; + } else { + float ratio=alpha/255f; + int prev_col=canvas[index]; + int prev_r=(prev_col&0xFF); + int prev_g=(prev_col&0xFF00)>>>8; + int prev_b=(prev_col&0xFF0000)>>>16; + int r=(col&0xFF); + int g=(col&0xFF00)>>>8; + int b=(col&0xFF0000)>>>16; + + int new_r=(int)(ratio*r+(1-ratio)*prev_r); + int new_g=(int)(ratio*g+(1-ratio)*prev_g); + int new_b=(int)(ratio*b+(1-ratio)*prev_b); + + canvas[index]=new_r+(new_g<<8)+(new_b<<16)+(col&0xFF000000); + } + } + + @Override + public void run() { + while (true) { + // request a JPanel re-drawing + repaint(); + //System.out.println("Repaint "+frameCount++); + //try {Thread.sleep(1);} catch (InterruptedException e) {} + } + } +} \ No newline at end of file diff --git a/src/sig/engine/Point.java b/src/sig/engine/Point.java new file mode 100644 index 0000000..b848018 --- /dev/null +++ b/src/sig/engine/Point.java @@ -0,0 +1,32 @@ +package sig.engine; + +public class Point { + int x,y; + + public Point(int x, int y) { + super(); + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + + @Override + public String toString() { + return "Point(" + x + "," + y + ")"; + } +} diff --git a/utils/.coauthors b/utils/.coauthors new file mode 100644 index 0000000..b904d0f --- /dev/null +++ b/utils/.coauthors @@ -0,0 +1 @@ +sigonasr2 diff --git a/utils/.updateDirectories b/utils/.updateDirectories new file mode 100644 index 0000000..e4dde11 --- /dev/null +++ b/utils/.updateDirectories @@ -0,0 +1,3 @@ +Java/ +scripts/ +utils/ \ No newline at end of file diff --git a/utils/define.sh b/utils/define.sh new file mode 100755 index 0000000..0926c6c --- /dev/null +++ b/utils/define.sh @@ -0,0 +1,23 @@ +export VARS=("") + +function define() { + VARS+=("$1") + value="${*:2}" + eval export "$1"='$value' +} + +if [[ $(pwd) != *"SigScript" ]]; then + source utils/search.sh + + find . -type f -name md5 -delete + + #Check for hashes + FILES=$(cat utils/.updateDirectories) + for f in $FILES + do + search $f + check $f + done +else + echo "Dev build, no checks required." +fi \ No newline at end of file diff --git a/utils/main.sh b/utils/main.sh new file mode 100644 index 0000000..645950d --- /dev/null +++ b/utils/main.sh @@ -0,0 +1,28 @@ +if [ -z "$1" ] + then + echo "" + echo " Usage: ./sig {args}" + echo "" + printf "====\tCurrent Configuration" + printf "\t=====================" + for t in ${VARS[@]} + do + printf "\n\t%-15s%20s" $t ${!t} + done + printf "\n=====================================================" + echo "" + echo "" + echo " Command List:" + FILES=$(ls -1A ./scripts | sed -e 's/\.sh$//' | sed -e 's/^/ /') + for f in $FILES + do + if [ $f != "md5" ]; then + DESC="$(head -n1 ./scripts/$f.sh)" + printf "\n\t%-15s%-65s" $f "${DESC:1}" + fi + done + echo "" + exit +fi + +./scripts/$1.sh "${*:2}" \ No newline at end of file diff --git a/utils/md5 b/utils/md5 new file mode 100644 index 0000000..715e752 --- /dev/null +++ b/utils/md5 @@ -0,0 +1,5 @@ +.coauthors:3785ad38663e5fc43e574914ad067294 - +define.sh:d6b20a25a04a60d94f466e48fa60ac69 - +main.sh:32a1f953ffca8584d1eb57c0ecd8a582 - +search.sh:28d0ede8345514d80cc68cc756870002 - +.updateDirectories:0ede00461e947494545e694040787b3f - diff --git a/utils/search.sh b/utils/search.sh new file mode 100644 index 0000000..5392df5 --- /dev/null +++ b/utils/search.sh @@ -0,0 +1,77 @@ +function search() { + FILES2=$(ls -A $1) + for g in $FILES2 + do + if [ -d $1$g ]; + then + echo "$1$g is a directory" + search $1$g/ + else + echo "$1$g is a file" + if [ $g != "md5" ]; then + SUM=$(md5sum < $1$g) + echo "$g:$SUM" >> $1md5 + else + echo " md5 file, ignoring..." + fi + fi + done +} + +function check() { + echo "Check $1" + FILES2=$(ls -A $1) + if [ -f "$1/md5" ]; + then + echo " md5: https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1md5" + curl -H 'Cache-Control: no-cache, no-store' -s https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1md5 --output /tmp/out + cmp -s $1/md5 /tmp/out + if [ "$?" -ne 0 ] + then + echo " Differences detected!" + cat /tmp/out + while IFS= read -r line + do + IFS=':' read -ra split <<< $line + g="${split[0]}" + if [ "$g" != "md5" ]; then + if [ -f $1$g ]; + then + echo "++Redownload $1$g..." + if [ -f "$1$g" ]; then + #Read the 2nd line and see if it has a special directory. + CHECKLINE=$(sed -n '2{p;q;}' $1$g) + if [ "${CHECKLINE:0:1}" = "#" ]; then + #This could be a different diff, try that one. + echo " md5: https://raw.githubusercontent.com/sigonasr2/SigScript/main/${CHECKLINE:1}/$1md5" + curl -H 'Cache-Control: no-cache, no-store' -s https://raw.githubusercontent.com/sigonasr2/SigScript/main/${CHECKLINE:1}/$1md5 --output /tmp/out + cmp -s $1/md5 /tmp/out + if [ "$?" -ne 0 ] + then + echo " Differences detected here too." + curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/${CHECKLINE:1}/$1$g --output $1$g + fi + else + curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g + fi + else + echo "===Could not find directory, assuming regular scripts directory exists." + curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output scripts/$g + fi + else + echo "++==Downloading $1$g..." + curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g + fi + fi + done < /tmp/out + fi + fi + for g in $FILES2 + do + if [ -d $1$g ]; + then + echo "$1$g is a directory" + check $1$g/ + fi + done +} \ No newline at end of file