Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,19 @@
#include<graphics.h>
#include<iostream>
int main()
{
int k;
initwindow(1500,810,"Rosetta Cuboid");
do{
std::cout<<"Enter ratio of sides ( 0 or -ve to exit) : ";
std::cin>>k;
if(k>0){
bar3d(100, 100, 100 + 2*k, 100 + 4*k, 3*k, 1);
}
}while(k>0);
return 0;
}

View file

@ -0,0 +1,37 @@
defmodule Cuboid do
@x 6
@y 2
@z 3
@dir %{-: {1,0}, |: {0,1}, /: {1,1}}
def draw(nx, ny, nz) do
IO.puts "cuboid #{nx} #{ny} #{nz}:"
{x, y, z} = {@x*nx, @y*ny, @z*nz}
area = Map.new
area = Enum.reduce(0..nz-1, area, fn i,acc -> draw_line(acc, x, 0, @z*i, :-) end)
area = Enum.reduce(0..ny, area, fn i,acc -> draw_line(acc, x, @y*i, z+@y*i, :-) end)
area = Enum.reduce(0..nx-1, area, fn i,acc -> draw_line(acc, z, @x*i, 0, :|) end)
area = Enum.reduce(0..ny, area, fn i,acc -> draw_line(acc, z, x+@y*i, @y*i, :|) end)
area = Enum.reduce(0..nz-1, area, fn i,acc -> draw_line(acc, y, x, @z*i, :/) end)
area = Enum.reduce(0..nx, area, fn i,acc -> draw_line(acc, y, @x*i, z, :/) end)
Enum.each(y+z..0, fn j ->
IO.puts Enum.map(0..x+y, fn i -> Dict.get(area, {i,j}, " ") end) |> Enum.join
end)
end
defp draw_line(area, n, sx, sy, c) do
{dx, dy} = Dict.get(@dir, c)
draw_line(area, n, sx, sy, c, dx, dy)
end
defp draw_line(area, n, _, _, _, _, _) when n<0, do: area
defp draw_line(area, n, i, j, c, dx, dy) do
area2 = Dict.update(area, {i,j}, c, fn _ -> :+ end)
draw_line(area2, n-1, i+dx, j+dy, c, dx, dy)
end
end
Cuboid.draw(2,3,4)
Cuboid.draw(1,1,1)
Cuboid.draw(2,4,1)
Cuboid.draw(4,2,1)

View file

@ -1,30 +1,92 @@
import java.awt.*;
import java.awt.event.*;
import static java.lang.Math.*;
import javax.swing.*;
public class Cuboid extends JFrame {
public class Cuboid extends JPanel {
double[][] nodes = {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1},
{1, -1, -1}, {1, -1, 1}, {1, 1, -1}, {1, 1, 1}};
public static void main(String[] args) {
JFrame f = new Cuboid();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
int[][] edges = {{0, 1}, {1, 3}, {3, 2}, {2, 0}, {4, 5}, {5, 7}, {7, 6},
{6, 4}, {0, 4}, {1, 5}, {2, 6}, {3, 7}};
int mouseX, prevMouseX, mouseY, prevMouseY;
public Cuboid() {
Container content = getContentPane();
content.setLayout(new BorderLayout());
content.add(new CuboidPanel(), BorderLayout.CENTER);
setTitle("Cuboid");
setResizable(false);
pack();
setLocationRelativeTo(null);
}
}
class CuboidPanel extends JPanel {
public CuboidPanel() {
setPreferredSize(new Dimension(600, 500));
setPreferredSize(new Dimension(640, 640));
setBackground(Color.white);
scale(80, 120, 160);
rotateCube(PI / 5, PI / 9);
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
mouseX = e.getX();
mouseY = e.getY();
}
});
addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
prevMouseX = mouseX;
prevMouseY = mouseY;
mouseX = e.getX();
mouseY = e.getY();
double incrX = (mouseX - prevMouseX) * 0.01;
double incrY = (mouseY - prevMouseY) * 0.01;
rotateCube(incrX, incrY);
repaint();
}
});
}
private void scale(double sx, double sy, double sz) {
for (double[] node : nodes) {
node[0] *= sx;
node[1] *= sy;
node[2] *= sz;
}
}
private void rotateCube(double angleX, double angleY) {
double sinX = sin(angleX);
double cosX = cos(angleX);
double sinY = sin(angleY);
double cosY = cos(angleY);
for (double[] node : nodes) {
double x = node[0];
double y = node[1];
double z = node[2];
node[0] = x * cosX - z * sinX;
node[2] = z * cosX + x * sinX;
z = node[2];
node[1] = y * cosY - z * sinY;
node[2] = z * cosY + y * sinY;
}
}
void drawCube(Graphics2D g) {
g.translate(getWidth() / 2, getHeight() / 2);
for (int[] edge : edges) {
double[] xy1 = nodes[edge[0]];
double[] xy2 = nodes[edge[1]];
g.drawLine((int) round(xy1[0]), (int) round(xy1[1]),
(int) round(xy2[0]), (int) round(xy2[1]));
}
for (double[] node : nodes) {
g.fillOval((int) round(node[0]) - 4, (int) round(node[1]) - 4, 8, 8);
}
}
@Override
@ -34,13 +96,19 @@ class CuboidPanel extends JPanel {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.translate(165, -80);
drawCube(g);
}
g.drawRect(50, 275, 100, 100);
g.drawLine(50, 275, 130, 240);
g.drawLine(150, 275, 210, 240);
g.drawLine(130, 240, 210, 240);
g.drawLine(210, 240, 210, 340);
g.drawLine(150, 375, 210, 340);
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("Cuboid");
f.setResizable(false);
f.add(new Cuboid(), BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
});
}
}

View file

@ -0,0 +1,27 @@
Call cuboid 1,3,4
End
Sub cuboid width, height, depth
wd=width*7+2: hi=height*3: dp=depth
For i=1 To wd-2
w$=w$+"-":h$=h$+" "
Next
w$="+"+w$+"+":d$="/"+h$+"/":h$="|"+h$+"|"
px=dp+2:py=1:Locate dp+2,py:Print w$;
For i=2 To hi+1
Locate wd+dp+1,i:Print"|";
Next
Locate wd+dp+1, i: Print "+";
For i=dp+1 To 1 Step -1
py=py+1:Locate i,py:Print d$;
Next
For i=1 To dp
Locate wd+(dp+1)-i,hi+d+2+i:Print "/";
Next
Locate 1, dp+2: Print w$;
For i=dp+3 To hi+dp+2
Locate 1,i:Print h$;
Next
Locate 1, dp+hi+3: Print w$
End Sub

View file

@ -0,0 +1,59 @@
NoMainWin
Global sw, sh
sw = 400: sh = 400
WindowWidth = sw+6
WindowHeight= sh+32
Open "[RC] Draw Cuboid" For graphics_nsb_nf As #g
#g "Down; Fill black; TrapClose [xit]"
#g "when leftButtonDown [xit]"
Call drawCuboid 3,4,5
Wait
[xit]
Close #g
End
Sub drawCuboid width, height, depth
wd = width*50
ht = height*50
dp = depth*20
sx = Int((sw-(wd+dp))/2)
sy = Int((sh-(ht-dp))/2)
#g "Color 0 128 255; BackColor 0 128 255"
#g "Place ";sx;" ";sy
#g "boxFilled ";sx+wd;" ";sy+ht
x1 = sx+dp : y1 = sy-dp
x2 = x1+wd-1 : y2 = y1+1
#g "Color 0 64 128"
Call triFill sx,sy, x1,y1, x2,y2
Call triFill sx,sy, x2,y2, sx+wd, sy
#g "Color 0 96 192"
x3 = x2: y3 = y2+ht
Call triFill x2,y2, x3,y3, sx+wd-1, sy+ht-1
Call triFill x2,y2, sx+wd-1, sy+ht-1, sx+wd-1, sy
#g "Color white;BackColor black;Place 5 20"
#g "\Size: ";width;", ";height;", ";depth
End Sub
Sub triFill x1,y1, x2,y2, x3,y3
If x2<x1 Then x=x2: y=y2: x2=x1: y2=y1: x1=x: y1=y
If x3<x1 Then x=x3: y=y3: x3=x1: y3=y1: x1=x: y1=y
If x3<x2 Then x=x3: y=y3: x3=x2: y3=y2: x2=x: y2=y
If x1<>x3 Then slope1=(y3-y1)/(x3-x1)
length=x2-x1
If length<>0 Then
slope2=(y2-y1)/(x2-x1)
For x = 0 To length
#g "Line ";Int(x+x1);" ";Int(x*slope1+y1);" ";Int(x+x1);" ";Int(x*slope2+y1)
Next
End If
y = length*slope1+y1 :length=x3-x2
If length<>0 Then
slope3=(y3-y2)/(x3-x2)
For x = 0 To length
#g "Line ";Int(x+x2);" ";Int(x*slope1+y);" ";Int(x+x2);" ";Int(x*slope3+y2)
Next
End If
End Sub

View file

@ -0,0 +1,21 @@
#N canvas 1 51 450 300 10;
#X obj 66 67 gemwin;
#X obj 239 148 cuboid 2 3 4;
#X obj 239 46 gemhead;
#X obj 239 68 scale 0.3;
#X msg 66 45 lighting 1 \, create \, 1;
#X obj 61 118 gemhead;
#X obj 61 140 world_light;
#X msg 294 90 1;
#X obj 239 90 t a b;
#X obj 239 118 accumrotate;
#X connect 2 0 3 0;
#X connect 3 0 8 0;
#X connect 4 0 0 0;
#X connect 5 0 6 0;
#X connect 7 0 9 1;
#X connect 7 0 9 2;
#X connect 7 0 9 3;
#X connect 8 0 9 0;
#X connect 8 1 7 0;
#X connect 9 0 1 0;

View file

@ -1,20 +1,17 @@
/*REXX program to draw a cuboid (dimensions must be positive integers).*/
parse arg x y z indent . /*x,y,z dimensions, indentation.*/
x=p(x 1); y=p(y x); z=p(z y); indent=p(indent 0)
call sayer y+2 , , "+-"
do j=1 for y; call sayer y-j+2, j-1, "/ |" ; end
call sayer , y , "+-|"
do z-1; call sayer , y , "| |" ; end
call sayer , y , "| +"
do j=1 for y; call sayer , y-j, "| /" ; end
call sayer , , "+-"
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────P subroutine────────────────────────*/
p: return word(arg(1),1) /*pick the first word in the list*/
/*──────────────────────────────────SAYER subroutine────────────────────*/
sayer: parse arg times,a,_ /*get the arguments specified. */
say left('',indent)right(left(_,1),pick1(times 1)) || ,
copies(substr(_,2,1),4*x)left(_,1)right(substr(_,3,1),pick1(a 0)+1)
return
/*REXX program displays a cuboid (dimensions must be positive integers). */
parse arg x y z indent . /*x,y,z: dimensions and indentation. */
x=p(x 2); y=p(y 3); z=p(z 4) /*use the defaults if not specified. */
in=p(indent 0)
call show y+2 , , "+-"
do j=1 for y; call show y-j+2, j-1, "/ |" ; end
call show , y , "+-|"
do z-1; call show , y , "| |" ; end
call show , y , "| +"
do j=1 for y; call show , y-j, "| /" ; end
call show , , "+-"
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
p: return word(arg(1), 1) /*pick the first number or word in list*/
/*────────────────────────────────────────────────────────────────────────────*/
show: parse arg #,$,a 2 b 3 c 4 /*get the arguments (or parts thereof).*/
say left('',in)right(a,p(# 1))copies(b,4*x)a || right(c,p($ 0)+1); return

View file

@ -1,22 +1,23 @@
X, Y, Z = 6, 2, 3
DIR = {"-" => [1,0], "|" => [0,1], "/" => [1,1]}
def cuboid(nx, ny, nz)
puts "cuboid %d %d %d:" % [nx, ny, nz]
x, y, z = 8*nx, 2*ny, 4*nz
x, y, z = X*nx, Y*ny, Z*nz
area = Array.new(y+z+1){" " * (x+y+1)}
line = lambda do |n, sx, sy, c|
draw_line = lambda do |n, sx, sy, c|
dx, dy = DIR[c]
(n+1).times do |i|
xi, yi = sx+i*dx, sy+i*dy
area[yi][xi] = (area[yi][xi]==" " ? c : "+")
end
end
nz .times {|i| line[x, 0, 4*i, "-"]}
(ny+1).times {|i| line[x, 2*i, z+2*i, "-"]}
nx .times {|i| line[z, 8*i, 0, "|"]}
(ny+1).times {|i| line[z, x+2*i, 2*i, "|"]}
nz .times {|i| line[y, x, 4*i, "/"]}
(nx+1).times {|i| line[y, 8*i, z, "/"]}
nz .times {|i| draw_line[x, 0, Z*i, "-"]}
(ny+1).times {|i| draw_line[x, Y*i, z+Y*i, "-"]}
nx .times {|i| draw_line[z, X*i, 0, "|"]}
(ny+1).times {|i| draw_line[z, x+Y*i, Y*i, "|"]}
nz .times {|i| draw_line[y, x, Z*i, "/"]}
(nx+1).times {|i| draw_line[y, X*i, z, "/"]}
puts area.reverse
end