Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Created April 3, 2018 10:12
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dockimbel/bf833e5a737f0efe4bfe07a26a528ec4 to your computer and use it in GitHub Desktop.
Save dockimbel/bf833e5a737f0efe4bfe07a26a528ec4 to your computer and use it in GitHub Desktop.
Test script for Red/View Android backend
Red [
Title: "Red Android bridge demo"
Author: "Nenad Rakocevic"
File: %eval2.red
Config: [type: 'dll libRed?: no libRedRT?: yes export-ABI: 'cdecl]
Tabs: 4
Needs: 'View
Rights: "Copyright (C) 2013-2017 Nenad Rakocevic. All rights reserved."
License: {
Distributed under the Boost Software License, Version 1.0.
See https://github.com/red/red/blob/master/BSL-License.txt
}
]
#include %../../bridges/java/bridge.red
;system/view/debug?: yes
t0: t1: now/time/precise
tiger: #include %tiger.red
rot: 0
z: 0.01
zoom: 0.2
insert tiger compose [translate 100x100 rotate (rot) scale (zoom) (zoom) translate -21x-40]
font-label: make font! [
name: "Arial"
size: 11
color: white
anti-alias?: no
]
font-A: make font! [
name: "Times New Roman"
size: 15
color: red
style: [bold italic underline]
anti-alias?: yes
]
img1: make image! [10x10 1.2.3]
n: 1
loop 10 [
poke img1 1x1 * n 254.0.0
n: n + 1
]
pattern: make image! 30x30
draw pattern [fill-pen red pen off box 0x0 30x30 pen black circle 15x15 10]
fstk-logo: load/as 64#{iVBORw0KGgoAAAANSUhEUgAAAD4AAAA/CAIAAAA3/+y2AAAACXBIWXMAABJ
0AAASdAHeZh94AAAGr0lEQVR4nNVaTW8kVxU9975XVf0xthNDBMoi4m8EwTZZsEAiG9jwM9jzE/gB
SBFIMFKEhIDFwIY9e1ggNhERYqTIMx67XR/v3XtYtO3Y3dXVXZXBnjlqtVpVr947dd+p+9UlH373e
4nEWwUBCpH43ix+/12JSp/Ev1SI6kQKhUJl9EXC5yk++7yOp/Pih9/k6cx8/CwASkN5EiZcCAAqYb
mgqriPuEj1n5fy7N9dhAh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yGmS+AHqzlUFkWrupnLVgBgNYDN3lxfkfn+rx8c36okF1fJ4jAru4LIJLGO2xPBnIcCdabeYwP
Qgxna+e//pXuPUyTg1azkIsZN3MCxjhgIony2Je9OSne9lnB+w2U+jJYTZBACLFbONYosQyCgCnjq
FuRjT5mv3IgOfZ0CJUEbtymINmcdaXuVyEoKMbBpadq65clBJGF72ezOmxiuGuYER66jsANDI1sM0
AYUDbynwZZb4YbT9nalIxjxqEHEk/MzJxUYlIpDPVVphZ2Nx6WVnxwfvv/uBj3dXpreuL3/0WXatx
KE3vIdCaNVYdFfurky24W7YkEqIbVq/aIiUpig3zed3OT99750c/jd/4Vu8szPV/f/lp0VwVx0ej2
zVimahmQXU4YdmE0Sy4+41KUgadGybY+3emr1akpC4Q1DDOfqpCZ0pObq576AwAqCFRm4Rps7ixfk
USY9kDyImpIzCl2aMAxA305Khb+JbtD4E7V+fmNoV9SmwbJ0ezvzc8E03HbeXshQjoqC/NfbRyAOT
MtvWxVtu800yZphwRuOHqAZXTM/BWOWOXFwEfUDn9o9bKSQfVuPfwkMrZeYOZkoxSVBJ2vu6iy5Pt
93geTDlDOYzH+OLv/4g//1mcV70DUt15dpbVBsFb5SyOggbxkf/Zp0TSq5mqDvTdBqkzxPr5i/989
hcRFDvsF0+Oe9P3W+XMj3QC+5yJ1stSRHrbwPuoixNS5EURBKGEaM8sA6K8Vc7yRKawTxSgrGSX7Q
96mI2ouynR6uv7nKbe6XMO9aKPFa3MdvqcEcH3TYtW4/KGyXnO61TOzdWjE7bHV87NkSlNlteiHJm
knLb76sWuCACqRWSQcXG/NZlFrWRscQQAdmFyFGUZkMc1Yz2DmcXcRYr40vyv8ydSzWxSrbIM176e
kHVr65AfAsBFOh1bVQMIhotz0lL8skt/YBSd+l7ujdVIEeGBPwDQRCa9kghAakbk/wFTSfh53Lxjk
wAAAABJRU5ErkJggg==
} 'png
view [
title "Red on Android"
tab-panel [
"Basic" [
backdrop white
space 5x5
style base: base
on-click [print "click!"]
on-down [print "down!"]
on-up [print "up"]
button "Hello" [
b/offset: b/offset - 0x10
s/text: first random ["Wifi" "GPS" "GSM" "Data"]
p/data: random 100%
sl/data: random 100%
r/data: random true
c/data: random true
s/data: random true
but/color: random 255.255.255
b/color: random 255.255.255
g/visible?: not g/visible?
dl/selected: random length? dl/data
]
but: button "Stop" #FF8080 [
b/size: b/size + random 10x10
bb/rate: all [none? bb/rate 20]
] return
text-list cyan data ["itemA" "itemB" "itemC" "itemD"]
panel [
origin 0x0 below
dl: drop-list #FFEFD5 80 data ["itemA" "itemB" "itemC" "itemD"]
drop-down #98FB98 data ["itemA" "itemB" "itemC" "itemD"]
] return
below
info: text "This is a text label"
bb: base 20x20 black extra 1 rate 20 on-time [
if any [face/offset/x < 10 face/offset/x > 200][
face/extra: negate face/extra
]
face/offset/x: face/offset/x + (face/extra * 6)
]
field "world"
panel yellow 2 [
r: radio "option 1"
radio "option 2"
c: check "check 1"
check "check 2"
]
s: switch "Wifi"
p: progress
sl: slider
across
base red on-down [b/offset: b/offset - 0x10]
g: base green on-down [b/offset: b/offset + 10x0]
b: base blue
base orange on-time [
face/color: random white
;t1: now/time/precise
;print t1 - t0
;t0: t1
]
return
below
area "This is^/a multi-line^/sentence."
text "-- Scroll below for more --" 200
text "Hello"
field "input field"
radio "option 1"
radio "option 2"
check "check 1"
check "check 2"
]
"Camera" [
across
cam: camera 120x160 on-created [
cam-list/data: cam/data
cam-list/selected: 1
]
panel [
below
button "start" [cam/selected: cam-list/selected]
button "stop" [cam/selected: none]
cam-list: drop-list data [] [cam/selected: cam-list/selected]
]
]
"Draw 1" [
base 240x940 draw [
pen red
line 10x10 30x30
line 30x10 50x50 70x120 120x55 100x100 50x89
fill-pen blue
triangle 100x54 180x154 20x154
line-width 3
fill-pen linear red blue green
box 10x200 50x250
fill-pen green
box 80x200 160x280 5
line-width 2
polygon 20x10 100x10 140x30 80x20 60x40
line-width 1
fill-pen off
spline 10x260 50x330 140x290 200x400 100x300 10x280
pen blue
fill-pen radial red blue green 180x90 30
circle 180x90 30
fill-pen bitmap pattern
ellipse 10x158 80x36
text 150x10 "Hello Red"
fill-pen orange
arc 100x25 80x80 0 90 closed
pen red
fill-pen off
arc 100x25 50x80 30 90
curve 10x55 45x55 45x90
curve 10x60 40x60 10x90 40x90
pen yellow
shape [
move 0x199
line 21x177
arc 42x157 25 20 -45 sweep
line 63x137
arc 84x115 25 40 -45 sweep
line 105x95
arc 126x73 25 60 -45 sweep
line 147x53
arc 168x31 25 80 -45 sweep
line 199x0
move 0x0
]
image img1 190x150
image fstk-logo 10x20 30x40
]
]
"Draw 2" [
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
line 10x10 40x30 10x30
line 10x40 40x40
font font-label
text 5x45 "line"
]
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
triangle 10x10 40x10 25x40
font font-label
text 5x45 "triangle"
]
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
box 10x10 40x20
box 20x30 30x40
font font-label
text 5x45 "box"
]
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
polygon 10x10 40x10 40x40 20x30
font font-label
text 5x45 "polygon"
]
return
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
circle 25x25 15
circle 25x25 10 5
font font-label
text 5x45 "circle"
]
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
ellipse 10x10 5x10
ellipse 35x10 5x10
ellipse 20x20 10x20
font font-label
text 5x45 "ellipse"
]
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
;arc <center> <radius> <begin> <sweep> closed
arc 25x25 15x15 0 180 closed
fill-pen off
arc 25x25 5x10 90 270
font font-label
text 5x45 "arc"
]
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
curve 10x5 45x5 45x40
curve 10x10 40x10 10x40 40x40
font font-label
text 5x45 "curve"
]
return
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
spline 10x10 40x10 40x40 10x40 10x20 30x20 30x30 20x30
font font-label
text 5x45 "spline"
]
base 50x60 100.70.70 draw [
line-width 2
fill-pen 170.20.20.128
image fstk-logo 10x10 40x40
font font-label
text 5x45 "image"
]
base 50x60 100.70.70 draw [
font font-label
text 5x45 "text"
text 10x10 "Red"
pen red ; test if pen color
font font-A
text 10x20 "Red"
]
base 50x60 100.70.70 draw [
font font-label
text 5x45 "pen flat"
line 10x10 10x40
box 15x10 20x40
pen off
fill-pen 20.20.170.128
box 25x10 30x40
pen 255.255.255.100
line-width 1
triangle 35x10 40x40 35x40
fill-pen off
triangle 35x10 40x10 40x40
]
return
base 50x60 100.70.70 draw [
font font-label
text 5x45 "pen gradient"
pen linear red green blue
line-width 5
fill-pen off
box 10x10 40x40
]
base 50x60 100.70.70 draw [
font font-label
text 5x45 "fill gradient"
fill-pen linear red green blue
box 10x10 40x40
]
base 50x60 100.70.70 draw [
font font-label
text 5x45 "line join"
line-width 5
line-join miter
line 10x40 15x20 20x40
line-join round
line 20x40 25x20 30x40
line-join bevel
line 30x40 35x20 40x40
]
base 50x60 100.70.70 draw [
font font-label
text 5x45 "line cap"
line-width 7
line-cap flat
line 15x15 15x35
line-cap square
line 25x15 25x35
line-cap round
line 35x15 35x35
]
return
base 230x2 0.0.0
return
base 50x60 70.70.100 draw [
font font-label
text 5x45 "rotate"
line-width 2
fill-pen 170.20.20.128
box 15x15 35x35
rotate 45 25x25
box 15x15 35x35
]
base 50x60 70.70.100 draw [
font font-label
text 5x45 "scale"
line-width 2
fill-pen 170.20.20.128
box 10x10 40x40
scale 0.5 0.5
box 10x10 40x40
]
base 50x60 70.70.100 draw [
font font-label
text 5x45 "translate"
line-width 2
fill-pen 170.20.20.128
box 10x10 30x30
translate 10x10
box 10x10 30x30
]
]
"Tiger" [
base 200x200 options [accelerated: #[false]] rate 50 on-time [
rot: rot + 1
zoom: zoom + z
if any [zoom < 0.1 zoom > 0.7][z: negate z]
tiger/4: rot
tiger/6: zoom
tiger/7: zoom
face/draw: tiger
]
]
]
]
@iArnold
Copy link

iArnold commented Apr 11, 2018

The Draw1 section is very chaotic. Suggest to change it to a little less so.
As you and Qingtian are very busy I propose some changes here.
base 240x940 draw [
pen red
line 10x10 10x400
; Letter R
line 20x360 20x400 30x400 30x380 40x400 50x400 40x380 50x375 50x365 40x360 20x360
; Letter E
line 60x360 60x400 90x400 90x390 70x390 70x380 80x380 80x375 70x375 70x370 90x370 90x360 60x360
; Letter D (left bar)
line 100x360 100x400 ;120x400 130x390 130x370 120x360 100x360
fill-pen blue
triangle 130x350 20x275 20x350
line-width 3
fill-pen linear red blue green
box 140x400 200x360
fill-pen green
box 120x300 200x340 5
line-width 2
fill-pen snow
polygon 30x260 100x300 110x290 180x280 90x285
line-width 1
pen blue
fill-pen radial red blue green 60x310 30
circle 60x310 30
fill-pen orange
arc 10x10 80x80 0 90 closed
pen white
text 15x15 "Hello Red!"
pen red
fill-pen off
arc 10x10 85x85 0 90
arc 10x10 90x90 0 90
arc 10x10 95x95 0 90
; Letter D continued with two curve's
curve 100x360 130x360 130x380
curve 130x380 130x400 100x400
; Some sinus like curve
pen navy
curve 10x175 40x180 10x210 45x210
curve 45x210 80x210 45x180 80x175
curve 80x175 110x180 80x210 115x210
curve 115x210 150x210 115x180 150x175
curve 150x175 180x180 150x210 185x210
curve 185x210 220x210 185x180 220x175
pen yellow
shape [
move 0x199
line 21x177
arc 42x157 25 20 -45 sweep
line 63x137
arc 84x115 25 40 -45 sweep
line 105x95
arc 126x73 25 60 -45 sweep
line 147x53
arc 168x31 25 80 -45 sweep
line 199x0
move 0x0
]
;fill-pen bitmap pattern
ellipse 120x240 80x36
pen red
fill-pen off
spline 20x290 200x130 130x100 80x150 80x200 100x210 130x210 140x220 140x240 160x255 170x260
image img1 120x10
image fstk-logo 15x35 35x55
]

Could be improved a lot but as a first step a lot better.
Link here: https://gist.github.com/iArnold/47b550871cba564ad1980ab611ed8eca

@beenotung
Copy link

I think it's better to put this code into a repo than as a gist, because it's including other file with relative path

@kabsyakskabeer
Copy link

i like it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment