September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,66 @@
'This code will create the necessary controls on a GUI Form
hLabel As Label 'Label needed to display the 'Hello World! " message
hTimer As Timer 'Timer to rotate the display
bDirection As Boolean 'Used to control the direction of the text
'__________________________________________________
Public Sub Form_Open()
Dim hPanel As Panel '2 Panels used to centre the Label vertically on the Form
Dim hHBox As HBox 'Box to hold the Label
With Me 'Set the Form Properties
.Arrangement = Arrange.Vertical 'Arrange controls vertically
.Title = "Animation" 'Give the Form a Title
.Height = 75 'Set the Height of the Form
.Width = 225 'Set the Width of the Form
End With
hPanel = New Panel(Me) 'Add a Panel to the Form
HPanel.Expand = True 'Expand the Panel
hHBox = New HBox(Me) 'Add a HBox to the Form
hHBox.Height = 28 'Set the HBox Height
hLabel = New Label(hHBox) As "LabelAnimation" 'Add new Lable with Event name
With hLabel 'Change the hLabel properties
.Height = 35 'Set the Height of the Label
.Expand = True 'Expand the hLabel
.Font.Bold = True 'Set the Font to Bold
.Font.size = 20 'Set the Font Size
.Alignment = Align.Center 'Centre align the text
.Tooltip = "Click me to reverse direction" 'Add a Tooltip
.Border = Border.Plain 'Add a Border
.Text = "Hello World! " 'Add the Text
End With
hPanel = New Panel(Me) 'Add another Panel
HPanel.Expand = True 'Expand the Panel
hTimer = New Timer As "Timer1" 'Add a Timer
hTimer.delay = 500 'Set the Timer Delay
hTimer.Start 'Start the Timer
End
'__________________________________________________
Public Sub LabelAnimation_MouseDown() 'If the hLabel is clicked..
bDirection = Not bDirection 'Change the value of bDirection
End
'__________________________________________________
Public Sub Timer1_Timer() 'Timer
Dim sString As String = hLabel.Text 'To hold the text in the Label
Dim sTemp As String 'Temp string
If bDirection Then 'If the text is to rotate left then..
sTemp = Left(sString, 1) 'Get the first charater of the Label Text e.g 'H'
sString = Right(sString, -1) & sTemp 'Recreate sString with all the text less the 1st character e.g. 'ello World! ' and add the 1st character to the end e.g. 'ello World! H'
Else 'Else if text is to rotate right then..
sTemp = Right(sString, 1) 'Get the last charater of the Label Text e.g '!'
sString = sTemp & Left(sString, -1) 'Recreate sString with all the text less the last character e.g. ' Hello World' and add the last character to the begining e.g. '! Hello World'
End If
hLabel.text = sString 'Display the result
End

View file

@ -1,18 +0,0 @@
CHARACTER string="Hello World! "
WINDOW(WINdowhandle=wh, Height=1, X=1, TItle="left/right click to rotate left/right, Y-click-position sets milliseconds period")
AXIS(WINdowhandle=wh, PoinT=20, X=2048, Y, Title='ms', MiN=0, MaX=400, MouSeY=msec, MouSeCall=Mouse_callback, MouSeButton=button_type)
direction = 4
msec = 100 ! initial milliseconds
DO tic = 1, 1E20
WRITE(WIN=wh, Align='Center Vertical') string
IF(direction == 4) string = string(LEN(string)) // string ! rotate left
IF(direction == 8) string = string(2:) // string(1) ! rotate right
WRITE(StatusBar, Name) tic, direction, msec
SYSTEM(WAIT=msec)
ENDDO
END
SUBROUTINE Mouse_callback()
direction = button_type ! 4 == left button up, 8 == right button up
END

View file

@ -1,44 +0,0 @@
import gui
$include "guih.icn"
class WindowApp : Dialog (label, direction)
method rotate_left (msg)
return msg[2:0] || msg[1]
end
method rotate_right (msg)
return msg[-1:0] || msg[1:-1]
end
method reverse_direction ()
direction := 1-direction
end
# this method gets called by the ticker, and updates the label
method tick ()
static msg := "Hello World! "
if direction = 0
then msg := rotate_left (msg)
else msg := rotate_right (msg)
label.set_label(msg)
end
method component_setup ()
direction := 1 # start off rotating to the right
label := Label("label=Hello World! ", "pos=0,0")
# respond to a mouse click on the label
label.connect (self, "reverse_direction", MOUSE_RELEASE_EVENT)
add (label)
connect (self, "dispose", CLOSE_BUTTON_EVENT)
# tick every 100ms
self.set_ticker (100)
end
end
# create and show the window
procedure main ()
w := WindowApp ()
w.show_modal ()
end

View file

@ -1,59 +1,61 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class Rotate extends JFrame {
String text = "Hello World! ";
JLabel label = new JLabel(text);
boolean rotRight = true;
int startIdx = 0;
public class Rotate {
public Rotate() {
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
rotRight = !rotRight;
}
});
add(label);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
private static class State {
private final String text = "Hello World! ";
private int startIndex = 0;
private boolean rotateRight = true;
}
public static void main(String[] args) {
final Rotate rot = new Rotate();
TimerTask task = new TimerTask() {
public void run() {
if (rot.rotRight) {
rot.startIdx++;
if (rot.startIdx >= rot.text.length()) {
rot.startIdx -= rot.text.length();
}
} else {
rot.startIdx--;
if (rot.startIdx < 0) {
rot.startIdx += rot.text.length();
}
public static void main(String[] args) {
State state = new State();
JLabel label = new JLabel(state.text);
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
state.rotateRight = !state.rotateRight;
}
});
TimerTask task = new TimerTask() {
public void run() {
int delta = state.rotateRight ? 1 : -1;
state.startIndex = (state.startIndex + state.text.length() + delta) % state.text.length();
label.setText(rotate(state.text, state.startIndex));
}
};
Timer timer = new Timer(false);
timer.schedule(task, 0, 500);
JFrame rot = new JFrame();
rot.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
rot.add(label);
rot.pack();
rot.setLocationRelativeTo(null);
rot.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
timer.cancel();
}
});
rot.setVisible(true);
}
private static String rotate(String text, int startIdx) {
char[] rotated = new char[text.length()];
for (int i = 0; i < text.length(); i++) {
rotated[i] = text.charAt((i + startIdx) % text.length());
}
rot.label.setText(getRotatedText(rot.text, rot.startIdx));
}
};
Timer timer = new Timer(false);
timer.schedule(task, 0, 500);
}
public static String getRotatedText(String text, int startIdx) {
String ret = "";
int i = startIdx;
do {
ret += text.charAt(i) + "";
i++;
i = i % text.length();
} while (i != startIdx);
return ret;
}
return String.valueOf(rotated);
}
}

View file

@ -0,0 +1,55 @@
// version 1.1.0
import java.awt.Dimension
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.util.*
import javax.swing.JFrame
import javax.swing.JLabel
class Rotate : JFrame() {
val text = "Hello World! "
val label = JLabel(text)
var rotRight = true
var startIdx = 0
init {
preferredSize = Dimension(96, 64)
label.addMouseListener(object: MouseAdapter() {
override fun mouseClicked(evt: MouseEvent) {
rotRight = !rotRight
}
})
add(label)
pack()
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
isVisible = true
}
}
fun getRotatedText(text: String, startIdx: Int): String {
val ret = StringBuilder()
var i = startIdx
do {
ret.append(text[i++])
i %= text.length
}
while (i != startIdx)
return ret.toString()
}
fun main(args: Array<String>) {
val rot = Rotate()
val task = object : TimerTask() {
override fun run() {
if (rot.rotRight) {
if (--rot.startIdx < 0) rot.startIdx += rot.text.length
}
else {
if (++rot.startIdx >= rot.text.length) rot.startIdx -= rot.text.length
}
rot.label.text = getRotatedText(rot.text, rot.startIdx)
}
}
Timer(false).schedule(task, 0, 500)
}

View file

@ -0,0 +1,60 @@
#[cfg(feature = "gtk")]
mod graphical {
extern crate gtk;
use self::gtk::traits::*;
use self::gtk::{Inhibit, Window, WindowType};
use std::ops::Not;
use std::sync::{Arc, RwLock};
pub fn create_window() {
gtk::init().expect("Failed to initialize GTK");
let window = Window::new(WindowType::Toplevel);
window.connect_delete_event(|_, _| {
gtk::main_quit();
Inhibit(false)
});
let button = gtk::Button::new_with_label("Hello World! ");
window.add(&button);
let lock = Arc::new(RwLock::new(false));
let lock_button = lock.clone();
button.connect_clicked(move |_| {
let mut reverse = lock_button.write().unwrap();
*reverse = reverse.not();
});
let lock_thread = lock.clone();
gtk::timeout_add(100, move || {
let reverse = lock_thread.read().unwrap();
let mut text = button.get_label().unwrap();
let len = &text.len();
if *reverse {
let begin = &text.split_off(1);
text.insert_str(0, begin);
} else {
let end = &text.split_off(len - 1);
text.insert_str(0, end);
}
button.set_label(&text);
gtk::Continue(true)
});
window.show_all();
gtk::main();
}
}
#[cfg(feature = "gtk")]
fn main() {
graphical::create_window();
}
#[cfg(not(feature = "gtk"))]
fn main() {}

View file

@ -0,0 +1,17 @@
'Animation, by rbytes and Dutchman
word$="Hello World! "
'use button window with text
SET BUTTONS CUSTOM
SET BUTTONS FONT SIZE 40
DRAW COLOR 0,0,0
DO 'the button is redrawn each loop
BUTTON "anim" TEXT word$ AT 130,100
PAUSE .1
'touching the button reverses the scrolling
IF BUTTON_PRESSED("anim") THEN flag=1-flag
IF flag THEN 'shift right
word$=RIGHT$(word$,1)&LEFT$(word$,LEN(word$)-1)
ELSE 'shift left
word$=RIGHT$(word$,LEN(word$)-1)&LEFT$(word$,1)
ENDIF
UNTIL 0

View file

@ -0,0 +1,2 @@
'by rbytes and Dutchman!word$="Hello World! "!'use button window with text!
SET BUTTONS CUSTOM!SET BUTTONS FONT SIZE 40!DRAW COLOR 0,0,0!DO!'the button is redrawn each loop!BUTTON "anim" TEXT word$ AT 130,100!PAUSE .1!'touching the button reverses the scrolling!IF BUTTON_PRESSED("anim") THEN flag=1-flag!IF flag THEN!'shift right!word$=RIGHT$(word$,1)&LEFT$(word$,LEN(word$)-1)!ELSE!'shift left!word$=RIGHT$(word$,LEN(word$)-1)&LEFT$(word$,1)!ENDIF!UNTIL 0

View file

@ -0,0 +1 @@
w$="Hello World! "!1 BUTTON 0 TEXT w$ AT 0,0!PAUSE .1!IF BUTTON_PRESSED("0") THEN f=1-f!IF f THEN w$=RIGHT$(w$,1)&LEFT$(w$,LEN(w$)-1) ELSE w$=RIGHT$(w$,LEN(w$)-1)&LEFT$(w$,1)!GOTO 1

View file

@ -0,0 +1 @@
w$="Hello World! "!1 BUTTON 0 TEXT w$ AT 0,0!PAUSE .1!IF BUTTON_PRESSED("0") THEN f=1-f!k=LEN(w$)-1!IF f THEN w$=RIGHT$(w$,1)&LEFT$(w$,k) ELSE w$=RIGHT$(w$,k)&LEFT$(w$,1)!GOTO 1